mergetool--lib: list user configured tools in '--tool-help'

Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

John Keeping committed Jan 30, 2013 at 19:55 UTC 665682c9fd81df7e2dc8fe9db28fa5918a2f8ba0
1 file changed +40 -1
git-mergetool--lib.sh
+40 -1
@@ -19,9 +19,24 @@ is_available () {
19 type "$merge_tool_path" >/dev/null 2>&1
20 }
21
22 +list_config_tools () {
23 + section=$1
24 + line_prefix=${2:-}
25 +
26 + git config --get-regexp $section'\..*\.cmd' |
27 + while read -r key value
28 + do
29 + toolname=${key#$section.}
30 + toolname=${toolname%.cmd}
31 +
32 + printf "%s%s\n" "$line_prefix" "$toolname"
33 + done
34 +}
35 +
36 show_tool_names () {
37 condition=${1:-true} per_line_prefix=${2:-} preamble=${3:-}
38 not_found_msg=${4:-}
39 + extra_content=${5:-}
40
41 shown_any=
42 ( cd "$MERGE_TOOLS_DIR" && ls ) | {
@@ -40,6 +55,19 @@ show_tool_names () {
55 fi
56 done
57
58 + if test -n "$extra_content"
59 + then
60 + if test -n "$preamble"
61 + then
62 + # Note: no '\n' here since we don't want a
63 + # blank line if there is no initial content.
64 + printf "%s" "$preamble"
65 + preamble=
66 + fi
67 + shown_any=yes
68 + printf "\n%s\n" "$extra_content"
69 + fi
70 +
71 if test -n "$preamble" && test -n "$not_found_msg"
72 then
73 printf "%s\n" "$not_found_msg"
@@ -254,9 +282,20 @@ show_tool_help () {
282 any_shown=no
283
284 cmd_name=${TOOL_MODE}tool
285 + config_tools=$({
286 + diff_mode && list_config_tools difftool "$tab$tab"
287 + list_config_tools mergetool "$tab$tab"
288 + } | sort)
289 + extra_content=
290 + if test -n "$config_tools"
291 + then
292 + extra_content="${tab}user-defined:${LF}$config_tools"
293 + fi
294 +
295 show_tool_names 'mode_ok && is_available' "$tab$tab" \
296 "$tool_opt may be set to one of the following:" \
259 - "No suitable tool for 'git $cmd_name --tool=<tool>' found." &&
297 + "No suitable tool for 'git $cmd_name --tool=<tool>' found." \
298 + "$extra_content" &&
299 any_shown=yes
300
301 show_tool_names 'mode_ok && ! is_available' "$tab$tab" \