Skip to content

Commit 283abb2

Browse files
davvidgitster
authored andcommitted
difftool: Check all return codes from compare()
Handle the case where compare() is unable to read its inputs. Emit a warning so that the user knows that something went wrong. We may later want to restructure the code so that we can inhibit tempdir cleanup when this condition is reached. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7c7584b commit 283abb2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

git-difftool.perl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,16 @@ sub dir_diff
370370
# external tool did not replace the original link with a file.
371371
for my $file (@worktree) {
372372
next if $symlinks && -l "$b/$file";
373-
if (-f "$b/$file" && compare("$b/$file", "$workdir/$file")) {
373+
next if ! -f "$b/$file";
374+
375+
my $diff = compare("$b/$file", "$workdir/$file");
376+
if ($diff == 0) {
377+
next;
378+
} elsif ($diff == -1) {
379+
my $errmsg = "warning: Could not compare ";
380+
$errmsg += "'$b/$file' with '$workdir/$file'\n";
381+
warn $errmsg;
382+
} elsif ($diff == 1) {
374383
copy("$b/$file", "$workdir/$file") or die $!;
375384
my $mode = stat("$b/$file")->mode;
376385
chmod($mode, "$workdir/$file") or die $!;

0 commit comments

Comments
 (0)