difftool: fix dir-diff when file does not exist in working tree
authorJohn Keeping <john@keeping.me.uk>
Fri, 17 May 2013 18:26:08 +0000 (19:26 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 May 2013 18:46:53 +0000 (11:46 -0700)
Commit 02c5631 (difftool --dir-diff: symlink all files matching the
working tree, 2013-03-14) does not handle the case where a file that is
being compared does not exist in the working tree. Fix this by checking
for existence explicitly before running git-hash-object.

Reported-by: Kevin Bracey <kevin@bracey.fi>
Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-difftool.perl
t/t7800-difftool.sh
index 67802922ccc41fa2993c1bce4ea1a3d2899c7a40..8a7520553776ec9d0c8d38526041dd37742d3bc1 100755 (executable)
@@ -92,6 +92,12 @@ sub use_wt_file
                return 0;
        }
 
+       if (! -e "$workdir/$file") {
+               # If the file doesn't exist in the working tree, we cannot
+               # use it.
+               return (0, $null_sha1);
+       }
+
        my $wt_sha1 = $repo->command_oneline('hash-object', "$workdir/$file");
        my $use = ($sha1 eq $null_sha1) || ($sha1 eq $wt_sha1);
        return ($use, $wt_sha1);
index a6bd99eaf51943a899aa5e5801479b0a84b6b692..d46f0411bd9a08b38035c8fb5ca611723b8baed2 100755 (executable)
@@ -356,6 +356,13 @@ run_dir_diff_test 'difftool --dir-diff from subdirectory' '
        )
 '
 
+run_dir_diff_test 'difftool --dir-diff when worktree file is missing' '
+       test_when_finished git reset --hard &&
+       rm file2 &&
+       git difftool --dir-diff $symlinks --extcmd ls branch master >output &&
+       grep file2 output
+'
+
 write_script .git/CHECK_SYMLINKS <<\EOF
 for f in file file2 sub/sub
 do