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

[PATCH] difftool: print list of valid tools with '--tool-help'

From
Tim Henigan <tim.henigan@gmail.com>
Date
Mar 15, 2012, 22:25 UTC
Message-ID
<1331850311-4620-1-git-send-email-tim.henigan@gmail.com>

Since bc7a96a, it is possible to add new diff tools by creating a simple script file in the '$(git --exec-path)/mergetools' directory. However, updating the difftool help text is still a manual process.

This commit reads the list of valid diff tools from the 'mergetools' directory and prints them for the user when the '--tool-help' option is given.

Signed-off-by: Tim Henigan <tim.henigan@gmail.com>
---
 Documentation/git-difftool.txt |    7 ++++---
 git-difftool.perl              |   14 ++++++++++++--
 2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt
index 19d473c..2b4b6ee 100644
--- a/Documentation/git-difftool.txt
+++ b/Documentation/git-difftool.txt
@@ -31,9 +31,10 @@ OPTIONS
 -t <tool>::
 --tool=<tool>::
 	Use the diff tool specified by <tool>.
-	Valid diff tools are:
-	araxis, bc3, diffuse, emerge, ecmerge, gvimdiff, kdiff3,
-	kompare, meld, opendiff, p4merge, tkdiff, vimdiff and xxdiff.
+	See `--tool-help` for the list of valid <tool> settings.
+
+--tool-help::
+	Print a list of diff tools that may be used with `--tool`.
 +
 If a diff tool is not specified, 'git difftool'
 will use the configuration variable `diff.tool`.  If the
diff --git a/git-difftool.perl b/git-difftool.perl
index 09b65f1..4cfb1ae 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -14,7 +14,7 @@ use 5.008;
 use strict;
 use warnings;
 use Cwd qw(abs_path);
-use File::Basename qw(dirname);
+use File::Basename qw(dirname basename);
 
 require Git;
 
@@ -24,7 +24,8 @@ my $DIR = abs_path(dirname($0));
 sub usage
 {
 	print << 'USAGE';
-usage: git difftool [-t|--tool=<tool>] [-x|--extcmd=<cmd>]
+usage: git difftool [-t|--tool=<tool>]   [--tool-help]
+                    [-x|--extcmd=<cmd>]
                     [-y|--no-prompt]   [-g|--gui]
                     ['git diff' options]
 USAGE
@@ -100,6 +101,15 @@ sub generate_command
 		if ($arg eq '-h') {
 			usage();
 		}
+		if ($arg eq '--tool-help') {
+			my $gitpath = Git::exec_path();
+			print "'git difftool --tool=<tool>' may be set to one of the following:\n";
+			for (glob "$gitpath/mergetools/*") {
+				next if /defaults$/;
+				print "\t" . basename($_) . "\n";
+			}
+			exit(1);
+		}
 		push @command, $arg;
 	}
 	if ($prompt eq 'yes') {
-- 
1.7.9.GIT
Next: Junio C Hamano
Message 1 of 7 in “difftool: print list of valid tools with '--tool-help'”
  1. difftool: print list of valid tools with '--tool-help'Tim Henigan, Mar 15, 2012
  2. Junio C HamanoMar 15, 2012
  3. David AguilarMar 17, 2012
  4. Junio C HamanoMar 15, 2012
  5. Tim HeniganMar 23, 2012
  6. Junio C HamanoMar 23, 2012
  7. 9/9 difftool: print list of valid tools with '--tool-help'Tim Henigan, Mar 26, 2012

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.