Skip to content

Commit 063f2bd

Browse files
Denton-Lgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Anmol Mago <[email protected]> Signed-off-by: Brian Ho <[email protected]> Signed-off-by: David Lu <[email protected]> Signed-off-by: Ryan Wang <[email protected]> Acked-by: David Aguilar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c4df23f commit 063f2bd

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

Documentation/git-mergetool.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ success of the resolution after the custom tool has exited.
7979
Prompt before each invocation of the merge resolution program
8080
to give the user a chance to skip the path.
8181

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+
8293
-O<orderfile>::
8394
Process files in the order specified in the
8495
<orderfile>, which has one shell glob pattern per line.

git-mergetool--lib.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,17 +350,23 @@ guess_merge_tool () {
350350
}
351351

352352
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
355361
if diff_mode
356362
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)
358364
else
359-
merge_tool=$(git config merge.tool)
365+
merge_tool=$(git config merge.${gui_prefix}tool)
360366
fi
361367
if test -n "$merge_tool" && ! valid_tool "$merge_tool"
362368
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"
364370
echo >&2 "Resetting to default..."
365371
return 1
366372
fi

git-mergetool.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# at the discretion of Junio C Hamano.
1010
#
1111

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] ...'
1313
SUBDIRECTORY_OK=Yes
1414
NONGIT_OK=Yes
1515
OPTIONS_SPEC=
@@ -389,6 +389,7 @@ print_noop_and_exit () {
389389

390390
main () {
391391
prompt=$(git config --bool mergetool.prompt)
392+
gui_tool=false
392393
guessed_merge_tool=false
393394
orderfile=
394395

@@ -414,6 +415,12 @@ main () {
414415
shift ;;
415416
esac
416417
;;
418+
--no-gui)
419+
gui_tool=false
420+
;;
421+
-g|--gui)
422+
gui_tool=true
423+
;;
417424
-y|--no-prompt)
418425
prompt=false
419426
;;
@@ -443,7 +450,7 @@ main () {
443450
if test -z "$merge_tool"
444451
then
445452
# Check if a merge tool has been configured
446-
merge_tool=$(get_configured_merge_tool)
453+
merge_tool=$(get_configured_merge_tool $gui_tool)
447454
# Try to guess an appropriate merge tool if no tool has been set.
448455
if test -z "$merge_tool"
449456
then

0 commit comments

Comments
 (0)