git/list[1] front-page[2] threads[3] people[4] search[5] about
 

mergetool: include custom tools in '--tool-help'

From
John Keeping <john@keeping.me.uk>
Date
Jan 27, 2013, 16:34 UTC
Message-ID
<20130127163442.GQ7498@serenity.lan>

'git mergetool --tool-help' only lists builtin tools, not those that the user has configured via a 'mergetool.<tool>.cmd' config value. Fix this by inspecting the tools configured in this way and adding them to the available and unavailable lists before displaying them.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
After the recent changes to mergetool, do we want to do something like
this as well, so that 'git mergetool --tool-help' will display any tools
configured by the user/system administrator?
This is on top of jk/mergetool.
 git-mergetool--lib.sh | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index 1d0fb12..f9a617c 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -206,6 +206,29 @@ list_merge_tool_candidates () {
 	esac
 }
 
+# Adds tools from git-config to the available and unavailable lists.
+# The tools are found in "$1.<tool>.cmd".
+add_config_tools() {
+	section=$1
+
+	eval $(git config --get-regexp $section'\..*\.cmd' |
+		while read -r key value
+		do
+			tool=${key#mergetool.}
+			tool=${tool%.cmd}
+
+			tool=$(echo "$tool" |sed -e 's/'\''/'\''\\'\'\''/g')
+
+			cmd=$(eval -- "set -- $value"; echo "$1")
+			if type "$cmd" >/dev/null 2>&1
+			then
+				echo "available=\"\${available}\"'$tool'\"\$LF\""
+			else
+				echo "unavailable=\"\${unavailable}\"'$tool'\"\$LF\""
+			fi
+		done)
+}
+
 show_tool_help () {
 	unavailable= available= LF='
 '
@@ -223,6 +246,12 @@ show_tool_help () {
 		fi
 	done
 
+	add_config_tools mergetool
+	if diff_mode
+	then
+		add_config_tools difftool
+	fi
+
 	cmd_name=${TOOL_MODE}tool
 	if test -n "$available"
 	then
-- 
1.8.1.1
Next: Junio C Hamano
Message 1 of 5 in “mergetool: include custom tools in '--tool-help'”
  1. John KeepingJan 27, 2013
  2. Junio C HamanoJan 27, 2013
  3. John KeepingJan 27, 2013
  4. Junio C HamanoJan 27, 2013
  5. David AguilarJan 27, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.