This is not yet tested (still have to do that): it's a base for discussion and something which I think reasonable. It does not touch the old behavior of "emerge" apart from calling Emacs with option -q foregoing user-specific initializations, and preselects "ediff" only where EDITOR/VISUAL suggest Emacs being used as a normal editor. Here goes: Most actual Emacs users prefer ediff to emerge concerning the consolidation of versions. In general, people habitually using Emacs will have this preference reflected in the EDITOR/VISUAL environment variables. If such a preference can be found there, ediff will be used/offered in preference of emerge (which retains its previous behavior). In ediff mode, success or failure of the merge will be discerned by Emacs either having written or not written the merge buffer; no attempt of interpreting the exit code is made. This is much closer to the working habits of Emacs users than the emerge behavior which uses Emacs as a one-shot session editor. In order to bypass things like desktop files being loaded, emerge mode now passes the "-q" option to Emacs. This will make it work in more situations likely to occur, at the price of excluding possibly harmless user customizations with the rest. --- git-mergetool.sh | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 36 insertions(+), 14 deletions(-) diff --git a/git-mergetool.sh b/git-mergetool.sh index 47a8055..8ed3ed4 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -251,13 +251,27 @@ merge_file () { ;; emerge) if base_present ; then - emacs -f emerge-files-with-ancestor-command "$LOCAL" "$REMOTE" "$BASE" "$path" + emacs -q -f emerge-files-with-ancestor-command "$LOCAL" "$REMOTE" "$BASE" "$path" else - emacs -f emerge-files-command "$LOCAL" "$REMOTE" "$path" + emacs -q -f emerge-files-command "$LOCAL" "$REMOTE" "$path" fi status=$? save_backup ;; + ediff) + case "${EDITOR:-${VISUAL:-emacs}}" in + */emacs*|*/gnuclient*|*/xemacs*) + emacs_candidate="${EDITOR:-${VISUAL:-emacs}}";; + *) + emacs_candidate=emacs;; + esac + if base_present ; then + ${emacs_candidate} --eval "(ediff-merge-files-with-ancestor (pop command-line-args-left) (pop command-line-args-left) (pop command-line-args-left) nil (pop-command-line-args-left))" "$LOCAL" "$REMOTE" "$BASE" "$path" + else + ${emacs_candidate} --eval "(ediff-merge-files (pop command-line-args-left) (pop command-line-args-left) nil (pop-command-line-args-left))" "$LOCAL" "$REMOTE" "$path" + fi + check_unchanged + save_backup esac if test "$status" -ne 0; then echo "merge of $path failed" 1>&2 @@ -299,7 +313,7 @@ done if test -z "$merge_tool"; then merge_tool=`git config merge.tool` case "$merge_tool" in - kdiff3 | tkdiff | xxdiff | meld | opendiff | emerge | vimdiff | gvimdiff | "") + kdiff3 | tkdiff | xxdiff | meld | opendiff | emerge | ediff | vimdiff | gvimdiff | "") ;; # happy *) echo >&2 "git config option merge.tool set to unknown tool: $merge_tool" @@ -319,23 +333,26 @@ if test -z "$merge_tool" ; then merge_tool_candidates="kdiff3 $merge_tool_candidates" fi fi - if echo "${VISUAL:-$EDITOR}" | grep 'emacs' > /dev/null 2>&1; then - merge_tool_candidates="$merge_tool_candidates emerge" - fi + case "${EDITOR:-${VISUAL}}" in + */emacs*|*/gnuclient*|*/xemacs*) + merge_tool_candidates="$merge_tool_candidates ediff" + esac if echo "${VISUAL:-$EDITOR}" | grep 'vim' > /dev/null 2>&1; then merge_tool_candidates="$merge_tool_candidates vimdiff" fi merge_tool_candidates="$merge_tool_candidates opendiff emerge vimdiff" echo "merge tool candidates: $merge_tool_candidates" for i in $merge_tool_candidates; do - if test $i = emerge ; then - cmd=emacs - else - cmd=$i - fi - if type $cmd > /dev/null 2>&1; then - merge_tool=$i - break + case $i in emerge) + cmd=emacs;; + ediff) + merge_tool=$i + break;; + *) cmd=$i + esac + if type $cmd > /dev/null 2>&1; then + merge_tool=$i + break fi done if test -z "$merge_tool" ; then @@ -357,6 +374,11 @@ case "$merge_tool" in exit 1 fi ;; + ediff) + if ! (set ${EDITOR:-${VISUAL:-emacs}}; type "$1" > /dev/null 2>&1); then + echo "${EDITOR:-${VISUAL:-emacs}} is not available" + exit 1 + fi *) echo "Unknown merge tool: $merge_tool" exit 1 -- 1.5.2.3 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html