Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Tfs Shelveset file contents at the command prompt?

I'm interested in getting the contents of a shelveset at the command prompt. Now, you would think that a cmdlet such as Get-TfsShelveset, available in the TFS Power Tools, would do this. You might also think that "tf.exe shelvesets" would do this.

However, unless I've missed something, I'm appalled to report that neither of these is the case. Instead, each command requires you to give it a shelveset name, and then simply regurgitates a single line item for that shelveset, along with some metadata about the shelveset such as creationdate, displayname, etc. But as far as I can tell, no way to tell what's actually in the shelf.

This is especially heinous for Get-TfsShelveset, which has the ability to include an array of file descriptors along with the Shelveset object it returns. I even tried to get clever, thinking that I could harvest the file names from using -WhatIf with Restore-TfsShelveset, but sadly Restore-TfsShelveset doesn't implement -WhatIf.

Please, someone tell me I'm wrong about this!

like image 743
bwerks Avatar asked Jul 01 '11 22:07

bwerks


2 Answers

tf status /shelveset:name

will list out the content of the named shelveset (you can also supplier an owner: see tf help status).

With the TFS PowerToy's PowerShell snapin:

Get-TfsPendingChange -Shelveset name

for the same information.

like image 78
Richard Avatar answered Sep 23 '22 01:09

Richard


It is possible to construct a small command-line application that uses the TFS SDK, which returns the list of files contained in a given shelveset.
The sample below assumes knowledge of the Shelveset name & it's owner:

using System;
using System.IO;
using System.Collections.ObjectModel;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace ShelvesetDetails
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri tfsUri = (args.Length < 1) ? new Uri("TFS_URI") : new Uri(args[0]);

            TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);

            ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(
                new[] { CatalogResourceTypes.ProjectCollection },
                false, CatalogQueryOptions.None);

            CatalogNode collectionNode = collectionNodes[0];

            Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
            TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);

            var vcServer = teamProjectCollection.GetService<VersionControlServer>();

            Shelveset[] shelves = vcServer.QueryShelvesets(
                "SHELVESET_NAME", "SHELVESET_OWNER");
            Shelveset shelveset = shelves[0];

            PendingSet[] sets = vcServer.QueryShelvedChanges(shelveset);
            foreach (PendingSet set in sets)
            {
                PendingChange[] changes = set.PendingChanges;
                foreach (PendingChange change in changes)
                {
                    Console.WriteLine(change.FileName);
                }
            }
        }
    }
}

Invoking this console app & catching the outcome during execution of the powershell should be possible.

like image 31
pantelif Avatar answered Sep 22 '22 01:09

pantelif