Undo / Unlock for Others with Team Foundation Version Control

Published 09 July 06 03:19 PM | dmckinstry

One typical scenario is the need to have an administrator (development lead, etc.) release the locks that a team member has placed on a file in the version control system.  This frequently occurs when a user has to make modifications to a locked file, and the peron who locked the file isn't available to unlock it. Team Foundation Version Control does support this capability, but is isn't complete obvious.  Here are the details...

The first step is making sure that you have the appropriate permissions.  The permissions are managed using the Source Control Explorer.  Each folder and file can be set to allow users or groups specific permissions, including: Unlock other user's changes and Undo other user's changes.  A user that is granted these permissions can perform the unlock or undo as described below.  By default, only the Project Administrators and Team Foundation Server Administrator groups have these permissions.

To actually perform the unlock or undo, you have to use the TF command from a Visual Studio command prompt.  It is somewhat unfortunate that these capabilities aren't available from Team Explorer or Source Control Explorer, but this is hopefully an infrequent enough administrative task that it doesn't cause too many issues.

The specific commands for unlock and undo are as follows:

TF LOCK filespec /LOCK:NONE /WORKSPACE:workspace;lock_user
TF UNDO filespec /WORKSPACE:workspace;checkout_user

The important things to realize about these commands are as follows:

  • Filespec will most frequently be a path to a file or folder in Team Foundation Vesion Control (TFVC).  For example: "$/MyTeamProject/MyFolder/Foo.cs".  If you have embedded spaces in the path, make sure to use quotes around the filespec.
  • Filespec can can be a local file (e.g., "C:\MyTeamProject\MyFolder\Foo.cs") only if that local path is in the workspace holding the lock or having the file checked out.  That means that it will have to be on the workstation of the user holding the lock/checkout.  You shouldn't need the workspace switch in this case, but I haven't actually verified this personally.
  • If TF can't detemine the server, you're also need a server switch on the command line (e.g., "/server:mytfs").
  • You can add the "/recursive" switch to unlock or undo all changes for a specific user recursively under a folder in TFVC.
  • The workspace can be queried by looking at the properties of the item in Source Control Explorer and switching to the Status tab.  It can also be queried using the TF command line utility.
  • The lock_user and checkout_user refer to the login for the user holding the lock or checkout.  For example: "notion\dmckinstry".

The examples above would look like this if you wanted to unlock the file "Foo.cs" from my "DaveWorkspace" workspace:

TF LOCK C:\MyTeamProject\MyFolder\Foo.cs /LOCK:NONE
       /WORKSPACE:DaveWorkspace;notion\dmckinstry

In theory, this same basic approach can be used to check in changes made by other users, but the note above pertaining to being in that user's workspace on their workstation would defintely apply.

 

Filed under:

Comments

No Comments

This Blog

Microsoft VSTS Blogs

MSDN Forums

VSTS Community Blogs

Syndication