3 test_description='test corner cases of git-archive'
6 test_expect_success 'create commit with empty tree' '
7 git commit --allow-empty -m foo
10 # Make a dir and clean it up afterwards
13 test_when_finished "rm -rf '$1'"
16 # Check that the dir given in "$1" contains exactly the
17 # set of paths given as arguments.
26 find "$dir" -print | sort >actual &&
27 test_cmp expect actual
30 test_expect_success 'tar archive of empty tree is empty' '
31 git archive --format=tar HEAD >empty.tar &&
33 "$TAR" xf empty.tar -C extract &&
37 test_expect_success 'tar archive of empty tree with prefix' '
38 git archive --format=tar --prefix=foo/ HEAD >prefix.tar &&
40 "$TAR" xf prefix.tar -C extract &&
44 test_expect_success UNZIP 'zip archive of empty tree is empty' '
45 # Detect the exit code produced when our particular flavor of unzip
46 # sees an empty archive. Infozip will generate a warning and exit with
47 # code 1. But in the name of sanity, we do not expect other unzip
48 # implementations to do the same thing (it would be perfectly
49 # reasonable to exit 0, for example).
51 # This makes our test less rigorous on some platforms (unzip may not
52 # handle the empty repo at all, making our later check of its exit code
53 # a no-op). But we cannot do anything reasonable except skip the test
54 # on such platforms anyway, and this is the moral equivalent.
55 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/empty.zip
58 git archive --format=zip HEAD >empty.zip &&
62 test_expect_code $expect_code "$GIT_UNZIP" ../empty.zip
67 test_expect_success UNZIP 'zip archive of empty tree with prefix' '
68 # We do not have to play exit-code tricks here, because our
69 # result should not be empty; it has a directory in it.
70 git archive --format=zip --prefix=foo/ HEAD >prefix.zip &&
74 "$GIT_UNZIP" ../prefix.zip
79 test_expect_success 'archive complains about pathspec on empty tree' '
80 test_must_fail git archive --format=tar HEAD -- foo >/dev/null
83 test_expect_success 'create a commit with an empty subtree' '
84 empty_tree=$(git hash-object -t tree /dev/null) &&
85 root_tree=$(printf "040000 tree $empty_tree\tsub\n" | git mktree)
88 test_expect_success 'archive empty subtree with no pathspec' '
89 git archive --format=tar $root_tree >subtree-all.tar &&
91 "$TAR" xf subtree-all.tar -C extract &&
95 test_expect_success 'archive empty subtree by direct pathspec' '
96 git archive --format=tar $root_tree -- sub >subtree-path.tar &&
98 "$TAR" xf subtree-path.tar -C extract &&