TFS 2010 Version Control: Branching and Branch Hierarchy

Posted by: Subodh Sohoni , on 6/18/2009, in Category Visual Studio, VSTS & TFS
Views: 56115
Abstract: One of the features of TFS 2008 I found interesting is ability to view branch hierarchy. The way branching process behaves in TFS 2010 is different than the way it behaves in 2008.
TFS 2010 Version Control: Branching and Branch Hierarchy
 
One of the features of TFS 2008 I found interesting is ability to view branch hierarchy. The way branching process behaves in TFS 2010 is different than the way it behaves in 2008. When we create a branch in TFS 2010 it just creates a folder of the branch with the name that we give to the branch. I created a code to check if that folder is treated as a branch or not:  
C# 
public List<string> GetBranches(string SelectedTeamProject, string RootName)
{
   List<string> branches = new List<string>();
   ItemIdentifier ii = new ItemIdentifier("$/" + SelectedTeamProject + "/" + RootName);
   BranchObject[] branchObjects = tfvc.QueryBranchObjects(ii, RecursionType.Full);
   for (int i = 0; i < branchObjects.Length; i++)
   {
      branches.Add(branchObjects[i].Properties.RootItem.Item);
   }
   return branches;
}
 VB.NET 
Public Function GetBranches(ByVal SelectedTeamProject As String, ByVal RootName As String) As List(Of String)
   Dim branches As New List(Of String)()
   Dim ii As New ItemIdentifier("$/" & SelectedTeamProject & "/" & RootName)
   Dim branchObjects() As BranchObject = tfvc.QueryBranchObjects(ii, RecursionType.Full)
   For i As Integer = 0 To branchObjects.Length - 1
       branches.Add(branchObjects(i).Properties.RootItem.Item)
   Next i
   Return branches
End Function
 
I found that newly created branch does not get added to the BrachObjects array. By the way QueryBranchObjects and BrachObject are new set of APIs I have seen and they reduce the code considerably. We can use this code for identifying a branch which can be built in the application for custom build creation and execution through code.     
              
Custom_Build
 
 After the branch is created but appears as folder,  we can right click that folder and convert it to a branch. In the above picture, WISpawner is shown as a plain folder and then in the picture below I have right clicked on it and selected to convert it to a branch. In the next picture you can see that it has got converted to a branch along with its child branch.
 
Branch_ChildBranch
 
Folders
 
There is an option to convert the branch back to folder if necessary. Another option is to re-parent the branch which works for only the linear descendant.
A feature which was very much in demand which is added now is the hierarchy view of the branch structure. We can select any branch and in the context sensitive menu (right click menu) get the option to view the hierarchy. By default the hierarchy show is for ancestors – descendants of the selected branch but we have the option to select other types of relations like Parent – Child, only ancestors or only descendants etc. View can even be customized to show only specific branches instead of all fitting the filter.  A nice graphical view shows the hierarchy of branches. This is the logical view of branch structure of source control whereas what we see in the source control editor is the physical view.
 
Branch_Hierarchy
 
Branch properties now have some additional options which can provide us the access to the metadata of the branch. It has options to view and change Owner of the branch, view relations of the branch and permissions to users to modify branch. By default it is the user who created the branch but may be edited. Relations tab provides the view of parent – child view of all branches. Matt Mitrik, Program Manager, TFS, Version Control in his blog http://blogs.msdn.com/mitrik/archive/2009/06/08/first-class-branches.aspx has mentioned that it is the base for view of the branch hierarchy in the logical view.
A very neat feature which I had not seen earlier is branch comparison. We can select any branch in the team project and compare it with any other branch in the same team project. Option is available to select branch in the local folder or server item. It is also possible to select any version of the branch depending upon date, label, changeset etc. and compare it with the other branch.
 
Compare_Branch
 
The view shows statistics of how many branches were compared and how many of them are same and how many are different. It also shows the files which are different with a red color.

Summary: In this article we have seen various new features related to branching in TFS 2010. We have seen the new objects to access the branches in Team Foundation Version Control APIs which can be used in other applications. We have also covered branching hierarchy and its view. Finally we have seen how to compare two branches or versions of branch through branch compare tool. 

If you liked the article,  Subscribe to the RSS Feed or Subscribe Via Email 
 
Subodh Sohoni is MCTS - Microsoft Team Foundation Server - Configuration and Development and also is a Microsoft Certified Trainer(MCT) since 2004. Subodh works as VP, Technology with SEED Infotech Ltd 

Give me a +1 if you think it was a good article. Thanks!
Recommended Articles
Subodh Sohoni, Team System MVP, is an MCTS – Microsoft Team Foundation Server – Configuration and Development and also is a Microsoft Certified Trainer(MCT) since 2004. Subodh has his own company and conducts a lot of corporate trainings. He is an M.Tech. in Aircraft Production from IIT Madras. He has over 20 years of experience working in sectors like Production, Marketing, Software development and now Software Training. Follow him on twitter @subodhsohoni


Page copy protected against web site content infringement by Copyscape


User Feedback
Comment posted by Greg Billour on Monday, June 22, 2009 1:51 AM
I didn't know this feature existed. 5 Stars.

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel