Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS 2010 programmatically determining item branch

Tags:

branch

How can I determine programatically which branch this file belongs to? I've spent 3 hours trying to figure this out with no results. I found this topic but it's not what I want: How to programmatically get information about branches in TFS?

like image 663
Krzysiek Avatar asked Aug 08 '11 14:08

Krzysiek


1 Answers

I had a very similar problem. I found a solution to it, here is the code:

...
// get all branches
VersionControlServer vcs = tfs.GetService(typeof(VersionControlServer));
BranchObject[] allBranches = vcs.QueryRootBranchObjects(RecursionType.Full);

string myItem = "$/My Project/some Path including the branch/myFile.txt";

foreach(BranchObject branch in allBranches)
{
  if(myItem.Contains(branch.Properties.RootItem.Item))
  {
    // branch is the branch to which the item belongs! :)
  }
}
...

I hope this helps someone with this problem, I think the op has already solved it (it's been a while since he asked the question).

like image 134
Christian Avatar answered Sep 24 '22 13:09

Christian