summaryrefslogtreecommitdiff
path: root/git-difftool.perl
diff options
context:
space:
mode:
authorTim Henigan <tim.henigan@gmail.com>2012-03-26 12:23:35 -0400
committerJunio C Hamano <gitster@pobox.com>2012-03-26 10:16:34 -0700
commit50bac4d8ee8a3ef0e3a6f2aaa3d695270dad522b (patch)
tree5fd2f68eecea27dd105d5624221cd5316b8e0193 /git-difftool.perl
parent6fbdb7b5c729f4341a0c69439062024933956a50 (diff)
downloadgit-th/difftool-diffall.tar.gz
difftool: print list of valid tools with '--tool-help'th/difftool-diffall
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, determine which of them are actually installed and then print them for the user when the '--tool-help' option is given. Signed-off-by: Tim Henigan <tim.henigan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-difftool.perl')
-rwxr-xr-xgit-difftool.perl40
1 files changed, 37 insertions, 3 deletions
diff --git a/git-difftool.perl b/git-difftool.perl
index 8d6bb5a388..e1754ffb2e 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,7 @@ sub usage
{
my $exitcode = shift;
print << 'USAGE';
-usage: git difftool [-t|--tool=<tool>]
+usage: git difftool [-t|--tool=<tool>] [--tool-help]
[-x|--extcmd=<cmd>]
[-g|--gui] [--no-gui]
[--prompt] [-y|--no-prompt]
@@ -38,6 +38,36 @@ USAGE
exit($exitcode);
}
+sub print_tool_help
+{
+ my ($cmd, @found, @notfound);
+ my $gitpath = Git::exec_path();
+
+ for (glob "$gitpath/mergetools/*") {
+ my $tool = basename($_);
+ next if ($tool eq "defaults");
+
+ $cmd = '. "$(git --exec-path)/git-mergetool--lib"';
+ $cmd .= " && get_merge_tool_path $tool >/dev/null 2>&1";
+ if (system('sh', '-c', $cmd) == 0) {
+ push(@found, $tool);
+ } else {
+ push(@notfound, $tool);
+ }
+ }
+
+ print "'git difftool --tool=<tool>' may be set to one of the following:\n";
+ print "\t$_\n" for (@found);
+
+ print "\nThe following tools are valid, but not currently available:\n";
+ print "\t$_\n" for (@notfound);
+
+ print "\nNOTE: Some of the tools listed above only work in a windowed\n";
+ print "environment. If run in a terminal-only session, they will fail.\n";
+
+ exit(0);
+}
+
sub setup_dir_diff
{
# Run the diff; exit immediately if no diff found
@@ -132,18 +162,22 @@ 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, $prompt);
+my ($difftool_cmd, $dirdiff, $extcmd, $gui, $help, $prompt, $tool_help);
GetOptions('g|gui!' => \$gui,
'd|dir-diff' => \$dirdiff,
'h' => \$help,
'prompt!' => \$prompt,
'y' => sub { $prompt = 0; },
't|tool:s' => \$difftool_cmd,
+ 'tool-help' => \$tool_help,
'x|extcmd:s' => \$extcmd);
if (defined($help)) {
usage(0);
}
+if (defined($tool_help)) {
+ print_tool_help();
+}
if (defined($difftool_cmd)) {
if (length($difftool_cmd) > 0) {
$ENV{GIT_DIFF_TOOL} = $difftool_cmd;