mergetool: accept -g/--[no-]gui as arguments

In line with how difftool accepts a -g/--[no-]gui option, make mergetool accept the same option in order to use the `merge.guitool` variable to find the default mergetool instead of `merge.tool`. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Anmol Mago <anmolmago@gmail.com> Signed-off-by: Brian Ho <briankyho@gmail.com> Signed-off-by: David Lu <david.lu97@outlook.com> Signed-off-by: Ryan Wang <shirui.wang@hotmail.com> Acked-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Oct 24, 2018 at 12:25 UTC 063f2bdbf767dd24bc0a35b5476d8025ee8646c7
3 files changed +31 -7
Documentation/git-mergetool.txt
+11
@@ -79,6 +79,17 @@ success of the resolution after the custom tool has exited.
79 Prompt before each invocation of the merge resolution program
80 to give the user a chance to skip the path.
81
82 +-g::
83 +--gui::
84 + When 'git-mergetool' is invoked with the `-g` or `--gui` option
85 + the default merge tool will be read from the configured
86 + `merge.guitool` variable instead of `merge.tool`.
87 +
88 +--no-gui::
89 + This overrides a previous `-g` or `--gui` setting and reads the
90 + default merge tool will be read from the configured `merge.tool`
91 + variable.
92 +
93 -O<orderfile>::
94 Process files in the order specified in the
95 <orderfile>, which has one shell glob pattern per line.
git-mergetool--lib.sh
+11 -5
@@ -350,17 +350,23 @@ guess_merge_tool () {
350 }
351
352 get_configured_merge_tool () {
353 - # Diff mode first tries diff.tool and falls back to merge.tool.
354 - # Merge mode only checks merge.tool
353 + # If first argument is true, find the guitool instead
354 + if test "$1" = true
355 + then
356 + gui_prefix=gui
357 + fi
358 +
359 + # Diff mode first tries diff.(gui)tool and falls back to merge.(gui)tool.
360 + # Merge mode only checks merge.(gui)tool
361 if diff_mode
362 then
357 - merge_tool=$(git config diff.tool || git config merge.tool)
363 + merge_tool=$(git config diff.${gui_prefix}tool || git config merge.${gui_prefix}tool)
364 else
359 - merge_tool=$(git config merge.tool)
365 + merge_tool=$(git config merge.${gui_prefix}tool)
366 fi
367 if test -n "$merge_tool" && ! valid_tool "$merge_tool"
368 then
363 - echo >&2 "git config option $TOOL_MODE.tool set to unknown tool: $merge_tool"
369 + echo >&2 "git config option $TOOL_MODE.${gui_prefix}tool set to unknown tool: $merge_tool"
370 echo >&2 "Resetting to default..."
371 return 1
372 fi
git-mergetool.sh
+9 -2
@@ -9,7 +9,7 @@
9 # at the discretion of Junio C Hamano.
10 #
11
12 -USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [-O<orderfile>] [file to merge] ...'
12 +USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [-g|--gui|--no-gui] [-O<orderfile>] [file to merge] ...'
13 SUBDIRECTORY_OK=Yes
14 NONGIT_OK=Yes
15 OPTIONS_SPEC=
@@ -389,6 +389,7 @@ print_noop_and_exit () {
389
390 main () {
391 prompt=$(git config --bool mergetool.prompt)
392 + gui_tool=false
393 guessed_merge_tool=false
394 orderfile=
395
@@ -414,6 +415,12 @@ main () {
415 shift ;;
416 esac
417 ;;
418 + --no-gui)
419 + gui_tool=false
420 + ;;
421 + -g|--gui)
422 + gui_tool=true
423 + ;;
424 -y|--no-prompt)
425 prompt=false
426 ;;
@@ -443,7 +450,7 @@ main () {
450 if test -z "$merge_tool"
451 then
452 # Check if a merge tool has been configured
446 - merge_tool=$(get_configured_merge_tool)
453 + merge_tool=$(get_configured_merge_tool $gui_tool)
454 # Try to guess an appropriate merge tool if no tool has been set.
455 if test -z "$merge_tool"
456 then