Using ediff3 from Emacs as merge-tool in Mercurial (hg)
With Corona/COVID-19 raging through the country, many people are in full homeoffice, so you might need a merge-tool that works in the terminal and in graphical mode and still provides a convenient 3-way merge.

So here’s a simple guide to setup Emacs ediff3 as a merge-tool for Mercurial.
Prepare the ediff3-script in ~/.local/bin/ediff3
which runs emacs:
#!/bin/bash if [ $# -ne 4 ]; then echo Usage: $0 local other base output exit 1 fi exec emacs --eval '(ediff-merge-with-ancestor "'$1'" "'$2'" "'$3'" nil "'$4'")'
Make it executable:
chmod +x ~/.local/bin/ediff3
Remember to put ~/.local/bin/
in your PATH
by editing ~/.bashrc
:
# add ~/.local/bin to your search path export PATH="$HOME/.local/bin/:$PATH"
Then configure ediff3 as your merge-tool in ~/.hgrc
:
[ui] merge = ediff3 [merge-tools] ediff3.executable = ediff3 ediff3.args = $local $other $base $output
Try it out:
hg init /tmp/foo cd /tmp/foo echo 0 > 0 hg ci -Am 0 echo 1 > 0 hg ci -Am 1 hg up 0 echo 2 > 0 hg ci -Am 2 hg merge
You’ll see ediff3 in GUI mode:

or in Terminal-mode:

Type $$
to focus on conflicts. Type n
to jump to the first conflict. Hit a or b to select. You can edit as you wish.
Let’s finish the example merge-session with q
:




Now close Emacs with CTRL-x CTRL-c
.
Have fun!