3

I previously had the following script in a file called .emacs.d/emerge-for-git:

#!/bin/sh
emacs -Q $*

And In my .gitconfig:

[merge]
  tool = emerge
[mergetool "emerge"]
  path = /home/rovanion/.emacs.d/emerge-for-git

But wishing to improve upon that so that it would connect to the already running emacsclient I ended up with the following lines:

#!/bin/sh
emacsclient -nw  --eval "(emerge-files nil \"$3\" \"$4\" \"${4}.out\")""\")"

But that ended up saving the merged file to source/path/path instead of source/path. So to save myself some grey hairs, and posterity of course, I decided to ask you instead:

How do you hook up git to your emacsclient?

1

I got a somewhat working solution going. In my .gitconfig I have:

[mergetool "emerge"]
    prompt = false
    cmd = emerge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"
trustExitCode = true

And in .local/bin/emerge

#!/bin/bash
set -e

local=$(readlink -f "$1")
remote=$(readlink -f "$2")
base=$(readlink -f "$3")
merged=$(readlink -f "$4")

emacsclient -nw --eval "(emerge-files-with-ancestor nil \"$local\" \"$remote\" \"$base\" \"$merged\")"

! egrep -q '^(<<<<<<<|=======$|>>>>>>>|####### Ancestor)' "$merged"

The remaining issue is that the emacsclient is not automatically killed when q is pressed.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.