git-mergetool: don't hardcode 'mergetool' in show_tool_help
[gitweb.git] / git-mergetool--lib.sh
index 54cb708254d38062983373c536589add648ae304..4c1e1292a68b28cc88483fc5edc0df775cf6eec4 100644 (file)
@@ -104,13 +104,49 @@ run_merge_tool () {
 
        if merge_mode
        then
-               merge_cmd "$1"
+               run_merge_cmd "$1"
        else
-               diff_cmd "$1"
+               run_diff_cmd "$1"
        fi
        return $status
 }
 
+# Run a either a configured or built-in diff tool
+run_diff_cmd () {
+       merge_tool_cmd="$(get_merge_tool_cmd "$1")"
+       if test -n "$merge_tool_cmd"
+       then
+               ( eval $merge_tool_cmd )
+               status=$?
+               return $status
+       else
+               diff_cmd "$1"
+       fi
+}
+
+# Run a either a configured or built-in merge tool
+run_merge_cmd () {
+       merge_tool_cmd="$(get_merge_tool_cmd "$1")"
+       if test -n "$merge_tool_cmd"
+       then
+               trust_exit_code="$(git config --bool \
+                       mergetool."$1".trustExitCode || echo false)"
+               if test "$trust_exit_code" = "false"
+               then
+                       touch "$BACKUP"
+                       ( eval $merge_tool_cmd )
+                       status=$?
+                       check_unchanged
+               else
+                       ( eval $merge_tool_cmd )
+                       status=$?
+               fi
+               return $status
+       else
+               merge_cmd "$1"
+       fi
+}
+
 list_merge_tool_candidates () {
        if merge_mode
        then
@@ -138,6 +174,44 @@ list_merge_tool_candidates () {
        esac
 }
 
+show_tool_help () {
+       list_merge_tool_candidates
+       unavailable= available= LF='
+'
+       for i in $tools
+       do
+               merge_tool_path=$(translate_merge_tool_path "$i")
+               if type "$merge_tool_path" >/dev/null 2>&1
+               then
+                       available="$available$i$LF"
+               else
+                       unavailable="$unavailable$i$LF"
+               fi
+       done
+
+       cmd_name=${TOOL_MODE}tool
+       if test -n "$available"
+       then
+               echo "'git $cmd_name --tool=<tool>' may be set to one of the following:"
+               echo "$available" | sort | sed -e 's/^/ /'
+       else
+               echo "No suitable tool for 'git $cmd_name --tool=<tool>' found."
+       fi
+       if test -n "$unavailable"
+       then
+               echo
+               echo 'The following tools are valid, but not currently available:'
+               echo "$unavailable" | sort | sed -e 's/^/       /'
+       fi
+       if test -n "$unavailable$available"
+       then
+               echo
+               echo "Some of the tools listed above only work in a windowed"
+               echo "environment. If run in a terminal-only session, they will fail."
+       fi
+       exit 0
+}
+
 guess_merge_tool () {
        list_merge_tool_candidates
        echo >&2 "merge tool candidates: $tools"