@matheusbsbs / matheus-bagliano / commits / f47f1e2ce8
Fork 0

difftool: Add '-x' and as an alias for '--extcmd'

This adds '-x' as a shorthand for the '--extcmd' option. Arguments to '--extcmd' can be specified separately, which was not originally possible. This also fixes the brief help text so that it mentions both '-x' and '--extcmd'. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Aguilar committed Jan 15, 2010 at 14:03 UTC f47f1e2ce8b4022113120b32decb4436341dc3aa
3 files changed +24 -8
Documentation/git-difftool.txt
+2 -1
@@ -7,7 +7,7 @@ git-difftool - Show changes using common diff tools
7
8 SYNOPSIS
9 --------
10 -'git difftool' [--tool=<tool>] [-y|--no-prompt|--prompt] [<'git diff' options>]
10 +'git difftool' [<options>] <commit>{0,2} [--] [<path>...]
11
12 DESCRIPTION
13 -----------
@@ -58,6 +58,7 @@ is set to the name of the temporary file containing the contents
58 of the diff post-image. `$BASE` is provided for compatibility
59 with custom merge tool commands and has the same value as `$LOCAL`.
60
61 +-x <command>::
62 --extcmd=<command>::
63 Specify a custom command for viewing diffs.
64 'git-difftool' ignores the configured defaults and runs
git-difftool.perl
+14 -7
@@ -1,5 +1,5 @@
1 #!/usr/bin/env perl
2 -# Copyright (c) 2009 David Aguilar
2 +# Copyright (c) 2009, 2010 David Aguilar
3 #
4 # This is a wrapper around the GIT_EXTERNAL_DIFF-compatible
5 # git-difftool--helper script.
@@ -23,8 +23,9 @@ my $DIR = abs_path(dirname($0));
23 sub usage
24 {
25 print << 'USAGE';
26 -usage: git difftool [-g|--gui] [-t|--tool=<tool>] [-y|--no-prompt]
27 - ["git diff" options]
26 +usage: git difftool [-t|--tool=<tool>] [-x|--extcmd=<cmd>]
27 + [-y|--no-prompt] [-g|--gui]
28 + ['git diff' options]
29 USAGE
30 exit 1;
31 }
@@ -62,14 +63,20 @@ sub generate_command
63 $skip_next = 1;
64 next;
65 }
65 - if ($arg =~ /^--extcmd=/) {
66 - $ENV{GIT_DIFFTOOL_EXTCMD} = substr($arg, 9);
67 - next;
68 - }
66 if ($arg =~ /^--tool=/) {
67 $ENV{GIT_DIFF_TOOL} = substr($arg, 7);
68 next;
69 }
70 + if ($arg eq '-x' || $arg eq '--extcmd') {
71 + usage() if $#ARGV <= $idx;
72 + $ENV{GIT_DIFFTOOL_EXTCMD} = $ARGV[$idx + 1];
73 + $skip_next = 1;
74 + next;
75 + }
76 + if ($arg =~ /^--extcmd=/) {
77 + $ENV{GIT_DIFFTOOL_EXTCMD} = substr($arg, 9);
78 + next;
79 + }
80 if ($arg eq '-g' || $arg eq '--gui') {
81 my $tool = Git::command_oneline('config',
82 'diff.guitool');
t/t7800-difftool.sh
+8
@@ -225,8 +225,16 @@ test_expect_success 'difftool.<tool>.path' '
225 test_expect_success 'difftool --extcmd=cat' '
226 diff=$(git difftool --no-prompt --extcmd=cat branch) &&
227 test "$diff" = branch"$LF"master
228 +'
229
230 +test_expect_success 'difftool --extcmd cat' '
231 + diff=$(git difftool --no-prompt --extcmd cat branch) &&
232 + test "$diff" = branch"$LF"master
233 +'
234
235 +test_expect_success 'difftool -x cat' '
236 + diff=$(git difftool --no-prompt -x cat branch) &&
237 + test "$diff" = branch"$LF"master
238
239
240 '