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. https://bitbucket.org/basarat/mvvm-dotnet-samples
  • 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.   https://basarat@bitbucket.org/basarat/mvvm-dotnet-samples.
  • 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.

Enjoy!

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 : http://mercurial.aragost.com/kick-start/en/basic/#divergent-lines-of-development

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. 

15 comments:

  1. You could use your own webhost to deploy SVN repository. Then use all the SVN tools available include AnkhSVN for VisualStudio integration with SVN.

    ReplyDelete
  2. Yes but I really like the difference mercurial makes between commit/update and push/pull. Check out http://hginit.com/00.html . I am never going back to SVN ever again. And really. I have tried ankhSVN. Its great. But TortoiseHG / VisualHG are just really really faster!

    ReplyDelete
  3. I'm trying to use this tutorial to set up a connection to an existing repository. It worked successfully to set up a smaller repository, but on one of my larger ones I am having difficulty. Specifically, in the section where I right click on the local folder, select Clone from the TortoiseHg folder and specify the bitbucket URL to my repository - it begins the clone but always hangs at the 155th file and then, after a time, closes the connection. Any idea what the problem could be?

    ReplyDelete
    Replies
    1. Sorry. Never happened to me. Try and ask the question at stackoverflow.com with a screenshot. Probably a problem with your internet connection IMO.

      Delete
  4. Thanks for this write-up, really was the key in my effort to set up my first bit-bucket project!

    BK

    ReplyDelete
  5. Thanks works like a charm. Please fix tortoise hg link typo =)

    ReplyDelete
  6. Thanks... nice job

    ReplyDelete
  7. Thank you, very helpful.

    ReplyDelete
  8. jazakumullahu khairan... We had great difficulties in our group project at university when integrating each member's module. hope this will really help

    ReplyDelete
  9. Hey ! Thank you very much for this post, very helpful !

    I'm a beginner with source code management and I have one question :

    I create my repository, create a visual studo project in it, commit, and push.

    I want to retrieve this project for an other user. What are the steps ? Creating a folder to work offline, clone, and that's it ? I will be able to launch my project on another PC ?

    Thank you !

    Anthony B.

    ReplyDelete
  10. Awesome tutorial! Just took about me half an hour to create an account, install the plugin, create the repository and add some source files.

    Thanks!

    ReplyDelete
  11. when ever i try to clone a repository, i get "http error 404 not found"
    i'm using the source as following
    https://bitbucket.org//
    i turned off my firewall, tried to manually clone the repository using the hq.exe cmd app, but still no help.

    any thoughts?

    ReplyDelete
  12. Thank you very much for this, just what I needed

    ReplyDelete