Skip to content

Commit f52a386

Browse files
committed
Merge branch 'jc/mergetool-tool-help' into maint
* jc/mergetool-tool-help: mergetool: support --tool-help option like difftool does
2 parents 0e4c882 + 109859e commit f52a386

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

Documentation/git-mergetool.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ OPTIONS
2727
-t <tool>::
2828
--tool=<tool>::
2929
Use the merge resolution program specified by <tool>.
30-
Valid merge tools are:
31-
araxis, bc3, diffuse, ecmerge, emerge, gvimdiff, kdiff3,
32-
meld, opendiff, p4merge, tkdiff, tortoisemerge, vimdiff and xxdiff.
30+
Valid values include emerge, gvimdiff, kdiff3,
31+
meld, vimdiff, and tortoisemerge. Run `git mergetool --tool-help`
32+
for the list of valid <tool> settings.
3333
+
3434
If a merge resolution program is not specified, 'git mergetool'
3535
will use the configuration variable `merge.tool`. If the

git-mergetool--lib.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ run_merge_tool () {
111111
return $status
112112
}
113113

114-
guess_merge_tool () {
114+
list_merge_tool_candidates () {
115115
if merge_mode
116116
then
117117
tools="tortoisemerge"
@@ -136,6 +136,10 @@ guess_merge_tool () {
136136
tools="$tools emerge vimdiff"
137137
;;
138138
esac
139+
}
140+
141+
guess_merge_tool () {
142+
list_merge_tool_candidates
139143
echo >&2 "merge tool candidates: $tools"
140144

141145
# Loop over each candidate and stop when a valid merge tool is found.

git-mergetool.sh

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# at the discretion of Junio C Hamano.
99
#
1010

11-
USAGE='[--tool=tool] [-y|--no-prompt|--prompt] [file to merge] ...'
11+
USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
1212
SUBDIRECTORY_OK=Yes
1313
OPTIONS_SPEC=
1414
TOOL_MODE=merge
@@ -284,11 +284,51 @@ merge_file () {
284284
return 0
285285
}
286286

287+
show_tool_help () {
288+
TOOL_MODE=merge
289+
list_merge_tool_candidates
290+
unavailable= available= LF='
291+
'
292+
for i in $tools
293+
do
294+
merge_tool_path=$(translate_merge_tool_path "$i")
295+
if type "$merge_tool_path" >/dev/null 2>&1
296+
then
297+
available="$available$i$LF"
298+
else
299+
unavailable="$unavailable$i$LF"
300+
fi
301+
done
302+
if test -n "$available"
303+
then
304+
echo "'git mergetool --tool=<tool>' may be set to one of the following:"
305+
echo "$available" | sort | sed -e 's/^/ /'
306+
else
307+
echo "No suitable tool for 'git mergetool --tool=<tool>' found."
308+
fi
309+
if test -n "$unavailable"
310+
then
311+
echo
312+
echo 'The following tools are valid, but not currently available:'
313+
echo "$unavailable" | sort | sed -e 's/^/ /'
314+
fi
315+
if test -n "$unavailable$available"
316+
then
317+
echo
318+
echo "Some of the tools listed above only work in a windowed"
319+
echo "environment. If run in a terminal-only session, they will fail."
320+
fi
321+
exit 0
322+
}
323+
287324
prompt=$(git config --bool mergetool.prompt || echo true)
288325

289326
while test $# != 0
290327
do
291328
case "$1" in
329+
--tool-help)
330+
show_tool_help
331+
;;
292332
-t|--tool*)
293333
case "$#,$1" in
294334
*,*=*)

0 commit comments

Comments
 (0)