Ok, to było zarówno łatwiejsze i trudniejsze, niż myślałem, że będzie. Byłem w stanie wyciągnąć to razem z kilku różnych źródeł, ale wydaje się, że to działa. Ostrzegam cię, nie ma tutaj obsługi błędów, a jeśli itemSpec nie istnieje, bombarduje z wyjątkiem.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
static void Main(string[] args)
{
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(
new Uri("http://tfs:8080"));
string srcFolder = "$/ProjectName";
var versionControl = tfs.GetService<VersionControlServer>();
ItemSpec[] specs = new ItemSpec[]{new ItemSpec(srcFolder, RecursionType.None)};
System.Console.WriteLine(string.Format("Source folder {0} was branched to:",
srcFolder));
BranchHistoryTreeItem[][] branchHistory =
versionControl.GetBranchHistory(specs, VersionSpec.Latest);
foreach (BranchHistoryTreeItem item in branchHistory[0][0].Children)
{
ShowChildren(item);
}
System.Console.WriteLine();
System.Console.WriteLine("Hit Enter to continue");
System.Console.ReadLine();
}
static void ShowChildren(BranchHistoryTreeItem parent)
{
foreach (BranchHistoryTreeItem item in parent.Children)
{
System.Console.WriteLine(
string.Format("Branched to {0}",
item.Relative.BranchToItem.ServerItem));
if (item.Children.Count > 0)
{
foreach(BranchHistoryTreeItem child in item.Children)
{
ShowChildren(child);
}
}
}
}
I może być brakuje czegoś tutaj, ale wydaje się, że QueryMergeRelationships zwraca listę elementów, gdzie istnieje jakikolwiek związek w ogóle, w tym związku macierzystego, w przeciwieństwie do zmiennej nazewnictwa; Twój kod zakłada, że używasz gałęzi głównej, a następnie dostarczysz listę wszystkich dzieci, ponieważ jest to root. Ale jeśli przejdziesz w gałęzi dziecka, zwróci ona także gałąź macierzystą, która nie spełnia wymagań pytania kapitana Comic, "muszę dowiedzieć się, jakie inne foldery zostały z niego rozgałęzione", co domyślnie oznacza tylko dziecko gałęzie są wymagane. – paulyphonic
Prawda. Zmodyfikowałem zmienne i nazwę metody. W interfejsie API może istnieć sposób określania, która ścieżka jest elementem nadrzędnym i wykluczania go. –