Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH 0/2] fix git-archive with empty trees

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:56:21

Jeff King [off-list ref] writes:
On Sun, Mar 10, 2013 at 09:31:24PM -0400, Jeff King wrote:
quoted
I noticed that "git archive" will barf when the root tree is empty.
[...]
I didn't bother even looking at empty subtrees. AFAIK, git should never
produce them (it omits the tree entirely if there is no content in it).
You would have to fake it using hash-object manually. I suspect it would
work just fine, as we already exercise the empty-dir code paths in the
tests I did add.
Curious, I went ahead and tested this. It does indeed work as expected.
Interesting.
The following tests can be squashed into patch 2/2 if we want:
Why not---will do.  Thanks.
quoted hunk
diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh
index 395dd58..cdb7d7a 100755
--- a/t/t5004-archive-corner-cases.sh
+++ b/t/t5004-archive-corner-cases.sh
@@ -80,4 +80,23 @@ test_expect_success 'archive complains about pathspec on empty tree' '
 	test_must_fail git archive --format=tar HEAD -- foo >/dev/null
 '
 
+test_expect_success 'create a commit with an empty subtree' '
+	empty_tree=$(git hash-object -t tree /dev/null) &&
+	root_tree=$(printf "040000 tree $empty_tree\tsub\n" | git mktree)
+'
+
+test_expect_success 'archive empty subtree with no pathspec' '
+	git archive --format=tar $root_tree >subtree-all.tar &&
+	make_dir extract &&
+	"$TAR" xf subtree-all.tar -C extract &&
+	check_dir extract sub
+'
+
+test_expect_success 'archive empty subtree by direct pathspec' '
+	git archive --format=tar $root_tree -- sub >subtree-path.tar &&
+	make_dir extract &&
+	"$TAR" xf subtree-path.tar -C extract &&
+	check_dir extract sub
+'
+
 test_done
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help