difftool/mergetool: add diffuse as merge and diff tool
[gitweb.git] / contrib / difftool / git-difftool-helper
index 9c0a13452a60059b504f07cb94a3cc16e1a2e6e7..4b0daec5a7d0d90c18967974b87afbcc5fb6dc8b 100755 (executable)
@@ -1,7 +1,5 @@
 #!/bin/sh
 # git-difftool-helper is a GIT_EXTERNAL_DIFF-compatible diff tool launcher.
-# It supports kdiff3, kompare, tkdiff, xxdiff, meld, opendiff,
-# emerge, ecmerge, vimdiff, gvimdiff, and custom user-configurable tools.
 # This script is typically launched by using the 'git difftool'
 # convenience command.
 #
@@ -9,31 +7,7 @@
 
 # Set GIT_DIFFTOOL_NO_PROMPT to bypass the per-file prompt.
 should_prompt () {
-       ! test -n "$GIT_DIFFTOOL_NO_PROMPT"
-}
-
-# Should we keep the backup .orig file?
-keep_backup_mode="$(git config --bool merge.keepBackup || echo true)"
-keep_backup () {
-       test "$keep_backup_mode" = "true"
-}
-
-# This function manages the backup .orig file.
-# A backup $MERGED.orig file is created if changes are detected.
-cleanup_temp_files () {
-       if test -n "$MERGED"; then
-               if keep_backup && test "$MERGED" -nt "$BACKUP"; then
-                       test -f "$BACKUP" && mv -- "$BACKUP" "$MERGED.orig"
-               else
-                       rm -f -- "$BACKUP"
-               fi
-       fi
-}
-
-# This is called when users Ctrl-C out of git-difftool-helper
-sigint_handler () {
-       cleanup_temp_files
-       exit 1
+       test -z "$GIT_DIFFTOOL_NO_PROMPT"
 }
 
 # This function prepares temporary files and launches the appropriate
@@ -47,12 +21,6 @@ launch_merge_tool () {
        LOCAL="$2"
        REMOTE="$3"
        BASE="$1"
-       ext="$$$(expr "$MERGED" : '.*\(\.[^/]*\)$')"
-       BACKUP="$MERGED.BACKUP.$ext"
-
-       # Create and ensure that we clean up $BACKUP
-       test -f "$MERGED" && cp -- "$MERGED" "$BACKUP"
-       trap sigint_handler INT
 
        # $LOCAL and $REMOTE are temporary files so prompt
        # the user with the real $MERGED name before launching $merge_tool.
@@ -69,7 +37,7 @@ launch_merge_tool () {
                "$merge_tool_path" --auto \
                        --L1 "$basename (A)" \
                        --L2 "$basename (B)" \
-                       -o "$MERGED" "$LOCAL" "$REMOTE" \
+                       "$LOCAL" "$REMOTE" \
                        > /dev/null 2>&1
                ;;
 
@@ -78,34 +46,34 @@ launch_merge_tool () {
                ;;
 
        tkdiff)
-               "$merge_tool_path" -o "$MERGED" "$LOCAL" "$REMOTE"
+               "$merge_tool_path" "$LOCAL" "$REMOTE"
                ;;
 
        meld)
                "$merge_tool_path" "$LOCAL" "$REMOTE"
                ;;
 
+       diffuse)
+               "$merge_tool_path" "$LOCAL" "$REMOTE" | cat
+               ;;
+
        vimdiff)
-               "$merge_tool_path" -c "wincmd l" "$LOCAL" "$REMOTE"
+               "$merge_tool_path" -d -c "wincmd l" "$LOCAL" "$REMOTE"
                ;;
 
        gvimdiff)
-               "$merge_tool_path" -c "wincmd l" -f "$LOCAL" "$REMOTE"
+               "$merge_tool_path" -d -c "wincmd l" -f "$LOCAL" "$REMOTE"
                ;;
 
        xxdiff)
                "$merge_tool_path" \
-                       -X \
-                       -R 'Accel.SaveAsMerged: "Ctrl-S"' \
                        -R 'Accel.Search: "Ctrl+F"' \
                        -R 'Accel.SearchForward: "Ctrl-G"' \
-                       --merged-file "$MERGED" \
                        "$LOCAL" "$REMOTE"
                ;;
 
        opendiff)
-               "$merge_tool_path" "$LOCAL" "$REMOTE" \
-                       -merge "$MERGED" | cat
+               "$merge_tool_path" "$LOCAL" "$REMOTE" | cat
                ;;
 
        ecmerge)
@@ -124,8 +92,6 @@ launch_merge_tool () {
                fi
                ;;
        esac
-
-       cleanup_temp_files
 }
 
 # Verifies that (difftool|mergetool).<tool>.cmd exists
@@ -160,6 +126,12 @@ init_merge_tool_path() {
        merge_tool_path=$(git config mergetool."$1".path)
        if test -z "$merge_tool_path"; then
                case "$1" in
+               vimdiff)
+                       merge_tool_path=vim
+                       ;;
+               gvimdiff)
+                       merge_tool_path=gvim
+                       ;;
                emerge)
                        merge_tool_path=emacs
                        ;;
@@ -194,9 +166,9 @@ if test -z "$merge_tool"; then
        if test -n "$DISPLAY"; then
                # If gnome then prefer meld, otherwise, prefer kdiff3 or kompare
                if test -n "$GNOME_DESKTOP_SESSION_ID" ; then
-                       merge_tool_candidates="meld kdiff3 kompare tkdiff xxdiff gvimdiff"
+                       merge_tool_candidates="meld kdiff3 kompare tkdiff xxdiff gvimdiff diffuse"
                else
-                       merge_tool_candidates="kdiff3 kompare tkdiff xxdiff meld gvimdiff"
+                       merge_tool_candidates="kdiff3 kompare tkdiff xxdiff meld gvimdiff diffuse"
                fi
        fi
        if echo "${VISUAL:-$EDITOR}" | grep 'emacs' > /dev/null 2>&1; then