Skip to content

Commit 4cefa49

Browse files
davvidgitster
authored andcommitted
git-difftool: Add '--gui' for selecting a GUI tool
Users might prefer to have git-difftool use a different tool when run from a Git GUI. This teaches git-difftool to honor 'diff.guitool' when the '--gui' option is specified. This allows users to configure their preferred command-line diff tool in 'diff.tool' and a GUI diff tool in 'diff.guitool'. Reference: http://article.gmane.org/gmane.comp.version-control.git/133386 Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 23218bb commit 4cefa49

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

Documentation/git-difftool.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ 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+
-g::
62+
--gui::
63+
When 'git-difftool' is invoked with the `-g` or `--gui` option
64+
the default diff tool will be read from the configured
65+
`diff.guitool` variable instead of `diff.tool`.
66+
6167
See linkgit:git-diff[1] for the full list of supported options.
6268

6369
CONFIG VARIABLES
@@ -68,6 +74,9 @@ difftool equivalents have not been defined.
6874
diff.tool::
6975
The default diff tool to use.
7076

77+
diff.guitool::
78+
The default diff tool to use when `--gui` is specified.
79+
7180
difftool.<tool>.path::
7281
Override the path for the given tool. This is useful in case
7382
your tool is not in the PATH.

git-difftool.perl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
use Cwd qw(abs_path);
1616
use File::Basename qw(dirname);
1717

18+
require Git;
19+
1820
my $DIR = abs_path(dirname($0));
1921

2022

2123
sub usage
2224
{
2325
print << 'USAGE';
24-
usage: git difftool [--tool=<tool>] [-y|--no-prompt] ["git diff" options]
26+
usage: git difftool [-g|--gui] [-t|--tool=<tool>] [-y|--no-prompt]
27+
["git diff" options]
2528
USAGE
2629
exit 1;
2730
}
@@ -63,6 +66,14 @@ sub generate_command
6366
$ENV{GIT_DIFF_TOOL} = substr($arg, 7);
6467
next;
6568
}
69+
if ($arg eq '-g' || $arg eq '--gui') {
70+
my $tool = Git::command_oneline('config',
71+
'diff.guitool');
72+
if (length($tool)) {
73+
$ENV{GIT_DIFF_TOOL} = $tool;
74+
}
75+
next;
76+
}
6677
if ($arg eq '-y' || $arg eq '--no-prompt') {
6778
$ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';
6879
delete $ENV{GIT_DIFFTOOL_PROMPT};

t/t7800-difftool.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ remove_config_vars()
1919
{
2020
# Unset all config variables used by git-difftool
2121
git config --unset diff.tool
22+
git config --unset diff.guitool
2223
git config --unset difftool.test-tool.cmd
2324
git config --unset difftool.prompt
2425
git config --unset merge.tool
@@ -77,6 +78,17 @@ test_expect_success 'difftool ignores bad --tool values' '
7778
test "$diff" = ""
7879
'
7980

81+
test_expect_success 'difftool honors --gui' '
82+
git config merge.tool bogus-tool &&
83+
git config diff.tool bogus-tool &&
84+
git config diff.guitool test-tool &&
85+
86+
diff=$(git difftool --no-prompt --gui branch) &&
87+
test "$diff" = "branch" &&
88+
89+
restore_test_defaults
90+
'
91+
8092
# Specify the diff tool using $GIT_DIFF_TOOL
8193
test_expect_success 'GIT_DIFF_TOOL variable' '
8294
git config --unset diff.tool

0 commit comments

Comments
 (0)