Category Archives: 16830

Cloning tfs repository with git-tf gives a "a server path must be absolute"

I am currently involved in moving some TFS TFVC hosted source to a TFS Git repository.  The first step was to clone the source for a team project from TFS using the command

git tf clone --deep http://tfsserver01:8080/tfs/defaultcollection ‘$My Project’ localrepo1

and it worked fine. However the next project I tried to move had no space in the source path

git tf clone --deep http://tfsserver01:8080/tfs/defaultcollection ‘$MyProject’ localrepo2

This gave the error

git-tf: A server path must be absolute.

Turns out if the problem was the single quotes. Remove these and the command worked as expected

git tf clone --deep http://tfsserver01:8080/tfs/defaultcollection $MyProject localrepo2

Seems you should only use the quotes when there are spaces in a path name.

Why can’t I find my build settings on a Git based project on TFS Service?

Just wasted a bit of time trying to find the build tab on a TFS Team Project hosted on the hosted http://tfs.visualstudio.com using a Git repository. I was looking on team explorer expecting to see something like

image

But all I was seeing the the Visual Studio Git Changes option (just the top bit on the left panel above).

It took to me ages to realise that the issue was I had cloned the Git repository to my local PC using the Visual Studio Tools for Git. So I was just using just Git tools, not TFS tools. As far as Visual Studio was concerned this was just some Git repository it could have been local, GitHub, TFS Service or anything that hosts Git.

To see the full features of TFS Service you need to connect to the service using Team Explorer (the green bits), not just as a Git client (the red bits)

image

Of course if you only need Git based source code management tools, just clone the repository and use the Git tooling, where inside or outside Visual Studio. The Git repository in TFS is just a standard Git repro so all tools should work. From the server end TFS does not care what client you use, in fact it will still associate you commits, irrespective of client, with TFS work items if you use the #1234 syntax for work item IDs in your comments.

However if you are using hosted TFS from Visual Studio, it probably makes more sense to use a Team Explorer connection so all the other TFS feature light up, such as build. The best bit is that all the Git tools are still there as Visual Studio knows it is still just a Git repository. Maybe doing this will be less confusing when I come to try to use a TFS feature!

Using git tf to migrate code between TFS servers retaining history

Martin Hinshelwood did a recent post on moving source code between TFS servers using  git tf. He mentioned that you could use the –deep option to get the whole changeset check-in history.

Being fairly new to using Git, in anything other than the simplest scenarios, it took me a while to get the commands right. This is what I used in the end (using the Brian Keller VM for sample data) …

C:\tmp\git> git tf clone http://vsalm:8080/tfs/fabrikamfibercollection $/fabrikamfiber/Main oldserver –deep

Connecting to TFS…

Cloning $/fabrikamfiber/Main into C:\Tmp\git\oldserver: 100%, done.

Cloned 5 changesets. Cloned last changeset 24 as 8b00d7d

C:\tmp\git> git init newserver

Initialized empty Git repository in C:/tmp/git/newserver/.git/

C:\tmp\git> cd newserver

C:\tmp\git\newserver [master]> git pull ..\oldserver –depth=100000000

remote: Counting objects: 372, done.

remote: Compressing objects: 100% (350/350), done.

96% (358/372), 2.09 MiB | 4.14 MiB/s

Receiving objects: 100% (372/372), 2.19 MiB | 4.14 MiB/s, done.

Resolving deltas: 100% (110/110), done.

From ..\oldserver

* branch HEAD -> FETCH_HEAD

C:\tmp\git\newserver [master]> git tf configure http://vsalm:8080/tfs/fabrikamfibercollection $/fabrikamfiber/NewLocation

Configuring repository

C:\tmp\git\newserver [master]> git tf checkin –deep –autosquash

Connecting to TFS…

Checking in to $/fabrikamfiber/NewLocation: 100%, done.

Checked in 5 changesets, HEAD is changeset 30

The key was I had missed the –autosquash option on the final checkin.

Once this was run I could see my checking history, the process is quick and once you have the right command line straight forward. However, just like TFS Integration Platform time is compressed, and unlike TFS Integration Platform you also lose the ownership of the original edits.

image

This all said, another useful tool in the migration arsenal.

A bit of an edge case – Using Git-TFS to get the best (or worst?) of both worlds

Background

Whilst at the Microsoft MVP summit there are a number of MVP2MVP sessions, these are similar to DDD style sessions with MVPs presenting as opposed to Microsoft staff. One I found really interesting was one by Richard Banks based on his post on using GIT with TFS. Now this was a usage of source control tools I had not considered, a mixture of Git and TFS (or could be Git to SVN, similar tools are available)

Why do you want this usage? Especially with local workspaces coming in TFS11?

The simple answer is it allows a developer to have the advantage of Git’s multiple local versions of a given file, that they can branch, merge and rollback to as required. All prior to pushing all the changes up to a central TFS server (as opposed to GitHub or a company central Git repository).

OK lets face it this is an edge case, and it is not helped by the usage being command line driven, as opposed to be integrated with the IDE (real developers don’t use a UI or mouse, so that is OK – right?). So to try to make life a it easier I would suggest also installing Posh Git.

Setup

So what is required to get this running, if you like me a fairly new to Git there are a couple of gotcha’s. Here is the process I followed

I used Chocolaty (think Nuget for applications) to install tfsgit, this handles the dependency for the Git client

cinst tfsgit

Next I install poshgit

cinst poshgit

It is essential that you edit your Windows PATH environment variable to point to both the Git and the TFSGit folders as this is how Git picks up the extra Tfs commands, it should be something similar too this

PATH= $PATH;C:\Program Files (x86)\Git\cmd;C:\tools\gittfs

Finally for poshgit  you need runs its install script (in a PowerShell windows with elevated privileges), so it can report the number of file changes in the command prompt (note the prompt only changes when you are in a Git folder)

c:\tools\postgit\..some version\install.ps1

So hopefully this will get you going, so you can try this interesting edge case.

For more general chat on Git and distributed source control try this recent Herding Code podcast