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>
David Aguilar committed
Dec 22, 2009 at 21:27 UTC
4cefa495ca91ad833084ebf3f73c77997920ae9b
3 files changed
+33
-1
Documentation/git-difftool.txt
+9
@@ -58,6 +58,12 @@ 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
+-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
+
67
See linkgit:git-diff[1] for the full list of supported options.
68
69
CONFIG VARIABLES
@@ -68,6 +74,9 @@ difftool equivalents have not been defined.
74
diff.tool::
75
The default diff tool to use.
76
77
+diff.guitool::
78
+ The default diff tool to use when `--gui` is specified.
79
+
80
difftool.<tool>.path::
81
Override the path for the given tool. This is useful in case
82
your tool is not in the PATH.
git-difftool.perl
+12
-1
@@ -15,13 +15,16 @@ use warnings;
15
use Cwd qw(abs_path);
16
use File::Basename qw(dirname);
17
18
+require Git;
19
+
20
my $DIR = abs_path(dirname($0));
21
22
23
sub usage
24
{
25
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]
28
USAGE
29
exit 1;
30
}
@@ -63,6 +66,14 @@ sub generate_command
66
$ENV{GIT_DIFF_TOOL} = substr($arg, 7);
67
next;
68
}
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
+ }
77
if ($arg eq '-y' || $arg eq '--no-prompt') {
78
$ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';
79
delete $ENV{GIT_DIFFTOOL_PROMPT};
t/t7800-difftool.sh
+12
@@ -19,6 +19,7 @@ remove_config_vars()
19
{
20
# Unset all config variables used by git-difftool
21
git config --unset diff.tool
22
+ git config --unset diff.guitool
23
git config --unset difftool.test-tool.cmd
24
git config --unset difftool.prompt
25
git config --unset merge.tool
@@ -77,6 +78,17 @@ test_expect_success 'difftool ignores bad --tool values' '
78
test "$diff" = ""
79
'
80
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
+
92
# Specify the diff tool using $GIT_DIFF_TOOL
93
test_expect_success 'GIT_DIFF_TOOL variable' '
94
git config --unset diff.tool