Skip to content

Commit

Permalink
difftool: Check all return codes from compare()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
David Aguilar authored and Junio C Hamano committed Jul 25, 2012
1 parent 7c7584b commit 283abb2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion git-difftool.perl
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,16 @@ sub dir_diff
# external tool did not replace the original link with a file.
for my $file (@worktree) {
next if $symlinks && -l "$b/$file";
if (-f "$b/$file" && compare("$b/$file", "$workdir/$file")) {
next if ! -f "$b/$file";

my $diff = compare("$b/$file", "$workdir/$file");
if ($diff == 0) {
next;
} elsif ($diff == -1) {
my $errmsg = "warning: Could not compare ";
$errmsg += "'$b/$file' with '$workdir/$file'\n";
warn $errmsg;
} elsif ($diff == 1) {
copy("$b/$file", "$workdir/$file") or die $!;
my $mode = stat("$b/$file")->mode;
chmod($mode, "$workdir/$file") or die $!;
Expand Down

0 comments on commit 283abb2

Please sign in to comment.