Lets say the following is my TFS structure:
- Branches (Folder)
- Module1 (Folder)
- Branch1 (Branch with parent Dev)
- Branch2 (Branch with parent Branch1)
- Branch3 (Branch with parent Branch1)
- Module1 (Folder)
- Dev (Branch)
In code, I have access to my local workspace, as well as a VersionControlServer
object.
I want a method such as string GetParentPath(string path)
that would act like the following:
GetParentPath("$/Branches/Module1/Branch1"); // $/Dev
GetParentPath("$/Branches/Module1/Branch2"); // $/Branches/Module1/Branch1
GetParentPath("$/Branches/Module1/Branch3"); // $/Branches/Module1/Branch1
GetParentPath("$/Dev"); // throws an exception since there is no parent
I currently have the following, thought it worked, but it doesn't (and I didn't honestly expect it to work either)
private string GetParentPath(string path)
{
return versionControlServer.QueryMergeRelationships(path)?.LastOrDefault()?.Item;
}