Skip to content

Commit 42accae

Browse files
davvidgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb6ad28 commit 42accae

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

git-difftool.perl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ sub generate_command
7878
next;
7979
}
8080
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+
};
8688
next;
8789
}
8890
if ($arg eq '-y' || $arg eq '--no-prompt') {

t/t7800-difftool.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ test_expect_success 'difftool honors --gui' '
9292
restore_test_defaults
9393
'
9494

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+
95104
# Specify the diff tool using $GIT_DIFF_TOOL
96105
test_expect_success 'GIT_DIFF_TOOL variable' '
97106
git config --unset diff.tool

0 commit comments

Comments
 (0)