Binary Lion Studios

I code for fun and for food.

Using FileMerge for merges with Mercurial

As a follow-up to the last post, you can also use FileMerge to handle merges with Mercurial.

Write a script and put it on your $PATH

First, you need to write a script that will force opendiff to wait before returning during a merge. Name the script opendiff-w.

1
2
# opendiff-w
opendiff "$@" | cat

Then you need to make it executable.

1
$ chmod u+x opendiff-w

Finally, put the script on your $PATH. I put mine in a folder called ~/development/scripts/path, and added this to my ~/.profile:

1
export PATH=$PATH:~development/scripts/path

Source the file and make sure you can execute the file you just created.

1
2
3
$ source ~/.profile
$ opendiff-w
opendiff[1234:56f] too few arguments

Tell Mercurial to use opendiff-w for merges

Edit your ~/.hgrc file and add the following:

~/.hgrc
1
2
3
4
5
6
[merge-patterns]
** = filemerge

[merge-tools]
filemerge.executable = /Users/user.name/path/to/opendiff-w
filemerge.args = $local $other -ancestor $base -merge $output

Make sure your executable path includes the opendiff-w at the end. For example, mine is:

1
filemerge.executable = /Users/user.name/development/scripts/path/opendiff-w

You are good to go. Next time you do a hg merge, Mercurial will use FileMerge to let you manually fix the conflict.