May 20, 2010

Seting up Mercurial on a Mac with Murky and Bitbucket

Seting up Mercurial on a Mac with Murky and BitbucketI had quite some trouble setting up Mercurial/Murky to work the way I wanted it to, so I’m writing it down here so I can reference it in the future if I ever need to and maybe it can helps others too.

The default settings for Hg (Mercurial) don’t seem to be the most user-friendly. In particular I didn’t like the way the default pull/update/merge was working. Fortunately, you can tweak settings in Hg to make it work to your liking. You will need to edit the dot file .hgrc located in your home directory for this.

This is what my .hgrc file ended up looking like:

[ui]
username = Ali <bitbucket.user@myemail.com>
merge = /Applications/kdiff3.app/Contents/MacOS/kdiff3

[merge-tools]
kdiff3.args = $base $local $other -o $output

The [ui] and [merge-tools] sections ensure that Mercurial uses the tool I specified for the merge operation. I found that the default merge was adding changes from both conflicting files together into one – the changes being placed on separate lines, separated by symbols like >, -, < (the same way that the command-line diff tools works). Its very hard to read through the changes this way. By specifying an external merge tool of your choice, hg will call that merge tool and let it handle the merging. In this case, I choose kdiff3, which seems to be a popular free cross-platform tool. The kdiff3 merge shows me both the files side by side with the changes highlighted in colour. Its easier to figure out what’s changed this way. Here’s some more information on Mercurial merge tools:http://mercurial.selenic.com/wiki/MergeProgram

In the [ui] section, I also included a username part. This ensures that when I push to Bitbucket, it links my push to my bitbucket account. Otherwise it will display the username and machine you are committing from as your username. Refer to the FAQ for more details.

The version of Murky that I’m using (v0.8.1) doesn’t let you do a hg push if you checked out your repository through https. You can still do it through the command line, but that is annoying. So I suggest cloning your repository through the ssh url that bitbucket provides. This is a known issue and might be fixed in the future.

Comments (1)

  1. February 11, 2011
    Joshua Cartmell said...

    Just thought I’d mention (and so it could help anyone else) that I think your kdiff3 configuration is wrong. It did not work for me and was specifying the wrong output file. I think it has to do with specifying the full path to a merge tool, that makes it ignore the arguments specified (more on that here: http://selenic.com/pipermail/mercurial/2011-February/036973.html).
    To get it working I created a symlink like so:
    sudo ln -s /Applications/kdiff3.app/Contents/MacOS/kdiff3 /usr/local/bin
    Then I set up my .hgrc as specified here:
    http://mercurial.selenic.com/wiki/KDiff3
    Everything is working for me now.

Leave a Reply