Disclaimer
Let me start with a disclaimer. I’ve only been using Mercurial for 2 days so my nomenclature may be completely wide of the mark. Hopefully this post will help other hgnewbies with what is probably a common requirement.
Introduction
I keep all of my pet projects in my own Subversion repository but I’ve recently decided to give this distributed version control shenanigans a whirl. I ummed and arred about Git or Mercurial, but in the end I plumped for Mercurial, with a bitbucket account, as it seems to have more ubiquitous support. I’m about to release a project I’ve been working on for the last week or so and thought it would be nice to release it via bitbucket – complete with the version history I’d build up in Subversion.
Turns out, it’s really rather easy!
I’m Converted!
I’m assuming at this point you have the commandline version of Mercurial (hg) installed and working. If you don’t then you should probably go and do that first 🙂 I’ve also assumed you’ve already created a mercurial repository (bitbucket or elsewhere) called “myproject”.
In my scenario I was converting a single project with no trunk, branch or tag directories. The convert command is capable of handling much more advanced scenarios – take a look at the documentation for more infomation.
First things first you need to edit your Mercurial settings (.hgrc for *nix, Mercurial.ini in your user dir for Windows) and add the following lines:
[extensions]
hgext.convert=
This will add the “convert” command extension to our client. Next up we clone our repository and use the new convert command to add the SVN changesets into it:
hg clone https://bitbucket.org/myuser/myproject
hg convert http://mysvn.server.com/svn/myproject/ myproject
The convert command will now start counting down the revisions and adding each one to our local hg repository. This may well take some time 🙂
Potential gotcha: it appears that the convert extension doesn’t work properly with Subversion repositories over http that require authentication. If you get multiple “http authorization required” messages and prompts for your username/password then you have a problem. The only solution I found was to temporarily disable authentication while I did the conversion 🙁
Once the conversion had finished we push our changes back:
cd myproject
hg push
Now at this point for me the push worked fine but my local repository had no files in it – despite insisting it was up to date. This may be my lack of knowledge on Mercurial, or it might be a bug, but deleting the myproject directory locally and cloning the remote repo again sorted things out.
Conclusion
All in all a pretty trivial task, albeit one that takes a while with a large repository. The only big issue is the authentication one I mention above – this may well be a showstopper for you if you can’t control the ACL on your Subversion repository.
Thank you so much for the instructions they were very useful. I have just moved my SVN repositories to HG and your instructions were the best. I also fond that https: would not work well and had to disable the authentication. Hg convert worked for me whereas hgconvert from the hgsvn code failed halfway through.
You said “Now at this point for me the push worked fine but my local repository had no files in it – despite insisting it was up to date. This may be my lack of knowledge on Mercurial, or it might be a bug, but deleting the myproject directory locally and cloning the remote repo again sorted things out.”
This happened to me to but then I realised that what you have done is populate your version of the repository not your working directory. All you have to do is hg update and all your files will appear.
Sometimes things can be soooo easy 🙂 Thanks for the tip!
I also encountered that multiple authentication problem, though i was entering correct username and password.
Drilling down the problem with –debug and –traceback, I found that I was missing python bindings for subversion.
So i did sudo apt-get install python-subversion
and it worked like a charm !! 🙂