sequencer: always allow tab after command name
[gitweb.git] / git-mergetool--lib.sh
index b928179a2e9034a897ff8ce9755c6eefa53a1744..204a5acd66f5444412f0088b8df6cb0ae2fd6b41 100644 (file)
@@ -80,14 +80,18 @@ show_tool_names () {
        }
 }
 
-diff_mode() {
+diff_mode () {
        test "$TOOL_MODE" = diff
 }
 
-merge_mode() {
+merge_mode () {
        test "$TOOL_MODE" = merge
 }
 
+gui_mode () {
+       test "$GIT_MERGETOOL_GUI" = true
+}
+
 translate_merge_tool_path () {
        echo "$1"
 }
@@ -279,6 +283,7 @@ list_merge_tool_candidates () {
                fi
                tools="$tools gvimdiff diffuse diffmerge ecmerge"
                tools="$tools p4merge araxis bc codecompare"
+               tools="$tools smerge"
        fi
        case "${VISUAL:-$EDITOR}" in
        *vim*)
@@ -350,20 +355,36 @@ guess_merge_tool () {
 }
 
 get_configured_merge_tool () {
-       # If first argument is true, find the guitool instead
-       if test "$1" = true
-       then
-               gui_prefix=gui
-       fi
-
-       # Diff mode first tries diff.(gui)tool and falls back to merge.(gui)tool.
-       # Merge mode only checks merge.(gui)tool
+       keys=
        if diff_mode
        then
-               merge_tool=$(git config diff.${gui_prefix}tool || git config merge.${gui_prefix}tool)
+               if gui_mode
+               then
+                       keys="diff.guitool merge.guitool diff.tool merge.tool"
+               else
+                       keys="diff.tool merge.tool"
+               fi
        else
-               merge_tool=$(git config merge.${gui_prefix}tool)
+               if gui_mode
+               then
+                       keys="merge.guitool merge.tool"
+               else
+                       keys="merge.tool"
+               fi
        fi
+
+       merge_tool=$(
+               IFS=' '
+               for key in $keys
+               do
+                       selected=$(git config $key)
+                       if test -n "$selected"
+                       then
+                               echo "$selected"
+                               return
+                       fi
+               done)
+
        if test -n "$merge_tool" && ! valid_tool "$merge_tool"
        then
                echo >&2 "git config option $TOOL_MODE.${gui_prefix}tool set to unknown tool: $merge_tool"
@@ -405,7 +426,7 @@ get_merge_tool_path () {
 get_merge_tool () {
        is_guessed=false
        # Check if a merge tool has been configured
-       merge_tool=$(get_configured_merge_tool $GIT_MERGETOOL_GUI)
+       merge_tool=$(get_configured_merge_tool)
        # Try to guess an appropriate merge tool if no tool has been set.
        if test -z "$merge_tool"
        then