1. Oleg Tarasov
  2. HgTfs

Wiki

Clone wiki

HgTfs / Home

Mercurial to TFS bridge

The background

I work at a large company which uses TFS for all of its source control and task management needs. In most cases this works great, but sometimes I work on a project that involves a lot of experimenting with unconventional ninja-style techniques. I'm used to a “branch per experiment” kind of workflow with Mercurial, but it's really hard to implement this workflow with TFS, especially when the project is large and creating new branches gets really painful. So I decided to use a Mercurial clone for my experiments and then push more or less stable code to TFS. I was really surprised to find a total absense of tools which would help me to accomplish this task. And yes, I know about Git, but still prefer Mercurial. So naturally, I set out to write my very own Mercurial-Tfs bridge.

The workflow

It's important to understand the workflow for which this tool was created.

First of all, we take our TFS working copy and clone a new Mercurial repository from it. Then we work in our new sandbox completely disconnected from TFS. When we are ready, we just push all our changes to TFS in a single changeset. We can also pull changes from TFS into our Mercurial repo.

Branching model

This workflow implies that default is your main branch to which you pull changes from TFS and from which you push your code to the outside world. When you want to experiment, you create a new branch and crunch some crazy code there. When you feel confident enough, you merge that branch into default and then push your changes to TFS. If the experiment goes wrong, you can just abandon that branch. The picture at the beginning of this post illustrates this kind of workflow.

Limitations

There are almost none. You can use whatever workflow you like, keeping in mind that hgtfs always works with your current revision (the one you are updated to). It doesn't perform much validation and generally does what you ask it to do. So if you ask it to shoot you with a railgun, it will do just that.

Updated