Team Foundation Server and Xcode Projects with git-tf

August 20, 2012

Brian Harry announced the availability of git-tf last Monday, a new tool from Microsoft thatallows you to create a local git repository from a path in Team FoundationServer, then check the changes in your repository back in to TFS.  Thistool is another piece in our cross-platform support, aimed at users of IDEsthat don't have built-in TFS integration.

We hope that Xcode users will find this particularly useful, as Xcodesadly lacks a plug-in model that would allow us to build TFS supportnatively.  Xcode does have git support, however, so once you've createdyour git repository with git-tf, you can use Xcode's source codeintegration directly.

This means that if you're writing mobile applications, you can now useTeam Foundation Server as your ALM solution for the entire development team. Imagine you have your shared business logic in C, you have a WindowsPhone 8 version being developed in Visual Studio, an Android version beingdeveloped in Eclipse and an iOS version being developed in Xcode.  Nowall your developers can take advantage of TFS Version Control - your VisualStudio users with Team Explorer, your Eclipse users with the TFS Plug-in forEclipse and your Xcode users with git-tf.

I'm too hopelessly old-school to be hip to the new mobile apps, so I'mgoing toshow how I work on a cross-platform command-line application that playsblackjack.  I've got my source in TFS, with an Xcode projectside-by-side with my Visual Studio solution:

Once I have Xcode and git-tf installed on my Mac, I can download thisproject easily:

ethomson@mbp:~/Demo% git tf clone --deep http://tfs2012:8080/tfs/DefaultCollection $/DefaultAgile/blackjack
Username: ethomson
Password:
Connecting to TFS...
Cloning $/DefaultAgile/blackjack into /Users/ethomson/Demo/blackjack: 100%, done.
Cloned 14 changesets.  Cloned last changeset 19 as fb65c36

Now I have a git repository that represents my TFS changesets, with fullhistory.  (That was the --deep option, without that I would have a single git committhat represents my latest TFS changeset.  This is quicker to computeand useful if you don't need full history.)  You can see that myhistory in Visual Studio:

is the same as the history in my local git repository:

ethomson@mbp:~/Demo/blackjack% git log
commit f33b75c0190d76c417fd5d724236a9c3f731b185
Author: tfsuser <tfs2012\tfsuser>
Date:   Tue Aug 14 15:20:20 2012 -0500

    This is a commit from Xcode
	
commit a88b3887f1998fac74beb8ee32b4d91e06d8e625
Author: ethomson <tfs2012\ethomson>
Date:   Tue Aug 14 15:16:16 2012 -0500

    This is a change from Visual Studio.

...etc...

When I open up this project in Xcode, you'll notice that when I startmaking changes to files, they're automatically added to my git index, asdenoted by the small M next to the filename in ProjectNavigator.  Below, I've made some changes to my project's assertionlogic, changing Assert.cpp and Assert.h.

When Xcode's source control integration, I can commit these changes to mylocal git repository from right within my IDE.  When committing, itwill show a handy diff viewer for each file in my commit.

You can see the two commits I've made in my Xcode project in my gitlog.

ethomson@mbp:~/Demo/blackjack% git log
commit 6f9bbafa5482c77de5b97b2548320b78de6b82fe
Author: Edward Thomson <ethomson@edwardthomson.com>
Date:   Thu Aug 16 15:58:43 2012 -0500

    Fixed some typos in the comments.

commit 8dd92848b4ea0f6549d6f88d28e47c3e1201cd7c
Author: Edward Thomson <ethomson@edwardthomson.com>
Date:   Thu Aug 16 15:55:01 2012 -0500

    A couple of minor changes in Xcode

...etc...

Once I'm done making changes locally and I want to integrate with the rest of the team, I can check them in to my TFS server using git-tf checkin.  Just like when I cloned my project, I can use the --deep option to preserve history.

ethomson@mbp:~/Demo/blackjack% git tf checkin --deep
Username: ethomson
Password: 
Connecting to TFS...
Checking in to $/DefaultAgile/blackjack: 100%, done.
Checked in 2 changesets, HEAD is changeset 21

Back in Visual Studio, you can see both of these changesets in my TFShistory.

And, of course, since I'm doing Continuous Integration builds for thisproject, as soon as I checkin from git-tf, TFS queues up a build for me. In this case, I get two - one for each changeset, since I did a deepcheckin from my two git commits.

So you can see that now I can easily use Xcode to take advantage of theALM functionality of Team Foundation Server, providing every developer on ateam with intuitive access to TFS Version Control.

git-tf is availablenow on CodePlex, Microsoft's Project Hosting for Open Source Softwareand we're making git-tf available open source under the MIT license. We think this is a very useful tool right now, and we're lookingforward to making it even better.