找到合并分支的tfs路径 [英] Find the tfs path of merged branch

查看:37
本文介绍了找到合并分支的tfs路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 TFS,我有主干 $/project/trunk 和分支 $/project/dev/feature/new_one.

Using TFS, I have trunk $/project/trunk and a branch $/project/dev/feature/new_one.

我已将我的分支合并回主干,如下所示:

I have merged my branch back to trunk as follows:

C33($/project/trunk)
|  \
|   \
|    C32($/project/dev/feature/new_one)
|     |
|     |
|     |
...

我使用 TFS API,可以找到合并变更集 C33.使用 QueryMerges() 方法,我可以找到包含所有文件更改的父变更集 C32,但找不到我需要的信息:(

I use the TFS API and can find the merge changeset C33. With the method QueryMerges(), I'm able to find the parent changeset C32 with all the changes on the files, but not the information I need :(

有没有办法,使用TFS API,找到分支合并$/project/dev/feature/new_one的仓库路径?

Is there a way, using the TFS API, to find the repository path of the branch merged $/project/dev/feature/new_one?

使用变更集 C32,我只能获取修改文件的路径,例如 $/project/dev/feature/new_one/path/to/file.txt 但我无法从文件的完整路径中提取分支的路径:(

With the changeset C32, I'm only able to get paths of modified files, like $/project/dev/feature/new_one/path/to/file.txt but I'm unable to extract the path of the branch from the full path of the file :(

PS:自 TFS2008 起工作的解决方案将是最好的,但如果它仅自 2010 年起工作,它应该是好的......

PS : A solution working since TFS2008 will be the best, but if it works only since 2010, it should be good...

PS2:解决这个问题将有助于管理我开发的 git-tfs 中的合并变更集...

PS2 : solving this problem will help to manage merge changesets in git-tfs which I develop...

推荐答案

不幸的是,没有 API 方法可以获取给定项目路径的分支,您会认为这是一个相当常见的用例.

Unfortunately there is no API method to get a branch for a given item path, which you would think is a fairly common use case.

从 TFS 2010 开始,您可以使用 VersionControlServer.QueryRootBranchObjects 查询版本控制中的所有分支.使用RecursionType.Full 作为此方法的参数,您将获得一个BranchObject 数组,其中包含所有没有父 其所有后代的分支.然后,您可以按如下方式确定给定文件路径的分支:

TFS 2010 onwards you can use VersionControlServer.QueryRootBranchObjects to query all branches in version control. Using RecursionType.Full as the parameter to this method you will get a BranchObject array of all branches with no parent and all of their descendents. You can then determine a branch for a given file path as follows:

var collection = new TfsTeamProjectCollection(new Uri("http://tfsuri"));
var versionControl = collection.GetService<VersionControlServer>();

var branchObjects = versionControl.QueryRootBranchObjects(RecursionType.Full);

var mergeFilePath = "$/project/dev/feature/new_one/path/to/file.txt";
var branch = branchObjects.SingleOrDefault(b => {
            var branchPath = b.Properties.RootItem.Item;
            return mergeFilePath.StartsWith(branchPath.EndsWith("/") ? branchPath : branchPath + "/");
        });

Console.WriteLine(branch.Properties.RootItem.Item);

如图所示,分支的路径位于 BranchObject.Properties.RootItem.Item.我相信只需检查合并文件的路径中包含哪个分支的路径,就可以安全地在数组中找到相关的 BranchObject(假设最多只能匹配一个分支,因为 TFS 强制要求只有一个分支)分支可以存在于给定的文件夹层次结构中).

As shown, the path to the branch is at BranchObject.Properties.RootItem.Item. I believe it is safe to find the relevant BranchObject in the array simply by checking which branch's path is contained in the merge file's path (given it is only possible match at most one branch as TFS enforces that only one branch can exist in a given folder hierarchy).

请注意,我已经被this 在 TFS 2012 中使用 QueryRootBranchObjects 时出现连接问题.原因是一些分支名称中带有撇号的虚假分支.

Just to be aware, I have been burned by this Connect issue when using QueryRootBranchObjects in TFS 2012. The cause were some spurious branches that had apostrophes in the branch name.

解决方法是使用 VersionControlServer.QueryBranchObjects,但是这需要一个项目标识符,它是分支的确切路径.很明显,此时您不知道分支路径,因为您只有一个文件路径,因此您必须每次都调用 QueryBranchObjects 递归调用文件路径的目录,直到获得匹配项.

The workaround to this is to use VersionControlServer.QueryBranchObjects, however this takes an item identifier which is the exact path to the branch. Clearly you don't know the branch path at this point as all you have is a file path, so you have to recurse up the directories of the file path calling QueryBranchObjects each time until you get a match.

这篇关于找到合并分支的tfs路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