Tag Archive for hg

Mercurial as a Git client

Days ago I just published a short blog post about using Mercurial as a SVN Client, I know, Subversion is the “now-legacy-vcs-system” and Git with Mercurial are the “cool kids” in the school, why not make them work together?

Well, in the same way we could make Subversion works with Hg (using extensions of course) we could make Git works with Mercurial. It requires a little more work in Windows but it stills easy to do. As usual we start with a TortoiseHg installation. I will try to show its installation in a short set of steps:

  • We need to activate the Mercurial Bookmark and rebase extensions (these extensions are included with standard Mercurial installation). Edit your mercurial.ini file and add the following to the [extensions] section
  • [extensions]
    rebase =
    hgext.bookmarks = 
  • HgGit needs a special python library to handle Git repositories, this library is named dulwich. You need to get it from its source repository, clone it in some directory

    hg clone http://bitbucket.org/abderrahim/dulwich
  • Now we need to get the HgGit source code from its repository, let’s clone it from repository

    hg clone http://bitbucket.org/durin42/hg-git
  • This is the hard part, we need to tell to HgGit the location where the dulwich library is installed. Remember, both HgGit and dalwich are Python libraries, so we’ll edit just a file to show where to get dalwich. Go to the place you cloned HgGit search and open the file __init__.py and add look for the following code and add the code highlighted
    import os
    
    # NOTE: Added for tortoisehg compatibility
    import sys
    sys.path.append('write here the directory where dulwich was cloned')
    
    from mercurial import commands, extensions, hg, util as hgutil
    from mercurial.i18n import _
  • Now let’s activate the extension, open again your mercurial.ini file and add the following line to your [extensions] section

    hggit = directory where hggit where clonedhggit

And that is all, just test your extension installation with hg help extensions And look for hggit

Now you can clone, rebase, push, pull and do whatever you do with mercurial but using remote git repositories, for example, now you can do something like

hg clone http://github.com/castleproject/Castle.Core.git castle

I hope this guide could help you to get more fun from Mercurial, see you later!

Mercurial as a SVN client

Our friend Fabio Maulo published a few days ago about converting Subversion repositories into Mercurial, so in that way we could “rid off” svn repositories and move into Mercurial. Well, I must admit, I love mercurial from first sight, but sometimes you could not afford transform the whole SVN repository, sometimes (probably because you are working on a client’s repository) you need to keep using Subversion as your main development repository but you will like to work with Mercurial as a SVN client (like a lot of people do using Git and Git-Svn).

As many of you remember, one of the biggest mercurial’s strong points is the support for extensions. There are extensions for almost anything, and all of them are written in Python language (an easy and very powerful programming language). There is a project named Hg-Svn, which allows us to use Mercurial as a Subversion client, treating our Subversion repository as a remote Mercurial repository, in that way we could use hg common remote operations (like push, pull, fetch).

Install it in Windows could become cumbersome, mainly because it is only available as Python source code and many Hg users in Windows doesn’t have a python interpreter. I will publish the easiest way to do it in Windows

  • Install TortoiseHg (if you don’t have installed already)
  • Enable rebase extension in your mercurial.ini (rebase = )
  • Fetch Hg-Svn source code from Bitbucket repository (http://bitbucket.org/durin42/hgsubversion) do it into a known directory.
  • Modify your mercurial.ini file and add svn as an extension, pointing it to the place you got hgsubversion, for example
    • svn = d:srchgsvnhgsubversion
  • Done!, just test your configuration with hg help extensions and look for svn

Use the extension is really easy, just clone from a subversion repository as you would do from a Mercurial repository.

hg clone svn+http://svn.caffeine-it.com/openrasta/ openrasta

And, of course, you may send your changes as you would do with a remote repo

hg push

If your changes creates a new head into your local hg repository, when you push to Subversion repository it will automatically rebase your head into subversion head, remember, subversion is a linear source control system.

Well, I hope it will help you to get more fun with your mercurial installation :)