Given a particular path of folder in tfs, I need to recursively find all files and folders within the folder for a given changeset. In other words, i need to get the transitive closure of a path in tfs for a given changeset. The problem I'm facing in doing so is listing the contents of a particular folder within tfs.. How would this be possible in C# ?
On the Source Control Explorer tab, in the Folders pane, select the folder that contains the item or items you want to add. Click the Add Items to Folder button. In the Add to Source Control dialog box, select the folder or items you want to add, and then click Next.
Right-Click If you have the Content Explorer, Project Organizer, Pending Changes window pane, or File List open, right-click the file you want to add and select Source Control > Add.
I'm assuming you want 'folder contents as of changeset X' and not 'folder contents that were part of changeset X'
GetItems is the right call to use, just pass in a version spec for the changeset you're interested in.
http://msdn.microsoft.com/en-US/library/bb138911.aspx
so, assuming you already have a reference to the VersionControlServer instance:
var myFolderAtChangeset17 = versionControlServer.GetItems("$/MyFolder", new ChangesetVersionSpec(17), RecursionType.Full);
If I misunderstood and you happen to want to 'folder contents that were part of changeset X', there's a few different ways of doing it, but getting the changeset with GetChangeset and just filtering the Changes is pretty simple.
Something like this might be more what you're looking for. This gets all changes in a changeset and iterates through them, identifying the ones in the given path. This could be shortened with a linq query, but I'm leaving it a bit more expanded to give the gist of what I'm trying to say:
TeamFoundationServer tfs = new TeamFoundationServer("http://tfs:8080");
VersionControlServer vcs = tfs.GetService<VersionControlServer>();
Changeset cs = vcs.GetChangeset(6284868);
foreach (Change change in cs.Changes)
{
if (change.Item.ServerItem.StartsWith("$/Application Common/Dev/src"))
{
System.Diagnostics.Debug.WriteLine(string.Format("Changeset {0}, file {1}, changes {2}",
cs.ChangesetId, change.Item.ServerItem, change.ChangeType.ToString()));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With