for-each-ref: use skip_prefix instead of starts_with
[git/mjg.git] / t / t5003-archive-zip.sh
blob14744b2a4b1e646890176ec53970d36de6f8ec3b
1 #!/bin/sh
3 test_description='git archive --format=zip test'
5 . ./test-lib.sh
7 SUBSTFORMAT=%H%n
9 test_lazy_prereq UNZIP_SYMLINKS '
11 mkdir unzip-symlinks &&
12 cd unzip-symlinks &&
13 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip &&
14 test -h symlink
18 check_zip() {
19 zipfile=$1.zip
20 listfile=$1.lst
21 dir=$1
22 dir_with_prefix=$dir/$2
24 test_expect_success UNZIP " extract ZIP archive" '
25 (mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile)
28 test_expect_success UNZIP " validate filenames" "
29 (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
30 test_cmp a.lst $listfile
33 test_expect_success UNZIP " validate file contents" "
34 diff -r a ${dir_with_prefix}a
37 dir=eol_$1
38 dir_with_prefix=$dir/$2
39 extracted=${dir_with_prefix}a
40 original=a
42 test_expect_success UNZIP " extract ZIP archive with EOL conversion" '
43 (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile)
46 test_expect_success UNZIP " validate that text files are converted" "
47 test_cmp_bin $extracted/text.cr $extracted/text.crlf &&
48 test_cmp_bin $extracted/text.cr $extracted/text.lf
51 test_expect_success UNZIP " validate that binary files are unchanged" "
52 test_cmp_bin $original/binary.cr $extracted/binary.cr &&
53 test_cmp_bin $original/binary.crlf $extracted/binary.crlf &&
54 test_cmp_bin $original/binary.lf $extracted/binary.lf
57 test_expect_success UNZIP " validate that diff files are converted" "
58 test_cmp_bin $extracted/diff.cr $extracted/diff.crlf &&
59 test_cmp_bin $extracted/diff.cr $extracted/diff.lf
62 test_expect_success UNZIP " validate that -diff files are unchanged" "
63 test_cmp_bin $original/nodiff.cr $extracted/nodiff.cr &&
64 test_cmp_bin $original/nodiff.crlf $extracted/nodiff.crlf &&
65 test_cmp_bin $original/nodiff.lf $extracted/nodiff.lf
69 test_expect_success \
70 'populate workdir' \
71 'mkdir a &&
72 echo simple textfile >a/a &&
73 mkdir a/bin &&
74 cp /bin/sh a/bin &&
75 printf "text\r" >a/text.cr &&
76 printf "text\r\n" >a/text.crlf &&
77 printf "text\n" >a/text.lf &&
78 printf "text\r" >a/nodiff.cr &&
79 printf "text\r\n" >a/nodiff.crlf &&
80 printf "text\n" >a/nodiff.lf &&
81 printf "\0\r" >a/binary.cr &&
82 printf "\0\r\n" >a/binary.crlf &&
83 printf "\0\n" >a/binary.lf &&
84 printf "\0\r" >a/diff.cr &&
85 printf "\0\r\n" >a/diff.crlf &&
86 printf "\0\n" >a/diff.lf &&
87 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
88 printf "A not substituted O" >a/substfile2 &&
89 (p=long_path_to_a_file && cd a &&
90 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
91 echo text >file_with_long_path)
94 test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
95 ln -s a a/symlink_to_a
98 test_expect_success 'prepare file list' '
99 (cd a && find .) | sort >a.lst
102 test_expect_success \
103 'add ignored file' \
104 'echo ignore me >a/ignored &&
105 echo ignored export-ignore >.git/info/attributes'
107 test_expect_success 'add files to repository' '
108 git add a &&
109 GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
112 test_expect_success 'setup export-subst and diff attributes' '
113 echo "a/nodiff.* -diff" >>.git/info/attributes &&
114 echo "a/diff.* diff" >>.git/info/attributes &&
115 echo "substfile?" export-subst >>.git/info/attributes &&
116 git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
117 >a/substfile1
120 test_expect_success \
121 'create bare clone' \
122 'git clone --bare . bare.git &&
123 cp .git/info/attributes bare.git/info/attributes'
125 test_expect_success \
126 'remove ignored file' \
127 'rm a/ignored'
129 test_expect_success \
130 'git archive --format=zip' \
131 'git archive --format=zip HEAD >d.zip'
133 check_zip d
135 test_expect_success \
136 'git archive --format=zip in a bare repo' \
137 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
139 test_expect_success \
140 'git archive --format=zip vs. the same in a bare repo' \
141 'test_cmp_bin d.zip d1.zip'
143 test_expect_success 'git archive --format=zip with --output' \
144 'git archive --format=zip --output=d2.zip HEAD &&
145 test_cmp_bin d.zip d2.zip'
147 test_expect_success 'git archive with --output, inferring format' '
148 git archive --output=d3.zip HEAD &&
149 test_cmp_bin d.zip d3.zip
152 test_expect_success \
153 'git archive --format=zip with prefix' \
154 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
156 check_zip e prefix/
158 test_expect_success 'git archive -0 --format=zip on large files' '
159 test_config core.bigfilethreshold 1 &&
160 git archive -0 --format=zip HEAD >large.zip
163 check_zip large
165 test_expect_success 'git archive --format=zip on large files' '
166 test_config core.bigfilethreshold 1 &&
167 git archive --format=zip HEAD >large-compressed.zip
170 check_zip large-compressed
172 test_done