Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

listing all contents of a folder in tfs

Tags:

c#

tfs

tfs-sdk

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# ?

like image 944
Sidd Avatar asked Jul 13 '10 18:07

Sidd


People also ask

How do I add a folder to TFS source control?

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.

How do I add files to TFS?

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.


2 Answers

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.

like image 71
James Manning Avatar answered Oct 01 '22 23:10

James Manning


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()));
        }
    }
like image 25
Robaticus Avatar answered Oct 01 '22 23:10

Robaticus