UP | HOME

Using ediff3 from Emacs as merge-tool in Mercurial (hg)


PDF (drucken)

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:

2020-03-21-ediff3-0.png

or in Terminal-mode:

2020-03-21-ediff3-5.png

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:

2020-03-21-ediff3-1.png
2020-03-21-ediff3-2.png
2020-03-21-ediff3-3.png
2020-03-21-ediff3-4.png

Now close Emacs with CTRL-x CTRL-c.

Have fun!

Autor: ArneBab

Created: 2020-03-22 So 21:51

Emacs 26.3 (Org mode 9.3.6)

Validate