Skip to content

Commit f47f1e2

Browse files
davvidgitster
authored andcommitted
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>
1 parent a9e1122 commit f47f1e2

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

Documentation/git-difftool.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ git-difftool - Show changes using common diff tools
77

88
SYNOPSIS
99
--------
10-
'git difftool' [--tool=<tool>] [-y|--no-prompt|--prompt] [<'git diff' options>]
10+
'git difftool' [<options>] <commit>{0,2} [--] [<path>...]
1111

1212
DESCRIPTION
1313
-----------
@@ -58,6 +58,7 @@ is set to the name of the temporary file containing the contents
5858
of the diff post-image. `$BASE` is provided for compatibility
5959
with custom merge tool commands and has the same value as `$LOCAL`.
6060

61+
-x <command>::
6162
--extcmd=<command>::
6263
Specify a custom command for viewing diffs.
6364
'git-difftool' ignores the configured defaults and runs

git-difftool.perl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env perl
2-
# Copyright (c) 2009 David Aguilar
2+
# Copyright (c) 2009, 2010 David Aguilar
33
#
44
# This is a wrapper around the GIT_EXTERNAL_DIFF-compatible
55
# git-difftool--helper script.
@@ -23,8 +23,9 @@
2323
sub usage
2424
{
2525
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]
2829
USAGE
2930
exit 1;
3031
}
@@ -62,14 +63,20 @@ sub generate_command
6263
$skip_next = 1;
6364
next;
6465
}
65-
if ($arg =~ /^--extcmd=/) {
66-
$ENV{GIT_DIFFTOOL_EXTCMD} = substr($arg, 9);
67-
next;
68-
}
6966
if ($arg =~ /^--tool=/) {
7067
$ENV{GIT_DIFF_TOOL} = substr($arg, 7);
7168
next;
7269
}
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+
}
7380
if ($arg eq '-g' || $arg eq '--gui') {
7481
my $tool = Git::command_oneline('config',
7582
'diff.guitool');

t/t7800-difftool.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,16 @@ test_expect_success 'difftool.<tool>.path' '
225225
test_expect_success 'difftool --extcmd=cat' '
226226
diff=$(git difftool --no-prompt --extcmd=cat branch) &&
227227
test "$diff" = branch"$LF"master
228+
'
228229

230+
test_expect_success 'difftool --extcmd cat' '
231+
diff=$(git difftool --no-prompt --extcmd cat branch) &&
232+
test "$diff" = branch"$LF"master
233+
'
229234

235+
test_expect_success 'difftool -x cat' '
236+
diff=$(git difftool --no-prompt -x cat branch) &&
237+
test "$diff" = branch"$LF"master
230238
231239
232240
'

0 commit comments

Comments
 (0)