Web Development & Programming Thoughts

By Timothy Elliott

Team Foundation Version Control and the Linux Command Line

5/28/2012

Team Foundation Server (TFS) is a suite of development collaboration tools used by Microsoft Visual Studio. Team Explorer Everywhere (TEE) is an Eclipse plug-in and a command-line client that allow you to access TFS version control on any Java platform. Here are some tips for using TEE from the command line in Linux.

Installation

Download the latest TEE Command Line Client from the Team Explorer Everywhere website. Make sure to get the Command Line Client (CLC) download. Extract it to your home folder.

Bash Alias

The command line client doesn't like being invoked via symlink, so I found the best way to invoke it to be through a bash alias. In ~/.bash_alias:

alias tf='/home/tim/TEE-CLC-10.1.0/tf'

Supplying Credentials

Most commands will require that you supply your username and password via the -login option, and that you supply the server url via the -server option. It quickly becomes tedious to supply these options every time you invoke the client, so you will want to update your bash alias to include them:

alias tf='/home/tim/TEE-CLC-10.1.0/tf -login:MYDOMAIN\\myusername,mypass -server:https://mytfsserver/mypath'

Make sure to restart your Bash shell, and now you should be able to invoke tfs commands easily. For example, in order to list all directories in my TFS Team Project named MyProject:

$ tf dir $/MyProject
  $/MyProject:
  $Directory1
  $Directory2
  $...
  9 item(s).

Create a Mapping Between a Local Directory and Source Control

Now we can map a local directory to a directory in source control. You will first have to create a workspace, which contains the mappings and only needs to be created once:

$ tf workspace -new my_workspace
Workspace 'my_workspace' created.
$ tf workfold -map $/MyProject/Directory1 /home/tim/my_project_directory -workspace:my_workspace

Get the Latest Source Files

Anytime you want to get latest, go into your locally mapped directory and use the 'get' command:

$ tf get
/home/tim/my_project_directory:

/home/tim/my_project_directory/app:

/home/tim/my_project_directory/app/assets:

/home/tim/my_project_directory/app/assets/images:

/home/tim/my_project_directory/app/assets/javascripts:
Getting application.js
...

Open a File for Edit, Show a Diff, and Check In Your Changes

By default, all of your local files are set to be read-only. In TFS, you are supposed to check out files from the server before editing them. In the example below, TEE informs us that a coworker has the same file checked out:

$ tf checkout
  lib/tasks:
  myfile.rake
  $/MyProject/Directory1/lib/tasks/myfile.rake:
     opened for edit in WORKSPACE;DOMAIN\my_coworker

Now we can edit the file and get a diff of our changes. TEE requires that the TF_DIFF_COMMAND environment variable is set to the diff command. Here is an example using xxdiff:

TF_DIFF_COMMAND="xxdiff -r \"%1\" \"%2\"" tf diff

Since I don't want to have to supply all that information every time, and since I don't want to add another piece of TEE configuration to another file, I am going to add another bash alias in ~/.bash_aliases:

alias tfdiff='TF_DIFF_COMMAND="xxdiff \"%1\" \"%2\"" tf diff'

After reviewing your changes you can check the changes into source control:

$ tf checkin -comment:"This is my first checkin from Linux" lib/tasks/myfile.rake lib/tasks/myfile2.rake