Friday, October 5, 2018

git: batch script to clean/delete(or list) your local branches that are merged/removed(deleted) from remote / server



How to list/delete/clean all the local branches (usually after PR merge) that you have on local but was deleted from remote/server (with simple batch/command line script on windows)?

Quick Answer:
Below is what i use as soon as i squash merge the pull request in single execution (to checkout to master, fetch prune, delete the local branches that are in my local but deleted in source and the do a git pull)

Command line:
git checkout master && git fetch --prune && git branch -vv | for /f "tokens=1" %a in ('findstr /R /C:": gone]"') do (git branch -D %a) && git pull
If you are creating a batch file (say cleanupAfterPRMerge.bat), put below inside:
git checkout master && git fetch --prune && git branch -vv | for /f "tokens=1" %%a in ('findstr /R /C:": gone]"') do (git branch -D %%a) && git pull

Step by step:
run "git checkout master"
run "git fetch --prune"
  • On windows command prompt:
    • details of those branches: 
      • git branch -vv | findstr /R /C:": gone]"

    • if you don't want the details and just the branch names, use
      • git branch -vv | for /f "tokens=1" %a in ('findstr /R /C:": gone]"') do echo %a

    • if you are happy with it and would delete all those local branches that are deleted from remote
      • git branch -vv | for /f "tokens=1" %a in ('findstr /R /C:": gone]"') do git branch -D %a



if you want to delete one by one or specific local branch:
  • if its still in remote branch and merged 
    • git branch -d [Branch name]
  • if its its not merged or deleted from remote/server or local only
    • git branch -D [Branch name]
