t5004: resurrect original empty tar archive test
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Thu, 9 May 2013 13:36:10 +0000 (15:36 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 May 2013 19:22:31 +0000 (12:22 -0700)
Add a test to verify the emptiness of an archive by extracting its
contents. Don't run this test if the version of tar doesn't support
archives containing only a comment header, though.

The existing check 'tar archive of empty tree is empty' used to work
like that (minus the tar capability check) but was changed to depend
on the exact representation of empty tar files created by git archive
instead of on the behaviour of tar in order to avoid issues with
different tar versions.

The different approaches test different things: The existing one is
for empty trees, for which we know the exact expected output and thus
we can simply check it without extracting; the new one is for commits
with empty trees, whose archives include stamps and so the more
"natural" check by extraction is a better fit because it focuses on
the interesting aspect, namely the absence of any archive entries.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5004-archive-corner-cases.sh
t/t5004/empty-with-pax-header.tar [new file with mode: 0644]
index 8d1bbd356ac9a22021db0cdbd14544fbcf3c9246..f25f06b02209fbf72b9022a21d8ab9a90cb6628b 100755 (executable)
@@ -27,6 +27,20 @@ check_dir() {
        test_cmp expect actual
 }
 
+# bsdtar/libarchive versions before 3.1.3 consider a tar file with a
+# global pax header that is not followed by a file record as corrupt.
+if "$TAR" tf "$TEST_DIRECTORY"/t5004/empty-with-pax-header.tar >/dev/null 2>&1
+then
+       test_set_prereq HEADER_ONLY_TAR_OK
+fi
+
+test_expect_success HEADER_ONLY_TAR_OK 'tar archive of commit with empty tree' '
+       git archive --format=tar HEAD >empty-with-pax-header.tar &&
+       make_dir extract &&
+       "$TAR" xf empty-with-pax-header.tar -C extract &&
+       check_dir extract
+'
+
 test_expect_success 'tar archive of empty tree is empty' '
        git archive --format=tar HEAD: >empty.tar &&
        perl -e "print \"\\0\" x 10240" >10knuls.tar &&
diff --git a/t/t5004/empty-with-pax-header.tar b/t/t5004/empty-with-pax-header.tar
new file mode 100644 (file)
index 0000000..da9e39e
Binary files /dev/null and b/t/t5004/empty-with-pax-header.tar differ