Using Mercurial as a local repository for Team Foundation Server / Start Front’N
This post covers how to setup mercurial(HG) as are local source control repository to sit in front of a Team Foundation Server . I am not going to go into the details of why you would want to run this way in this post. You can look at the StackOverflow question that may give you more insight. For those of you who want to use mercurial for your day to day source control but have to synchronize your source code into a TFS server, this will allow you to do this.
The tools used for this process were lifted from blog posts all over the web.
The Tools.
- TFS 2010 Powertools
- Tortoise HG
- MakeWritable Mercurial Extension
- Rebase Mercurial Extension
- Two Powershell scripts to push and pull files to the TFS server (listed below)
Setting up the environment
- Download and install, TFS 2010 Powertools, Tortoise HG, and the MakeWritable Mercurial extension
- Enable the MakeWritable and Rebase extensions in mercurial.
- Edit your profiles Mercurial.ini file. Add the following section to the file.
[extensions]
makewritable = c:program files (x86)TortoiseHgmakewritable.py
rebase=
- Edit your profiles Mercurial.ini file. Add the following section to the file.
[extensions]
- Configure the TFS and HG repositories on your local file system.
- Setup your project repository from tfs in a folder. C:codeProject-from-TFS . This is the gold repository that is only used for merging changes to and from the TFS repository. You will never make changes to code in this repository.
- Make that folder a Mercurial Repository and add all the files from TFS into the mercurial repository and commit them to Mercurial.
- Make a second folder. This is your working folder. In this folder using mercurial clone from the gold repository.
- Place the push.ps1 and pull.ps1 files into the working folder and commit them to the local repository.
The Workflow
- Start developing your work.. If you want commit to branches and merge to the main when you want to push something to TFS.
- Commit your local work.
- Run the pull.ps1 command to pull down changes from tfs and merge them.
- Keep working and committing to mercurial
- When your ready to send your change to the TFS server commit your changes to mercurial and then run the push.ps1 command.
- The push.ps1 command will pop up one window for adding new files to TFS (if you have created new files as part of your dev work)
- The push.ps1 will pop up a commit dialog for TFS so that you can verifiy all the files going to TFS and enter a commit message.
Rinse and Repeat.
Show sample of pull.ps1
Show sample of push.ps1
This shows the results of running a pull command. By using the Rebase command needless merge commits just go away. You see the +1 heads text below, that suggests a merge is needed, and it normally is. By scripting the rebase command I essentially eliminate the need for the merge, except for when a true merge conflict exists.
Is this useful? Is there a better way to do this? Please let me know.