3 test_description
='test corner cases of git-archive'
6 # the 10knuls.tar file is used to test for an empty git generated tar
7 # without having to invoke tar because an otherwise valid empty GNU tar
8 # will be considered broken by {Open,Net}BSD tar
9 test_expect_success
'create commit with empty tree and fake empty tar' '
10 git commit --allow-empty -m foo &&
11 perl -e "print \"\\0\" x 10240" >10knuls.tar
14 # Make a dir and clean it up afterwards
17 test_when_finished
"rm -rf '$1'"
20 # Check that the dir given in "$1" contains exactly the
21 # set of paths given as arguments.
30 find "$dir" ! -name pax_global_header
-print |
sort >actual
&&
31 test_cmp expect actual
34 test_lazy_prereq UNZIP_ZIP64_SUPPORT
'
35 "$GIT_UNZIP" -v | grep ZIP64_SUPPORT
38 # bsdtar/libarchive versions before 3.1.3 consider a tar file with a
39 # global pax header that is not followed by a file record as corrupt.
40 if "$TAR" tf
"$TEST_DIRECTORY"/t5004
/empty-with-pax-header.
tar >/dev
/null
2>&1
42 test_set_prereq HEADER_ONLY_TAR_OK
45 test_expect_success HEADER_ONLY_TAR_OK
'tar archive of commit with empty tree' '
46 git archive --format=tar HEAD >empty-with-pax-header.tar &&
48 "$TAR" xf empty-with-pax-header.tar -C extract &&
52 test_expect_success
'tar archive of empty tree is empty' '
53 git archive --format=tar HEAD: >empty.tar &&
54 test_cmp_bin 10knuls.tar empty.tar
57 test_expect_success
'tar archive of empty tree with prefix' '
58 git archive --format=tar --prefix=foo/ HEAD >prefix.tar &&
60 "$TAR" xf prefix.tar -C extract &&
64 test_expect_success UNZIP
'zip archive of empty tree is empty' '
65 # Detect the exit code produced when our particular flavor of unzip
66 # sees an empty archive. Infozip will generate a warning and exit with
67 # code 1. But in the name of sanity, we do not expect other unzip
68 # implementations to do the same thing (it would be perfectly
69 # reasonable to exit 0, for example).
71 # This makes our test less rigorous on some platforms (unzip may not
72 # handle the empty repo at all, making our later check of its exit code
73 # a no-op). But we cannot do anything reasonable except skip the test
74 # on such platforms anyway, and this is the moral equivalent.
76 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/empty.zip
80 git archive --format=zip HEAD >empty.zip &&
84 test_expect_code $expect_code "$GIT_UNZIP" ../empty.zip
89 test_expect_success UNZIP
'zip archive of empty tree with prefix' '
90 # We do not have to play exit-code tricks here, because our
91 # result should not be empty; it has a directory in it.
92 git archive --format=zip --prefix=foo/ HEAD >prefix.zip &&
96 "$GIT_UNZIP" ../prefix.zip
101 test_expect_success
'archive complains about pathspec on empty tree' '
102 test_must_fail git archive --format=tar HEAD -- foo >/dev/null
105 test_expect_success
'create a commit with an empty subtree' '
106 empty_tree=$(git hash-object -t tree /dev/null) &&
107 root_tree=$(printf "040000 tree $empty_tree\tsub\n" | git mktree)
110 test_expect_success
'archive empty subtree with no pathspec' '
111 git archive --format=tar $root_tree >subtree-all.tar &&
112 test_cmp_bin 10knuls.tar subtree-all.tar
115 test_expect_success
'archive empty subtree by direct pathspec' '
116 git archive --format=tar $root_tree -- sub >subtree-path.tar &&
117 test_cmp_bin 10knuls.tar subtree-path.tar
122 test_lazy_prereq ZIPINFO
'
123 n=$("$ZIPINFO" "$TEST_DIRECTORY"/t5004/empty.zip | sed -n "2s/.* //p")
127 test_expect_success ZIPINFO
'zip archive with many entries' '
128 # add a directory with 256 files
130 for a in 0 1 2 3 4 5 6 7 8 9 a b c d e f
132 for b in 0 1 2 3 4 5 6 7 8 9 a b c d e f
138 git commit -m "256 files in 1 directory" &&
140 # duplicate it to get 65536 files in 256 directories
141 subtree=$(git write-tree --prefix=00/) &&
142 for c in 0 1 2 3 4 5 6 7 8 9 a b c d e f
144 for d in 0 1 2 3 4 5 6 7 8 9 a b c d e f
146 echo "040000 tree $subtree $c$d"
149 tree=$(git mktree <tree) &&
152 git archive -o many.zip $tree &&
154 # check the number of entries in the ZIP file directory
155 expr 65536 + 256 >expect &&
156 "$ZIPINFO" -h many.zip >zipinfo &&
157 sed -n "2s/.* //p" <zipinfo >actual &&
158 test_cmp expect actual
161 test_expect_success EXPENSIVE
,UNZIP
,UNZIP_ZIP64_SUPPORT \
162 'zip archive bigger than 4GB' '
163 # build string containing 65536 characters
164 s=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef &&
165 s=$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s &&
166 s=$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s &&
168 # create blob with a length of 65536 + 1 bytes
169 blob=$(echo $s | git hash-object -w --stdin) &&
171 # create tree containing 65500 entries of that blob
172 for i in $(test_seq 1 65500)
174 echo "100644 blob $blob $i"
176 tree=$(git mktree <tree) &&
178 # zip it, creating an archive a bit bigger than 4GB
179 git archive -0 -o many-big.zip $tree &&
181 "$GIT_UNZIP" -t many-big.zip 9999 65500 &&
182 "$GIT_UNZIP" -t many-big.zip
185 test_expect_success EXPENSIVE
,LONG_IS_64BIT
,UNZIP
,UNZIP_ZIP64_SUPPORT
,ZIPINFO \
186 'zip archive with files bigger than 4GB' '
188 # dd if=/dev/zero of=file bs=1M count=4100 && git hash-object -w file
189 mkdir -p .git/objects/pack &&
191 cd .git/objects/pack &&
192 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/big-pack.zip
194 blob=754a93d6fada4c6873360e6cb4b209132271ab0e &&
195 size=$(expr 4100 "*" 1024 "*" 1024) &&
197 # create a tree containing the file
198 tree=$(echo "100644 blob $blob big-file" | git mktree) &&
200 # zip it, creating an archive with a file bigger than 4GB
201 git archive -o big.zip $tree &&
203 "$GIT_UNZIP" -t big.zip &&
204 "$ZIPINFO" big.zip >big.lst &&
211 foreach my $order (2..6) {
212 $first = 10 ** $order;
213 foreach my $i (-13..-9) {
214 my $name = "a" x ($first + $i);
215 print "100644 blob $hash\t$name\n"
221 test_expect_success
'tar archive with long paths' '
222 blob=$(echo foo | git hash-object -w --stdin) &&
223 tree=$(build_tree $blob | git mktree) &&
224 git archive -o long_paths.tar $tree