#!/bin/sh # set -e # bail out quickly on failure if [ $# -ne 3 ]; then echo "Usage: $0 local base other" exit 1 fi LOCAL=`cd \`dirname $1\`; pwd`/`basename $1` # "$1" BASE=`cd \`dirname $2\`; pwd`/`basename $2` OTHER=`cd \`dirname $3\`; pwd`/`basename $3` BACKUP="$LOCAL.orig" Rm () { rm -f "$BACKUP" } Restore () { cp "$BACKUP" "$LOCAL" } ExitOK () { echo "ExitOK" Rm exit $? } # Back up our file cp "$LOCAL" "$BACKUP" # Attempt to do a non-interactive merge if which merge > /dev/null 2>&1 ; then if merge "$LOCAL" "$BASE" "$OTHER" 2> /dev/null; then # success! ExitOK fi Restore elif which diff3 > /dev/null 2>&1 ; then if diff3 -m "$BACKUP" "$BASE" "$OTHER" > "$LOCAL" ; then # success ExitOK fi Restore fi CMD="(ediff-merge-with-ancestor \"$BACKUP\" \"$OTHER\" \"$BASE\" nil \"$LOCAL\")" echo "$CMD" # if emacs -q --no-site-file --eval "(ediff-merge-with-ancestor \"$BACKUP\" \"$OTHER\" \"$BASE\" nil \"$LOCAL\")" if emacsclient --eval "$CMD" then ExitOK fi echo "emacs-merge: failed to merge files" exit 1 # End of file