Skip to content

Commit 1f197a1

Browse files
johnkeepinggitster
authored andcommitted
difftool: fix dir-diff when file does not exist in working tree
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 <[email protected]> Signed-off-by: John Keeping <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 31eb360 commit 1f197a1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

git-difftool.perl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ sub use_wt_file
9292
return 0;
9393
}
9494

95+
if (! -e "$workdir/$file") {
96+
# If the file doesn't exist in the working tree, we cannot
97+
# use it.
98+
return (0, $null_sha1);
99+
}
100+
95101
my $wt_sha1 = $repo->command_oneline('hash-object', "$workdir/$file");
96102
my $use = ($sha1 eq $null_sha1) || ($sha1 eq $wt_sha1);
97103
return ($use, $wt_sha1);

t/t7800-difftool.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ run_dir_diff_test 'difftool --dir-diff from subdirectory' '
356356
)
357357
'
358358

359+
run_dir_diff_test 'difftool --dir-diff when worktree file is missing' '
360+
test_when_finished git reset --hard &&
361+
rm file2 &&
362+
git difftool --dir-diff $symlinks --extcmd ls branch master >output &&
363+
grep file2 output
364+
'
365+
359366
write_script .git/CHECK_SYMLINKS <<\EOF
360367
for f in file file2 sub/sub
361368
do

0 commit comments

Comments
 (0)