All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] blame: Allow to blame paths freshly added to the index
@ 2016-07-15  2:42 Mike Hommey
  2016-07-15 10:45 ` Johannes Schindelin
  2016-07-15 20:58 ` [PATCH] " Junio C Hamano
  0 siblings, 2 replies; 15+ messages in thread
From: Mike Hommey @ 2016-07-15  2:42 UTC (permalink / raw)
  To: git; +Cc: gitster

When blaming files, changes in the work tree are taken into account
and displayed as being "Not Committed Yet".

However, when blaming a file that is not known to the current HEAD,
git blame fails with `no such path 'foo' in HEAD`, even when the file
was git add'ed.

This would seem uninteresting with the plain `git blame` case, which
it is, but it becomes useful when using copy detection, and the new file
was created from pieces already in HEAD, moved or copied from other
files.
---
 builtin/blame.c               |  4 +++-
 t/t8003-blame-corner-cases.sh | 23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 1e214bd..0858b18 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2240,7 +2240,9 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
 		    sha1_object_info(blob_sha1, NULL) == OBJ_BLOB)
 			return;
 	}
-	die("no such path '%s' in HEAD", path);
+
+	if (cache_name_pos(path, strlen(path)) < 0)
+		die("no such path '%s' in HEAD", path);
 }
 
 static struct commit_list **append_parent(struct commit_list **tail, const unsigned char *sha1)
diff --git a/t/t8003-blame-corner-cases.sh b/t/t8003-blame-corner-cases.sh
index a9b266f..a0a09e2 100755
--- a/t/t8003-blame-corner-cases.sh
+++ b/t/t8003-blame-corner-cases.sh
@@ -137,6 +137,29 @@ test_expect_success 'blame wholesale copy and more' '
 
 '
 
+test_expect_success 'blame wholesale copy and more in the index' '
+
+	{
+		echo ABC
+		echo DEF
+		echo XXXX
+		echo YYYY
+		echo GHIJK
+	} >horse &&
+	git add horse &&
+	git blame -f -C -C1 -- horse | sed -e "$pick_fc" >current &&
+	{
+		echo mouse-Initial
+		echo mouse-Second
+		echo cow-Fifth
+		echo horse-Not
+		echo mouse-Third
+	} >expected &&
+	test_cmp expected current &&
+	git rm -f horse
+
+'
+
 test_expect_success 'blame path that used to be a directory' '
 	mkdir path &&
 	echo A A A A A >path/file &&
-- 
2.9.1.276.geea30e8


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

end of thread, other threads:[~2016-07-18 18:52 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-15  2:42 [PATCH] blame: Allow to blame paths freshly added to the index Mike Hommey
2016-07-15 10:45 ` Johannes Schindelin
2016-07-15 12:32   ` Mike Hommey
2016-07-15 12:37     ` Jeff King
2016-07-15 12:42       ` Mike Hommey
2016-07-15 12:55   ` [PATCH v2] " Mike Hommey
2016-07-15 15:28     ` Johannes Schindelin
2016-07-15 20:58 ` [PATCH] " Junio C Hamano
2016-07-15 21:14   ` Junio C Hamano
2016-07-15 23:16     ` Mike Hommey
2016-07-18 18:49       ` Junio C Hamano
2016-07-15 23:23     ` [PATCH v3 1/2] " Mike Hommey
2016-07-15 23:23       ` [PATCH v3 2/2] t/t8003-blame-corner-cases.sh: Use here documents Mike Hommey
2016-07-16 13:05         ` Johannes Schindelin
2016-07-18 18:52         ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.