difftool: Fix '--gui' when diff.guitool is unconfigured
When diff.guitool is unconfigured and "--gui" is specified git-difftool dies with the following error message: config diff.guitool: command returned error: 1 Catch the error so that the "--gui" flag is a no-op when diff.guitool is unconfigured. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
David Aguilar committed
Mar 27, 2010 at 14:58 UTC
42accaec0174f80c81681c4a6f896ca452ba3f76
2 files changed
+16
-5
git-difftool.perl
+7
-5
@@ -78,11 +78,13 @@ sub generate_command
78
next;
79
}
80
if ($arg eq '-g' || $arg eq '--gui') {
81
- my $tool = Git::command_oneline('config',
82
- 'diff.guitool');
83
- if (length($tool)) {
84
- $ENV{GIT_DIFF_TOOL} = $tool;
85
- }
81
+ eval {
82
+ my $tool = Git::command_oneline('config',
83
+ 'diff.guitool');
84
+ if (length($tool)) {
85
+ $ENV{GIT_DIFF_TOOL} = $tool;
86
+ }
87
+ };
88
next;
89
}
90
if ($arg eq '-y' || $arg eq '--no-prompt') {
t/t7800-difftool.sh
+9
@@ -92,6 +92,15 @@ test_expect_success 'difftool honors --gui' '
92
restore_test_defaults
93
'
94
95
+test_expect_success 'difftool --gui works without configured diff.guitool' '
96
+ git config diff.tool test-tool &&
97
+
98
+ diff=$(git difftool --no-prompt --gui branch) &&
99
+ test "$diff" = "branch" &&
100
+
101
+ restore_test_defaults
102
+'
103
+
104
# Specify the diff tool using $GIT_DIFF_TOOL
105
test_expect_success 'GIT_DIFF_TOOL variable' '
106
git config --unset diff.tool