Determine in which branches a changeset in present

百般思念 提交于 2020-01-01 06:26:14

问题


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).

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.


回答1:


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.



来源:https://stackoverflow.com/questions/16944170/determine-in-which-branches-a-changeset-in-present

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!