[posting this as i didn't find a quick answer on the web for windows commandline/batch (with out installing additional software)]

Hope this helps someone.


-- Tony Julien





Thursday, January 15, 2015

how to make button click work in listview on universal app ( xaml & WinRT)

If you are following MVVM pattern or using a datatemplate and trying to have a button inside a ListViewItem but the button click not working (not triggering the command), this might help.

The button gets binded to the item on the collection and if you want to manipulate the collection bound to listview, the command in most cases you might have it at the ViewModel bound to the listview. so make the button command bind to the listview data binding as below..


<ListView

                    x:Name="ItemListView"

                    ….

> 

                   <ListView.ItemTemplate>

                        <DataTemplate>

                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">

                                <Button Content="x" HorizontalAlignment="Left" VerticalAlignment="Center" Command="{Binding ElementName=ItemListView, Path=DataContext.RemoveButtonCommand}" CommandParameter="{Binding}"></Button>

                                <TextBlock Text="{Binding Title}"></TextBlock>

                            </StackPanel>

                        </DataTemplate>

                    </ListView.ItemTemplate>

                </ListView>


In above code, I'm setting the binding to the listview element by name and set the binding path to the elements datacontext and the command exposed through a property on the viewmodel bound to the listview.

The viewmodel would be something like this.
 
public myViewModel()

{ 
 
     this.RemoveButtonCommand = new RelayCommand(this.RemoveButtonCommandExecute);
}


public ICommand RemoveButtonCommand { get; set; }


please let me know in commands if this is useful or if you think more details/explanation would be helpful.

Thursday, September 5, 2013

how to generate nested xml from database/table using sql queries

[I’ve been focusing on Frontend development for some time and didn’t had an need to explore FOR XML command on SQL server. But I when I needed it today, felt its an awesome feature. Adding this post here as the search engines pointed me to how to write complex stored procedures for this instead of redirecting to nested For XML queries.]
 
I was working on migrating some of the features to Azure and there was data XML with complex structure, I wanted to move to relational data base and build WebAPI’s to expose the functionality to be used by many frontend clients running outside Azure. So I created all the relational tables in SQL Azure and wrote the stored procedures etc. A blocker question came in as a requirement on this feature should work if Azure goes down (yup, rare but I work on critical app which shouldn’t have any downtime) and we don’t the old app to work without much changes. After thinking through caching & performance, decided to generate the XML output from SQL itself and pass it on for current applications that are not in Azure (and save cost by get bulk and cache it and reducing chattiness).
 
Binged on creating XML in stored procedure and got many forums explaining how to create XML nodes, optimize it with Cursors, etc. wrote the full sp and accidently noticed the For XML clause. Explored further and found it was a simple and powerful with nested For XML queries and I got the whole legacy XML with <10 line query and still keep the well designed DB tables and names.
 
The MSDN has detailed info with many examples to refer, so not adding much here.. http://msdn.microsoft.com/en-us/library/ms188276(v=sql.110).aspx
 
An example from MSDN for quick reference…
SELECT ProductCategoryID, Name as CategoryName,
       (SELECT ProductSubCategoryID, Name SubCategoryName,
               (SELECT ProductModel.ProductModelID,
                       ProductModel.Name as ModelName,
                       (SELECT ProductID, Name as ProductName, Color
                        FROM   Production.Product
                        WHERE  Product.ProductModelID =
                               ProductModel.ProductModelID
                        FOR XML AUTO, TYPE)
                FROM   (SELECT distinct ProductModel.ProductModelID,
                               ProductModel.Name
                        FROM   Production.ProductModel,
                               Production.Product
                        WHERE  ProductModel.ProductModelID =
                               Product.ProductModelID
                        AND    Product.ProductSubCategoryID =
                               ProductSubCategory.ProductSubCategoryID)
                                  ProductModel
                FOR XML AUTO, type
               )
        FROM Production.ProductSubCategory
        WHERE ProductSubCategory.ProductCategoryID =
              ProductCategory.ProductCategoryID
        FOR XML AUTO, TYPE, ELEMENTS
       )
FROM Production.ProductCategory
ORDER BY ProductCategoryID
FOR XML AUTO, TYPE
 
 
~ Tony Julien
 

Wednesday, January 30, 2013

How to permanently delete an TFS branch

Delete context menu on TFS Source Control explorer will not purge the files and also it need you to get the latest and then delete (more steps), but it does not purge the files.

 

If you want to permanently delete a TFS branch, use “tf destroy” command on the VS command prompt. Incase if you want to keep the history add “/keephistory” to it.

 

E.g.:

tf destroy “<branchPath>"

 

Destroy Command msdn link has full details: http://msdn.microsoft.com/en-us/library/bb386005(v=VS.100).aspx

 

[It’s been sometime, I purged an branch and I wanted to quickly get the purge comment again and search on Bing and google with keyword permanently delete tfs didn’t bring relevant answer, so thought I’ll post it for permanently delete.]

 

 

 

 

 

Thursday, June 23, 2011

Tip: How to display an icon(on address bar/favorites/bookmark) to a webpage

Resolves these:

·         If you are wondering why you are getting event logs with favicon.ico file not found

·         If you are interested in having a custom icon for your webpage on the address bar of the browser (shown in front of the url ) or favorites or bookmark to your page.

 

How:

 

Add the following link tag with the href set to the icon you want to display:

 

<link href="http://www.mysite.com/myicon.ico" rel="shortcut icon"/>

Friday, January 29, 2010

What’s New in Windows Presentation Foundation 4

What’s New in Windows Presentation Foundation 4

Click here to Navigate to the videos series on msdev.com

This series of short, “how-to” videos will introduce the various new features that have been added to WPF with .NET 4.0. Each video provides a code-focused look at how you can leverage a new feature or set of features in your WPF applications.

Thursday, November 19, 2009

Windows Identity Foundation

Windows Identity Foundation Overview:

Click here to the Session on Microsoftpdc.com to
Hear how Windows Identity Foundation makes advanced identity capabilities and open standards first class citizens in the Microsoft .NET Framework. Learn how the Claims Based access model integrates seamlessly with the traditional .NET identity object model while also giving developers complete control over every aspect of authentication, authorization, and identity-driven application behavior. See examples of the point and click tooling with tight Microsoft Visual Studio integration, advanced STS capabilities, and much more that Windows Identity Foundation consistently provides across on-premise, service-based, ASP.NET and Windows Communication Foundation (WCF) applications.