4

I need to programmatically track changesets: determine in which branch a changeset is currently located.

Update: Let's say we got three branches for a project: Dev, Test and Release. Whenever we're ready to go live with some changesets, we first merge them to Test, and then to Release as soon as the testing is done. I need to know where a given changeset is located in this workflow (only in Dev OR in Dev + merged in Test OR in Dev + merged in Test + merged in Release).

enter image description here

It's already possible to do this using the Visual Studio "Tracking" interface, but I need to do it programmatically to get more customizations over it. I'm already able to get all the changesets for a specific work item using the code provided here, but I've yet to find a way to determine in which branches a changeset in present.

  • Well. A changeset can, of course, contain files in multiple branches. But really all you need to do is look at the server path prefix, or is there something more complicated you're trying to do? – Edward Thomson Jun 05 '13 at 16:38
  • I'm not sure I understand what you mean by "server path prefix". Could you point me out how it is represented in the TFS SDK ? –  Jun 05 '13 at 16:49
  • I mean `$/Project/Main` is in the `Main` branch, by definition... `$/Project/Branches/Foo` is in the `Foo` branch, by definition... I'm not sure I see yet what you're trying to determine beyond that... – Edward Thomson Jun 05 '13 at 16:56
  • I clarified what I'm trying to achieve in the question. –  Jun 05 '13 at 17:12

1 Answers1

4

I just made a tool which does the exact same thing. The call you need is TrackMerges. The good news is you can check multiple branches in one call. Here's a code snippet:

var tfsCollection = new TfsTeamProjectCollection(new Uri(server), new NetworkCredential(username, password, userDomain));
tfsCollection.EnsureAuthenticated();
VersionControlServer versionControlServer = tfsCollection.GetService<VersionControlServer>();

ExtendedMerge[] merges = versionControlServer.TrackMerges(
                                  new[] {changesetIdYouAreChecking}, 
                                  new ItemIdentifier("$/Proj/Dev"), 
                                  new [] {new ItemIdentifier("$/Proj/Test"), new ItemIdentifier("$/Proj/Release")}, 
                                  null);

foreach (ExtendedMerge extendedMerge in merges)
{
    Console.WriteLine("Branch --> " + extendedMerge.TargetItem.Item);
    Console.WriteLine("Changeset --> " + extendedMerge.TargetChangeset.ChangesetId);
}

If the merges variable does not contain the branch you are looking for, then it hasn't been merged.

riQQ
  • 9,878
  • 7
  • 49
  • 66
Jeff
  • 333
  • 2
  • 10