mergetool: support --tool-help option like difftool does

This way we do not have to risk the list of tools going out of sync between the implementation and the documentation. In the same spirit as bf73fc2 (difftool: print list of valid tools with '--tool-help', 2012-03-29), trim the list of merge backends in the documentation. We do not want to have a complete list of valid tools; we only want a list to help people guess what kind of things the tools do to be specified there, and refer them to --tool-help for a complete list. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 23, 2012 at 14:16 UTC 109859e27445a3ad12eb8f8cba43a5aa8f701733
3 files changed +49 -5
Documentation/git-mergetool.txt
+3 -3
@@ -27,9 +27,9 @@ OPTIONS
27 -t <tool>::
28 --tool=<tool>::
29 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.
33 +
34 If a merge resolution program is not specified, 'git mergetool'
35 will use the configuration variable `merge.tool`. If the
git-mergetool--lib.sh
+5 -1
@@ -111,7 +111,7 @@ run_merge_tool () {
111 return $status
112 }
113
114 -guess_merge_tool () {
114 +list_merge_tool_candidates () {
115 if merge_mode
116 then
117 tools="tortoisemerge"
@@ -136,6 +136,10 @@ guess_merge_tool () {
136 tools="$tools emerge vimdiff"
137 ;;
138 esac
139 +}
140 +
141 +guess_merge_tool () {
142 + list_merge_tool_candidates
143 echo >&2 "merge tool candidates: $tools"
144
145 # Loop over each candidate and stop when a valid merge tool is found.
git-mergetool.sh
+41 -1
@@ -8,7 +8,7 @@
8 # at the discretion of Junio C Hamano.
9 #
10
11 -USAGE='[--tool=tool] [-y|--no-prompt|--prompt] [file to merge] ...'
11 +USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
12 SUBDIRECTORY_OK=Yes
13 OPTIONS_SPEC=
14 TOOL_MODE=merge
@@ -284,11 +284,51 @@ merge_file () {
284 return 0
285 }
286
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 +
324 prompt=$(git config --bool mergetool.prompt || echo true)
325
326 while test $# != 0
327 do
328 case "$1" in
329 + --tool-help)
330 + show_tool_help
331 + ;;
332 -t|--tool*)
333 case "$#,$1" in
334 *,*=*)