查找合并分支的TFS路径
使用TFS,我有躯干 $ /项目/主干
和分支 $ /项目的/ dev /功能/ 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,找到分公司的仓库路径合并 $ /项目的/ dev /功能/ 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,我只能得到修改文件的路径,如 $ /项目的/ dev /功能/ new_one /路径/要/ 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).
只是要知道,我已经被烧毁由这个时候使用 QueryRootBranchObjects
在2012年TFS的原因是一些虚假的家分行曾在分支名撇号的连接问题。
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.