Code

Merge branch 'db/maint-missing-origin'
[git.git] / contrib / difftool / git-difftool-helper
index 10632a391731a490ac2db803dc885bcfe742ece9..9c0a13452a60059b504f07cb94a3cc16e1a2e6e7 100755 (executable)
@@ -128,8 +128,10 @@ launch_merge_tool () {
        cleanup_temp_files
 }
 
-# Verifies that mergetool.<tool>.cmd exists
+# Verifies that (difftool|mergetool).<tool>.cmd exists
 valid_custom_tool() {
+       merge_tool_cmd="$(git config difftool.$1.cmd)"
+       test -z "$merge_tool_cmd" &&
        merge_tool_cmd="$(git config mergetool.$1.cmd)"
        test -n "$merge_tool_cmd"
 }
@@ -150,8 +152,11 @@ valid_tool() {
 }
 
 # Sets up the merge_tool_path variable.
-# This handles the mergetool.<tool>.path configuration.
+# This handles the difftool.<tool>.path configuration.
+# This also falls back to mergetool defaults.
 init_merge_tool_path() {
+       merge_tool_path=$(git config difftool."$1".path)
+       test -z "$merge_tool_path" &&
        merge_tool_path=$(git config mergetool."$1".path)
        if test -z "$merge_tool_path"; then
                case "$1" in
@@ -165,15 +170,19 @@ init_merge_tool_path() {
        fi
 }
 
-# Allow the GIT_MERGE_TOOL variable to provide a default value
+# Allow GIT_DIFF_TOOL and GIT_MERGE_TOOL to provide default values
 test -n "$GIT_MERGE_TOOL" && merge_tool="$GIT_MERGE_TOOL"
+test -n "$GIT_DIFF_TOOL" && merge_tool="$GIT_DIFF_TOOL"
 
-# If not merge tool was specified then use the merge.tool
+# If merge tool was not specified then use the diff.tool
 # configuration variable.  If that's invalid then reset merge_tool.
+# Fallback to merge.tool.
 if test -z "$merge_tool"; then
+       merge_tool=$(git config diff.tool)
+       test -z "$merge_tool" &&
        merge_tool=$(git config merge.tool)
        if test -n "$merge_tool" && ! valid_tool "$merge_tool"; then
-               echo >&2 "git config option merge.tool set to unknown tool: $merge_tool"
+               echo >&2 "git config option diff.tool set to unknown tool: $merge_tool"
                echo >&2 "Resetting to default..."
                unset merge_tool
        fi
@@ -181,31 +190,24 @@ fi
 
 # Try to guess an appropriate merge tool if no tool has been set.
 if test -z "$merge_tool"; then
-
        # We have a $DISPLAY so try some common UNIX merge tools
        if test -n "$DISPLAY"; then
-               merge_tool_candidates="kdiff3 kompare tkdiff xxdiff meld gvimdiff"
-               # If gnome then prefer meld
-               if test -n "$GNOME_DESKTOP_SESSION_ID"; then
-                       merge_tool_candidates="meld $merge_tool_candidates"
-               fi
-               # If KDE then prefer kdiff3 or kompare
-               if test "$KDE_FULL_SESSION" = "true"; then
-                       merge_tool_candidates="kdiff3 kompare $merge_tool_candidates"
+               # 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"
+               else
+                       merge_tool_candidates="kdiff3 kompare tkdiff xxdiff meld gvimdiff"
                fi
        fi
-
-       # $EDITOR is emacs so add emerge as a candidate
        if echo "${VISUAL:-$EDITOR}" | grep 'emacs' > /dev/null 2>&1; then
-               merge_tool_candidates="$merge_tool_candidates emerge"
+               # $EDITOR is emacs so add emerge as a candidate
+               merge_tool_candidates="$merge_tool_candidates emerge opendiff vimdiff"
+       elif echo "${VISUAL:-$EDITOR}" | grep 'vim' > /dev/null 2>&1; then
+               # $EDITOR is vim so add vimdiff as a candidate
+               merge_tool_candidates="$merge_tool_candidates vimdiff opendiff emerge"
+       else
+               merge_tool_candidates="$merge_tool_candidates opendiff emerge vimdiff"
        fi
-
-       # $EDITOR is vim so add vimdiff as a candidate
-       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"
 
        # Loop over each candidate and stop when a valid merge tool is found.