Question

I would like to see all files that are locked. so far, I've only found to use tf.exe status and look for anything with '!' because they are not reported as "lock, edit" as they are in the UI. Any ideas? thanks.

Was it helpful?

Solution

If you have the power tools installed, it's a one-liner:

tfstatus . -r -user * | % { $_.pendingchanges } | ? { $_.islock } | select -unique serveritem

If you prefer GUIs to scripts, try TFS Sidekicks.

OTHER TIPS

If you are trying to use TFS Sidekicks, and can't figure out how, it is under Tools, Team Foundation Sidekicks, Status Sidekick. You will need to expand that window, but you will then be able to search for locks for a username.

I don't think this is possible using tf.exe or even tfpt.exe (The Power Tool command line). You'll need to look through the pending changesets for changes that are locks. You could do this in powershell using the Power Tool commandlets or you could do it using the following bit of .NET code that exercises the TFS API:

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace TfsApiExample
{
  class Program
  {
    static void Main(string[] args)
    {
      GetLockedFiles("http://tfsserver:8080","$/TeamProject");
    }

    private static void GetLockedFiles(string serverUrl, string serverPath)
    {
      TeamFoundationServer tfs = new TeamFoundationServer(serverUrl);
      VersionControlServer vcServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

      // Search for pending sets for all users in all 
      // workspaces under the passed path.
      PendingSet[] pendingSets = vcServer.QueryPendingSets(
          new string[] { serverPath }, 
          RecursionType.Full, 
          null, 
          null);

      Console.WriteLine(
          "Found {0} pending sets under {1}. Searching for Locks...",
          pendingSets.Length, 
          serverPath);

      foreach (PendingSet changeset in pendingSets)
      {
        foreach(PendingChange change in changeset.PendingChanges)
        {
          if (change.IsLock)
          {
            // We have a lock, display details about it.
            Console.WriteLine(
                "{0} : Locked for {1} by {2}",
                change.ServerItem, 
                change.LockLevelName, 
                changeset.OwnerName);
          }
        }
      }

    }
  }
}

from your command prompt

>powershell

Then from powershell do:

PS > tf info * -recursive | &{
 begin{
  $out=@{}
  $prefix = "loc"
 }
 process{
  if ($_ -match "Local information"){
   if ($out.Count -gt 0) {
    [pscustomobject]$out
    $out=@{}
    $prefix = "loc"
   }
  } ElseIf ($_ -match "Server information"){
   $prefix = "svr"
  } else {
   $parts = $_.Split(':')
   if ($parts.Length -eq 2){
    $out.Add($prefix + $parts[0].Trim(), $parts[1].Trim())
   }
  }
 }
 end{
  if ($out.Count -gt 0) {
   [pscustomobject]$out
  }
 }
} | where {!($_.svrLock -eq 'none')}

I've found a GUI option.

  1. Start Visual Studio
  2. Open file
  3. Go to source control
  4. Then workspaces
  5. Enter your credentials
  6. Check show remote workspaces
  7. Remove all unwanted workspaces

That simple :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top