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>
This commit is contained in:
David Aguilar 2009-12-22 21:27:14 -08:00 committed by Junio C Hamano
parent 23218bbd2e
commit 4cefa495ca
3 changed files with 33 additions and 1 deletions

View File

@ -58,6 +58,12 @@ is set to the name of the temporary file containing the contents
of the diff post-image. `$BASE` is provided for compatibility of the diff post-image. `$BASE` is provided for compatibility
with custom merge tool commands and has the same value as `$LOCAL`. with custom merge tool commands and has the same value as `$LOCAL`.
-g::
--gui::
When 'git-difftool' is invoked with the `-g` or `--gui` option
the default diff tool will be read from the configured
`diff.guitool` variable instead of `diff.tool`.
See linkgit:git-diff[1] for the full list of supported options. See linkgit:git-diff[1] for the full list of supported options.
CONFIG VARIABLES CONFIG VARIABLES
@ -68,6 +74,9 @@ difftool equivalents have not been defined.
diff.tool:: diff.tool::
The default diff tool to use. The default diff tool to use.
diff.guitool::
The default diff tool to use when `--gui` is specified.
difftool.<tool>.path:: difftool.<tool>.path::
Override the path for the given tool. This is useful in case Override the path for the given tool. This is useful in case
your tool is not in the PATH. your tool is not in the PATH.

View File

@ -15,13 +15,16 @@ use warnings;
use Cwd qw(abs_path); use Cwd qw(abs_path);
use File::Basename qw(dirname); use File::Basename qw(dirname);
require Git;
my $DIR = abs_path(dirname($0)); my $DIR = abs_path(dirname($0));
sub usage sub usage
{ {
print << 'USAGE'; print << 'USAGE';
usage: git difftool [--tool=<tool>] [-y|--no-prompt] ["git diff" options] usage: git difftool [-g|--gui] [-t|--tool=<tool>] [-y|--no-prompt]
["git diff" options]
USAGE USAGE
exit 1; exit 1;
} }
@ -63,6 +66,14 @@ sub generate_command
$ENV{GIT_DIFF_TOOL} = substr($arg, 7); $ENV{GIT_DIFF_TOOL} = substr($arg, 7);
next; next;
} }
if ($arg eq '-g' || $arg eq '--gui') {
my $tool = Git::command_oneline('config',
'diff.guitool');
if (length($tool)) {
$ENV{GIT_DIFF_TOOL} = $tool;
}
next;
}
if ($arg eq '-y' || $arg eq '--no-prompt') { if ($arg eq '-y' || $arg eq '--no-prompt') {
$ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true'; $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';
delete $ENV{GIT_DIFFTOOL_PROMPT}; delete $ENV{GIT_DIFFTOOL_PROMPT};

View File

@ -19,6 +19,7 @@ remove_config_vars()
{ {
# Unset all config variables used by git-difftool # Unset all config variables used by git-difftool
git config --unset diff.tool git config --unset diff.tool
git config --unset diff.guitool
git config --unset difftool.test-tool.cmd git config --unset difftool.test-tool.cmd
git config --unset difftool.prompt git config --unset difftool.prompt
git config --unset merge.tool git config --unset merge.tool
@ -77,6 +78,17 @@ test_expect_success 'difftool ignores bad --tool values' '
test "$diff" = "" test "$diff" = ""
' '
test_expect_success 'difftool honors --gui' '
git config merge.tool bogus-tool &&
git config diff.tool bogus-tool &&
git config diff.guitool test-tool &&
diff=$(git difftool --no-prompt --gui branch) &&
test "$diff" = "branch" &&
restore_test_defaults
'
# Specify the diff tool using $GIT_DIFF_TOOL # Specify the diff tool using $GIT_DIFF_TOOL
test_expect_success 'GIT_DIFF_TOOL variable' ' test_expect_success 'GIT_DIFF_TOOL variable' '
git config --unset diff.tool git config --unset diff.tool