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>
David Aguilar committed
Jul 24, 2012 at 20:14 UTC
283abb2c8abb3f40d8d0170ba45c2e45d40f8cdb
1 file changed
+10
-1
git-difftool.perl
+10
-1
@@ -370,7 +370,16 @@ sub dir_diff
370
# external tool did not replace the original link with a file.
371
for my $file (@worktree) {
372
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) {
383
copy("$b/$file", "$workdir/$file") or die $!;
384
my $mode = stat("$b/$file")->mode;
385
chmod($mode, "$workdir/$file") or die $!;