archive-zip.c: mark more strings for translation
[git/debian.git] / t / t5004-archive-corner-cases.sh
blobced44355cab99fc4f5fd9768daf10f5a2c1b21c7
1 #!/bin/sh
3 test_description='test corner cases of git-archive'
4 . ./test-lib.sh
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
11 make_dir() {
12 mkdir "$1" &&
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.
18 check_dir() {
19 dir=$1; shift
21 echo "$dir" &&
22 for i in "$@"; do
23 echo "$dir/$i"
24 done
25 } | sort >expect &&
26 find "$dir" ! -name pax_global_header -print | sort >actual &&
27 test_cmp expect actual
30 test_lazy_prereq UNZIP_ZIP64_SUPPORT '
31 "$GIT_UNZIP" -v | grep ZIP64_SUPPORT
34 # bsdtar/libarchive versions before 3.1.3 consider a tar file with a
35 # global pax header that is not followed by a file record as corrupt.
36 if "$TAR" tf "$TEST_DIRECTORY"/t5004/empty-with-pax-header.tar >/dev/null 2>&1
37 then
38 test_set_prereq HEADER_ONLY_TAR_OK
41 test_expect_success HEADER_ONLY_TAR_OK 'tar archive of commit with empty tree' '
42 git archive --format=tar HEAD >empty-with-pax-header.tar &&
43 make_dir extract &&
44 "$TAR" xf empty-with-pax-header.tar -C extract &&
45 check_dir extract
48 test_expect_success 'tar archive of empty tree is empty' '
49 git archive --format=tar HEAD: >empty.tar &&
50 perl -e "print \"\\0\" x 10240" >10knuls.tar &&
51 test_cmp_bin 10knuls.tar empty.tar
54 test_expect_success 'tar archive of empty tree with prefix' '
55 git archive --format=tar --prefix=foo/ HEAD >prefix.tar &&
56 make_dir extract &&
57 "$TAR" xf prefix.tar -C extract &&
58 check_dir extract foo
61 test_expect_success UNZIP 'zip archive of empty tree is empty' '
62 # Detect the exit code produced when our particular flavor of unzip
63 # sees an empty archive. Infozip will generate a warning and exit with
64 # code 1. But in the name of sanity, we do not expect other unzip
65 # implementations to do the same thing (it would be perfectly
66 # reasonable to exit 0, for example).
68 # This makes our test less rigorous on some platforms (unzip may not
69 # handle the empty repo at all, making our later check of its exit code
70 # a no-op). But we cannot do anything reasonable except skip the test
71 # on such platforms anyway, and this is the moral equivalent.
73 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/empty.zip
74 expect_code=$?
75 } &&
77 git archive --format=zip HEAD >empty.zip &&
78 make_dir extract &&
80 cd extract &&
81 test_expect_code $expect_code "$GIT_UNZIP" ../empty.zip
82 ) &&
83 check_dir extract
86 test_expect_success UNZIP 'zip archive of empty tree with prefix' '
87 # We do not have to play exit-code tricks here, because our
88 # result should not be empty; it has a directory in it.
89 git archive --format=zip --prefix=foo/ HEAD >prefix.zip &&
90 make_dir extract &&
92 cd extract &&
93 "$GIT_UNZIP" ../prefix.zip
94 ) &&
95 check_dir extract foo
98 test_expect_success 'archive complains about pathspec on empty tree' '
99 test_must_fail git archive --format=tar HEAD -- foo >/dev/null
102 test_expect_success 'create a commit with an empty subtree' '
103 empty_tree=$(git hash-object -t tree /dev/null) &&
104 root_tree=$(printf "040000 tree $empty_tree\tsub\n" | git mktree)
107 test_expect_success 'archive empty subtree with no pathspec' '
108 git archive --format=tar $root_tree >subtree-all.tar &&
109 make_dir extract &&
110 "$TAR" xf subtree-all.tar -C extract &&
111 check_dir extract
114 test_expect_success 'archive empty subtree by direct pathspec' '
115 git archive --format=tar $root_tree -- sub >subtree-path.tar &&
116 make_dir extract &&
117 "$TAR" xf subtree-path.tar -C extract &&
118 check_dir extract
121 ZIPINFO=zipinfo
123 test_lazy_prereq ZIPINFO '
124 n=$("$ZIPINFO" "$TEST_DIRECTORY"/t5004/empty.zip | sed -n "2s/.* //p")
125 test "x$n" = "x0"
128 test_expect_success ZIPINFO 'zip archive with many entries' '
129 # add a directory with 256 files
130 mkdir 00 &&
131 for a in 0 1 2 3 4 5 6 7 8 9 a b c d e f
133 for b in 0 1 2 3 4 5 6 7 8 9 a b c d e f
135 : >00/$a$b
136 done
137 done &&
138 git add 00 &&
139 git commit -m "256 files in 1 directory" &&
141 # duplicate it to get 65536 files in 256 directories
142 subtree=$(git write-tree --prefix=00/) &&
143 for c in 0 1 2 3 4 5 6 7 8 9 a b c d e f
145 for d in 0 1 2 3 4 5 6 7 8 9 a b c d e f
147 echo "040000 tree $subtree $c$d"
148 done
149 done >tree &&
150 tree=$(git mktree <tree) &&
152 # zip them
153 git archive -o many.zip $tree &&
155 # check the number of entries in the ZIP file directory
156 expr 65536 + 256 >expect &&
157 "$ZIPINFO" many.zip | head -2 | sed -n "2s/.* //p" >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"
175 done >tree &&
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' '
187 # Pack created with:
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
193 ) &&
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 &&
205 grep $size big.lst
208 test_done