Paul Hacker's Blog

Musings from a "Hacker"
posts - 21, comments - 65, trackbacks - 22

My Links

News



Archives

Get Branch Relatives in Team Foundation Version Control

I am currently working on a TFVC utility. Part of the functionality of the utility is for the user to select a sourcepath and have the system return all the branches that are related to the path. Here is what I was able to come up with to solve this. The sample will return an Item array that you can then work against to get the desired information.

private TeamFoundationServer tfsServer = null;

private VersionControlServer vcs = null; 

public Item[] GetMyRelatives(Item sourceItem)
{

tfsServer = TeamFoundationServerFactory.GetServer(serverName, new UICredentialsProvider());

tfsServer.EnsureAuthenticated();

vcs = (VersionControlServer)tfsServer.GetService(typeof(VersionControlServer));


      List<Item> listRelatives= new List<Item>();
      BranchHistoryTreeItem[][] historyTreeArray = vcs.GetItemBranches(sourceItem);
      BranchHistoryTreeItem treeItem = null;


      if ((historyTreeArray.Length != 0) && (historyTreeArray[0].Length != 0))
      {
            treeItem = historyTreeArray [0][0];
      }

//make sure we have some branches to work with
      if (treeItem != null)
      {
            treeItem = treeItem .GetRequestedItem();
            if (((treeItem .Parent.Relative.BranchToItem != null)) && (treeItem .Parent.Relative.BranchToItem.DeletionId == 0))
            {
                  listRelatives.Add(treeItem .Parent.Relative.BranchToItem);
            }

//loop through the all the children (if any)and get the relatives
          foreach (BranchHistoryTreeItem treeItem2 in treeItem .Children)
            {
                  if ((treeItem2 .Relative.BranchToItem != null) && (treeItem2 .Relative.BranchToItem.DeletionId == 0))
                  {
                        listRelatives.Add(treeItem2 .Relative.BranchToItem);
                  }
            }
      }
      return listRelatives.ToArray();

Grant it that this is not production level, but it shows just another way that you can take advantage of the source control API available in TFS.

Hope it helps!  Happy coding :-)

pjhacker

Print | posted on Tuesday, August 08, 2006 9:09 AM |

Feedback

Gravatar

# re: Get Branch Relatives in Team Foundation Version Control

Hey Paul,

Just wondering if you were the same guy I worked with on the Irradiated Nuclear Graphite DB at the IAEA. If so looks like you are still heavily involved in coding and now blogging! I can best be reached at jeffrey.stephens@ngc.com -

Regards,
Jeff
9/7/2006 1:12 PM | Jeff Stephens
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: