Git fork
at reftables-rust 231 lines 6.7 kB view raw
1#!/bin/sh 2 3test_description='test corner cases of git-archive' 4 5. ./test-lib.sh 6 7if ! test_have_prereq PERL_TEST_HELPERS 8then 9 skip_all='skipping archive corner cases tests; Perl not available' 10 test_done 11fi 12 13# the 10knuls.tar file is used to test for an empty git generated tar 14# without having to invoke tar because an otherwise valid empty GNU tar 15# will be considered broken by {Open,Net}BSD tar 16test_expect_success 'create commit with empty tree and fake empty tar' ' 17 git commit --allow-empty -m foo && 18 perl -e "print \"\\0\" x 10240" >10knuls.tar 19' 20 21# Make a dir and clean it up afterwards 22make_dir() { 23 mkdir "$1" && 24 test_when_finished "rm -rf '$1'" 25} 26 27# Check that the dir given in "$1" contains exactly the 28# set of paths given as arguments. 29check_dir() { 30 dir=$1; shift 31 { 32 echo "$dir" && 33 for i in "$@"; do 34 echo "$dir/$i" 35 done 36 } | sort >expect && 37 find "$dir" ! -name pax_global_header -print | sort >actual && 38 test_cmp expect actual 39} 40 41test_lazy_prereq UNZIP_ZIP64_SUPPORT ' 42 "$GIT_UNZIP" -v | grep ZIP64_SUPPORT 43' 44 45# bsdtar/libarchive versions before 3.1.3 consider a tar file with a 46# global pax header that is not followed by a file record as corrupt. 47if "$TAR" tf "$TEST_DIRECTORY"/t5004/empty-with-pax-header.tar >/dev/null 2>&1 48then 49 test_set_prereq HEADER_ONLY_TAR_OK 50fi 51 52test_expect_success HEADER_ONLY_TAR_OK 'tar archive of commit with empty tree' ' 53 git archive --format=tar HEAD >empty-with-pax-header.tar && 54 make_dir extract && 55 "$TAR" xf empty-with-pax-header.tar -C extract && 56 check_dir extract 57' 58 59test_expect_success 'tar archive of empty tree is empty' ' 60 git archive --format=tar HEAD: >empty.tar && 61 test_cmp_bin 10knuls.tar empty.tar 62' 63 64test_expect_success 'tar archive of empty tree with prefix' ' 65 git archive --format=tar --prefix=foo/ HEAD >prefix.tar && 66 make_dir extract && 67 "$TAR" xf prefix.tar -C extract && 68 check_dir extract foo 69' 70 71test_expect_success UNZIP 'zip archive of empty tree is empty' ' 72 # Detect the exit code produced when our particular flavor of unzip 73 # sees an empty archive. Infozip will generate a warning and exit with 74 # code 1. But in the name of sanity, we do not expect other unzip 75 # implementations to do the same thing (it would be perfectly 76 # reasonable to exit 0, for example). 77 # 78 # This makes our test less rigorous on some platforms (unzip may not 79 # handle the empty repo at all, making our later check of its exit code 80 # a no-op). But we cannot do anything reasonable except skip the test 81 # on such platforms anyway, and this is the moral equivalent. 82 { 83 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/empty.zip 84 expect_code=$? 85 } && 86 87 git archive --format=zip HEAD >empty.zip && 88 make_dir extract && 89 ( 90 cd extract && 91 test_expect_code $expect_code "$GIT_UNZIP" ../empty.zip 92 ) && 93 check_dir extract 94' 95 96test_expect_success UNZIP 'zip archive of empty tree with prefix' ' 97 # We do not have to play exit-code tricks here, because our 98 # result should not be empty; it has a directory in it. 99 git archive --format=zip --prefix=foo/ HEAD >prefix.zip && 100 make_dir extract && 101 ( 102 cd extract && 103 "$GIT_UNZIP" ../prefix.zip 104 ) && 105 check_dir extract foo 106' 107 108test_expect_success 'archive complains about pathspec on empty tree' ' 109 test_must_fail git archive --format=tar HEAD -- foo >/dev/null 110' 111 112test_expect_success 'create a commit with an empty subtree' ' 113 empty_tree=$(git hash-object -t tree /dev/null) && 114 root_tree=$(printf "040000 tree $empty_tree\tsub\n" | git mktree) 115' 116 117test_expect_success 'archive empty subtree with no pathspec' ' 118 git archive --format=tar $root_tree >subtree-all.tar && 119 test_cmp_bin 10knuls.tar subtree-all.tar 120' 121 122test_expect_success 'archive empty subtree by direct pathspec' ' 123 git archive --format=tar $root_tree -- sub >subtree-path.tar && 124 test_cmp_bin 10knuls.tar subtree-path.tar 125' 126 127ZIPINFO=zipinfo 128 129test_lazy_prereq ZIPINFO ' 130 n=$("$ZIPINFO" "$TEST_DIRECTORY"/t5004/empty.zip | sed -n "2s/.* //p") 131 test "x$n" = "x0" 132' 133 134test_expect_success ZIPINFO 'zip archive with many entries' ' 135 # add a directory with 256 files 136 mkdir 00 && 137 for a in 0 1 2 3 4 5 6 7 8 9 a b c d e f 138 do 139 for b in 0 1 2 3 4 5 6 7 8 9 a b c d e f 140 do 141 : >00/$a$b || return 1 142 done 143 done && 144 git add 00 && 145 git commit -m "256 files in 1 directory" && 146 147 # duplicate it to get 65536 files in 256 directories 148 subtree=$(git write-tree --prefix=00/) && 149 for c in 0 1 2 3 4 5 6 7 8 9 a b c d e f 150 do 151 for d in 0 1 2 3 4 5 6 7 8 9 a b c d e f 152 do 153 echo "040000 tree $subtree $c$d" || return 1 154 done 155 done >tree && 156 tree=$(git mktree <tree) && 157 158 # zip them 159 git archive -o many.zip $tree && 160 161 # check the number of entries in the ZIP file directory 162 expr 65536 + 256 >expect && 163 "$ZIPINFO" -h many.zip >zipinfo && 164 sed -n "2s/.* //p" <zipinfo >actual && 165 test_cmp expect actual 166' 167 168test_expect_success EXPENSIVE,UNZIP,UNZIP_ZIP64_SUPPORT \ 169 'zip archive bigger than 4GB' ' 170 # build string containing 65536 characters 171 s=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef && 172 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 && 173 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 && 174 175 # create blob with a length of 65536 + 1 bytes 176 blob=$(echo $s | git hash-object -w --stdin) && 177 178 # create tree containing 65500 entries of that blob 179 test_seq -f "100644 blob $blob\t%d" 1 65500 >tree && 180 tree=$(git mktree <tree) && 181 182 # zip it, creating an archive a bit bigger than 4GB 183 git archive -0 -o many-big.zip $tree && 184 185 "$GIT_UNZIP" -t many-big.zip 9999 65500 && 186 "$GIT_UNZIP" -t many-big.zip 187' 188 189test_expect_success EXPENSIVE,LONG_IS_64BIT,UNZIP,UNZIP_ZIP64_SUPPORT,ZIPINFO \ 190 'zip archive with files bigger than 4GB' ' 191 # Pack created with: 192 # dd if=/dev/zero of=file bs=1M count=4100 && git hash-object -w file 193 mkdir -p .git/objects/pack && 194 ( 195 cd .git/objects/pack && 196 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/big-pack.zip 197 ) && 198 blob=754a93d6fada4c6873360e6cb4b209132271ab0e && 199 size=$(expr 4100 "*" 1024 "*" 1024) && 200 201 # create a tree containing the file 202 tree=$(echo "100644 blob $blob big-file" | git mktree) && 203 204 # zip it, creating an archive with a file bigger than 4GB 205 git archive -o big.zip $tree && 206 207 "$GIT_UNZIP" -t big.zip && 208 "$ZIPINFO" big.zip >big.lst && 209 grep $size big.lst 210' 211 212build_tree() { 213 perl -e ' 214 my $hash = $ARGV[0]; 215 foreach my $order (2..6) { 216 $first = 10 ** $order; 217 foreach my $i (-13..-9) { 218 my $name = "a" x ($first + $i); 219 print "100644 blob $hash\t$name\n" 220 } 221 } 222 ' "$1" 223} 224 225test_expect_success 'tar archive with long paths' ' 226 blob=$(echo foo | git hash-object -w --stdin) && 227 tree=$(build_tree $blob | git mktree) && 228 git archive -o long_paths.tar $tree 229' 230 231test_done