Git development
 help / color / mirror / Atom feed
* [PATCH] difftool: fix dir-diff when file does not exist in working tree
@ 2013-05-17 17:29 John Keeping
  2013-05-17 18:10 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: John Keeping @ 2013-05-17 17:29 UTC (permalink / raw)
  To: git; +Cc: Kevin Bracey, Junio C Hamano, John Keeping

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>
---
This fixes a regression in 1.8.3-rc0.

 git-difftool.perl   | 9 ++++++++-
 t/t7800-difftool.sh | 7 +++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/git-difftool.perl b/git-difftool.perl
index 6780292..0a1cb0a 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -92,7 +92,14 @@ sub use_wt_file
 		return 0;
 	}
 
-	my $wt_sha1 = $repo->command_oneline('hash-object', "$workdir/$file");
+	my $wt_sha1;
+	if (-e "$workdir/$file") {
+		$wt_sha1 = $repo->command_oneline('hash-object', "$workdir/$file");
+	} else {
+		# If the file doesn't exist in the working tree, use something
+		# that cannot match a SHA-1.
+		$wt_sha1 = '';
+	};
 	my $use = ($sha1 eq $null_sha1) || ($sha1 eq $wt_sha1);
 	return ($use, $wt_sha1);
 }
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index a6bd99e..d46f041 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -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
-- 
1.8.3.rc2.285.gfc18c2c

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-05-17 18:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-17 17:29 [PATCH] difftool: fix dir-diff when file does not exist in working tree John Keeping
2013-05-17 18:10 ` Junio C Hamano
2013-05-17 18:26   ` [PATCH v2] " John Keeping
2013-05-17 18:46     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox