revision: use generation for A..B --topo-order queries
[gitweb.git] / git-mergetool--lib.sh
index aaa4eed0bc7fc2c5706853d39e4644c9d31e1e0d..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"
 }
@@ -351,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"
@@ -404,14 +424,17 @@ get_merge_tool_path () {
 }
 
 get_merge_tool () {
+       is_guessed=false
        # Check if a merge tool has been configured
        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
                merge_tool=$(guess_merge_tool) || exit
+               is_guessed=true
        fi
        echo "$merge_tool"
+       test "$is_guessed" = false
 }
 
 mergetool_find_win32_cmd () {