Saturday, January 22, 2011

Setting up a mercurial repository with bitbucket and Visual Studio awesomeness

Bit Bucket is awesome. The best thing about is that they provide private repositories for free! As long as you have lesser than 5 users. This is great for a consultant developer. Ofcourse if you are a consultancy you will probably upgrade.

A great tutorial for Mercurial by Joel is available here.

Anyways. Here is a quick way to get started with mercurial with visual studio. There are the things you need to do once. And then the things you need to to for each repository.

One time stuff

  • Signup for bitbucket
  • Download and install TortoiseHg.
  • Download and install VisualHg
  • Start Visual Studio. Goto Tools->Options. Select SourceControl. Select VisualHg from the drop down. Click Ok.
  • Select any folder On your computer where you will working off. Right click in windows explorer. And select Global Settings as shown.
  • click edit file and setup your bit bucket username / password and save the file.
For each new Software Development Contract
  • Goto bitbucket and create a new repository. Selecting whether you need to keep it private or not. e.g.
  • Right click (anywhere inside OR on) a folder (e.g. F:\temp\DotNetMVVM) that you will be working from. Select TortoiseHg -> clone. Type in the repository URL as the source path. e.g.
  • Now create a new Visual Studio project in that folder. Its better if you Check "Create a Solution Folder". Name the solution same as the folder you cloned to e.g. "DotNetMVVM" and give the solution path of one level up e.g. "F:\temp". This is shown:
  • If you set it up right as soon as the project / solution opens you will see the source control icons in Visual Studio (These are actually determined by the presence of .hg in the SAME folder as your sln file) :
  • Just right click the solution and select HgCommit. Enter the message. This will commit to your local repository. Finally to update the server when your code is nice and ready (and you want to inflict it on the world) select hg synchronize and then push. Type in your password. 
  • Also you can permanently store you password by clicking configure -> synchronize -> Edit as shown:
Trouble shooting tortoiseHG:

TortoiseHg does not show any dialog
Setting up at another machine tortoise Hg stopped working. If I right click in windows explorer and select any item from the TortoiseHg submenu nothing came up. This is probably due to an error in the global settings file. 

I navigated to "C:\Program Files\TortoiseHg" (where I had installed tortoisehg) and just ran the hg command in the command prompt:

I had some mistake in my global settings. (Note that it gave me the global settings path as c:\users\ebasali\mercurial.ini) 
I just edited it manually to remove the erroneous lines.
You get a Url open error while cloning the repository:
Sample Error:

If you are using a proxy server make sure you enable it in global settings:

After this you can check use proxy server in clone.

Note: Mercurial cannot detect your internet explorer settings so you need to do this manually.


Update: I got this T-Shirt as a thank you for this post. Totally not required but totally appreciated mates :)

Update March 2011: I also really liked this tutorial :

Update June 2011: There is another quite nice workflow. I havent made screenshots of it yet but here it is:

  •  right click while in the root folder which you want to be managed by mercurial and select Tortoise Hg -- Create Repository here. Select Ok.
  • Right click while in the folder and select Tortoise Hg -- Synchronize. Select configure. Setup the bitbucket path / password as before. And finally push.