签入变更集以编程方式合并

Check in changeset is merged programmatically

我正在检索与 WorkItem 相关的 tfvc 变更集。我的下一步是我想检查它们是否已合并到特定分支。我没有找到任何有关如何在 c# 中执行此操作的信息。

今天我得到的是:

using (var changeSetClient =
                new TfvcHttpClient(_uri, _credentials))
            {

                foreach (var relation in wi.Relations.Where(r => r.Url.Contains("Changeset")))
                {
                    var changeset = changeSetClient.GetChangesetAsync("Welfare_Research_2009", relation.Attributes["id"]).Result;
                    changeset.

                }
            }
            return null;
}

我还可以获得正确的 TfvcBranch,我想知道它是否已合并到。

但是如何检查它是否已合并?很像 Visual Studio.

中的 "Track Changesets" 功能

可能有更有效的方法来做到这一点,但您可以使用如下方式查询相应分支的历史记录:

// pseudo code
var parameter = new QueryHistoryParameters();
parameter.RecursionType = RecursionType.Full;
parameter.IncludeChanges = true;
// set other members to potentially filter out unneeded stuff
// especially, say, "VersionStart" / "VersionEnd".

var result = workspace.VersionControlServer.QueryHistory(parameter);

foreach (var entry in result)
{
     // Compare "entry.ChangesetId" with the ID of the changeset you're looking for.
}

请注意,可以通过不同的方式收集对 VersionControlServer 接口的引用。以上我假设您已经有工作区参考。

根据您的描述,VersionControlServer.TrackMerges()就是您要使用的API。

TrackMerges(array<Int32[], ItemIdentifier, array<ItemIdentifier[], ItemSpec)

获取从源项目到一组目标项目的合并,用于源变更集 ID 列表。

In the sourceItem parameter, pass the root of the branch you want to track changes from. In the targetItems parameter, pass the root of the branches that you want to track the changeset to. Note, this will only work for branch roots that have a merge relationship. The best way to make sure that is true is to view the branch hierarchy and make the branches are directly related or related through some route.

Let's say you wanted to track a changeset from $/Proj/Main to $/Proj/Feature2 in a branch hierarchy like this:

$/Proj/Main
    $/Proj/Dev
       $/Proj/Feature2

Then you would want to pass $/Proj/Main in as your sourceItem and $/Proj/Dev AND $/Proj/Feature2 as targetItems.

更多详细代码和示例请参考此博客:TFS API - TRACK CHANGESET MERGE IN BRANCHES