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

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

From
Tim Henigan <tim.henigan@gmail.com>
Date
Mar 18, 2012, 01:55 UTC
Message-ID
<1332035734-5443-10-git-send-email-tim.henigan@gmail.com>
In-Reply-To
<1332035734-5443-1-git-send-email-tim.henigan@gmail.com>

Since bc7a96a (mergetool--lib: Refactor tools into separate files, 2011-08-18), it is possible to add a new diff tool by creating a simple script in the '$(git --exec-path)/mergetools' directory. Updating the difftool help text is still a manual process, and the documentation can easily go out of sync.

Teach the command to read the list of valid tools from the 'mergetools' directory and print them for the user when the '--tool-help' option is given.

Signed-off-by: Tim Henigan <tim.henigan@gmail.com>
---
Changes in v2:
  The glob statement used to find the mergetool options now uses the
  fully qualified path.  This insures that 'git difftool --tool-help'
  can be called from any diretory.
 Documentation/git-difftool.txt |   11 ++++++-----
 git-difftool.perl              |   17 ++++++++++++++---
 2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt
index aba5e76..31fc2e3 100644
--- a/Documentation/git-difftool.txt
+++ b/Documentation/git-difftool.txt
@@ -36,11 +36,9 @@ OPTIONS
 
 -t <tool>::
 --tool=<tool>::
-	Use the diff tool specified by <tool>.
-	Valid diff tools are:
-	araxis, bc3, deltawalker, diffuse, emerge, ecmerge, gvimdiff,
-	kdiff3,	kompare, meld, opendiff, p4merge, tkdiff, vimdiff and
-	xxdiff.
+	Use the diff tool specified by <tool>.  Valid values include
+	emerge, kompare, meld, and vimdiff. Run `git difftool --tool-help`
+	for the list of valid <tool> settings.
 +
 If a diff tool is not specified, 'git difftool'
 will use the configuration variable `diff.tool`.  If the
@@ -68,6 +66,9 @@ of the diff post-image.  `$MERGED` is the name of the file which is
 being compared. `$BASE` is provided for compatibility
 with custom merge tool commands and has the same value as `$MERGED`.
 
+--tool-help::
+	Print a list of diff tools that may be used with `--tool`.
+
 -x <command>::
 --extcmd=<command>::
 	Specify a custom command for viewing diffs.
diff --git a/git-difftool.perl b/git-difftool.perl
index e306977..fb4e3e6 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -14,7 +14,7 @@
 use 5.008;
 use strict;
 use warnings;
-use File::Basename qw(dirname);
+use File::Basename qw(dirname basename);
 use File::Copy;
 use File::stat;
 use File::Path qw(mkpath);
@@ -28,7 +28,8 @@ sub usage
 {
 	my $exitcode = shift;
 	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]
                     [-d|--dir-diff]
                     ['git diff' options]
@@ -129,18 +130,28 @@ sub setup_dir_diff
 
 # parse command-line options. all unrecognized options and arguments
 # are passed through to the 'git diff' command.
-my ($difftool_cmd, $dirdiff, $extcmd, $gui, $help, $no_prompt, $prompt);
+my ($difftool_cmd, $dirdiff, $extcmd, $gui, $help, $no_prompt, $prompt, $tool_help);
 GetOptions('g|gui' => \$gui,
 	'd|dir-diff' => \$dirdiff,
 	'h' => \$help,
 	'prompt' => \$prompt,
 	't|tool:s' => \$difftool_cmd,
+	'tool-help' => \$tool_help,
 	'x|extcmd:s' => \$extcmd,
 	'y|no-prompt' => \$no_prompt);
 
 if (defined($help)) {
 	usage(0);
 } 
+if (defined($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(0);
+}
 if (defined($difftool_cmd)) {
 	if (length($difftool_cmd) > 0) {
 		$ENV{GIT_DIFF_TOOL} = $difftool_cmd;
-- 
1.7.9.1.290.gbd444
Previous: Tim HeniganNext: Junio C Hamano
Message 21 of 26 in “difftool: teach command to perform directory diffs”
  1. 0/9 difftool: teach command to perform directory diffsTim Henigan, Mar 17, 2012
  2. 1/9 difftool: parse options using Getopt::LongTim Henigan, Mar 17, 2012
  3. David AguilarMar 17, 2012
  4. Tim HeniganMar 17, 2012
  5. David AguilarMar 18, 2012
  6. 2/9 difftool: exit(0) when usage is printedTim Henigan, Mar 17, 2012
  7. 3/9 difftool: remove explicit change of PATHTim Henigan, Mar 17, 2012
  8. 4/9 difftool: stop appending '.exe' to gitTim Henigan, Mar 17, 2012
  9. Junio C HamanoMar 17, 2012
  10. Tim HeniganMar 17, 2012
  11. Junio C HamanoMar 17, 2012
  12. 0/9 difftool: teach command to perform directory diffsTim Henigan, Mar 18, 2012
  13. 1/9 difftool: parse options using Getopt::LongTim Henigan, Mar 18, 2012
  14. 2/9 difftool: exit(0) when usage is printedTim Henigan, Mar 18, 2012
  15. 3/9 difftool: remove explicit change of PATHTim Henigan, Mar 18, 2012
  16. 4/9 difftool: stop appending '.exe' to gitTim Henigan, Mar 18, 2012
  17. 5/9 difftool: eliminate setup_environment functionTim Henigan, Mar 18, 2012
  18. 6/9 difftool: replace system call with Git::command_noisyTim Henigan, Mar 18, 2012
  19. 7/9 difftool: teach difftool to handle directory diffsTim Henigan, Mar 18, 2012
  20. 8/9 difftool: teach dir-diff to copy modified files back to working treeTim Henigan, Mar 18, 2012
  21. 9/9 difftool: print list of valid tools with '--tool-help'Tim Henigan, Mar 18, 2012
  22. Junio C HamanoMar 19, 2012
  23. David AguilarMar 20, 2012
  24. Junio C HamanoMar 20, 2012
  25. Tim HeniganMar 20, 2012
  26. Junio C HamanoMar 20, 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.