archive-zip: use deflateInit2() to ask for raw compressed data
[git] / t / t5003-archive-zip.sh
1 #!/bin/sh
2
3 test_description='git archive --format=zip test'
4
5 . ./test-lib.sh
6 GIT_UNZIP=${GIT_UNZIP:-unzip}
7
8 SUBSTFORMAT=%H%n
9
10 test_lazy_prereq UNZIP '
11         "$GIT_UNZIP" -v
12         test $? -ne 127
13 '
14
15 test_lazy_prereq UNZIP_SYMLINKS '
16         (
17                 mkdir unzip-symlinks &&
18                 cd unzip-symlinks &&
19                 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip &&
20                 test -h symlink
21         )
22 '
23
24 check_zip() {
25         zipfile=$1.zip
26         listfile=$1.lst
27         dir=$1
28         dir_with_prefix=$dir/$2
29
30         test_expect_success UNZIP " extract ZIP archive" '
31                 (mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile)
32         '
33
34         test_expect_success UNZIP " validate filenames" "
35                 (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
36                 test_cmp a.lst $listfile
37         "
38
39         test_expect_success UNZIP " validate file contents" "
40                 diff -r a ${dir_with_prefix}a
41         "
42 }
43
44 test_expect_success \
45     'populate workdir' \
46     'mkdir a b c &&
47      echo simple textfile >a/a &&
48      mkdir a/bin &&
49      cp /bin/sh a/bin &&
50      printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
51      printf "A not substituted O" >a/substfile2 &&
52      (p=long_path_to_a_file && cd a &&
53       for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
54       echo text >file_with_long_path)
55 '
56
57 test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
58         ln -s a a/symlink_to_a
59 '
60
61 test_expect_success 'prepare file list' '
62         (cd a && find .) | sort >a.lst
63 '
64
65 test_expect_success \
66     'add ignored file' \
67     'echo ignore me >a/ignored &&
68      echo ignored export-ignore >.git/info/attributes'
69
70 test_expect_success \
71     'add files to repository' \
72     'find a -type f | xargs git update-index --add &&
73      find a -type l | xargs git update-index --add &&
74      treeid=`git write-tree` &&
75      echo $treeid >treeid &&
76      git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
77      git commit-tree $treeid </dev/null)'
78
79 test_expect_success 'setup export-subst' '
80         echo "substfile?" export-subst >>.git/info/attributes &&
81         git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
82                 >a/substfile1
83 '
84
85 test_expect_success \
86     'create bare clone' \
87     'git clone --bare . bare.git &&
88      cp .git/info/attributes bare.git/info/attributes'
89
90 test_expect_success \
91     'remove ignored file' \
92     'rm a/ignored'
93
94 test_expect_success \
95     'git archive --format=zip' \
96     'git archive --format=zip HEAD >d.zip'
97
98 check_zip d
99
100 test_expect_success \
101     'git archive --format=zip in a bare repo' \
102     '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
103
104 test_expect_success \
105     'git archive --format=zip vs. the same in a bare repo' \
106     'test_cmp d.zip d1.zip'
107
108 test_expect_success 'git archive --format=zip with --output' \
109     'git archive --format=zip --output=d2.zip HEAD &&
110     test_cmp d.zip d2.zip'
111
112 test_expect_success 'git archive with --output, inferring format' '
113         git archive --output=d3.zip HEAD &&
114         test_cmp d.zip d3.zip
115 '
116
117 test_expect_success \
118     'git archive --format=zip with prefix' \
119     'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
120
121 check_zip e prefix/
122
123 test_expect_success 'git archive -0 --format=zip on large files' '
124         test_config core.bigfilethreshold 1 &&
125         git archive -0 --format=zip HEAD >large.zip
126 '
127
128 check_zip large
129
130 test_expect_success 'git archive --format=zip on large files' '
131         test_config core.bigfilethreshold 1 &&
132         git archive --format=zip HEAD >large-compressed.zip
133 '
134
135 check_zip large-compressed
136
137 test_done