Commit | Line | Data |
---|---|---|
e9882c80 RS |
1 | #!/bin/sh |
2 | ||
3 | test_description='git archive --format=zip test' | |
4 | ||
5 | . ./test-lib.sh | |
e9882c80 RS |
6 | |
7 | SUBSTFORMAT=%H%n | |
8 | ||
55292ea2 RS |
9 | test_lazy_prereq UNZIP_SYMLINKS ' |
10 | ( | |
11 | mkdir unzip-symlinks && | |
12 | cd unzip-symlinks && | |
13 | "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip && | |
14 | test -h symlink | |
15 | ) | |
16 | ' | |
17 | ||
e9882c80 RS |
18 | check_zip() { |
19 | zipfile=$1.zip | |
20 | listfile=$1.lst | |
21 | dir=$1 | |
22 | dir_with_prefix=$dir/$2 | |
23 | ||
24 | test_expect_success UNZIP " extract ZIP archive" ' | |
25 | (mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile) | |
26 | ' | |
27 | ||
28 | test_expect_success UNZIP " validate filenames" " | |
29 | (cd ${dir_with_prefix}a && find .) | sort >$listfile && | |
30 | test_cmp a.lst $listfile | |
31 | " | |
32 | ||
33 | test_expect_success UNZIP " validate file contents" " | |
34 | diff -r a ${dir_with_prefix}a | |
35 | " | |
4aff646d RS |
36 | |
37 | dir=eol_$1 | |
38 | dir_with_prefix=$dir/$2 | |
39 | extracted=${dir_with_prefix}a | |
40 | original=a | |
41 | ||
42 | test_expect_success UNZIP " extract ZIP archive with EOL conversion" ' | |
43 | (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile) | |
44 | ' | |
45 | ||
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 | |
49 | " | |
50 | ||
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 | |
55 | " | |
56 | ||
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 | |
60 | " | |
61 | ||
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 | |
66 | " | |
e9882c80 RS |
67 | } |
68 | ||
69 | test_expect_success \ | |
70 | 'populate workdir' \ | |
1355241b | 71 | 'mkdir a && |
e9882c80 RS |
72 | echo simple textfile >a/a && |
73 | mkdir a/bin && | |
74 | cp /bin/sh a/bin && | |
4aff646d RS |
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 && | |
e9882c80 RS |
87 | printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && |
88 | printf "A not substituted O" >a/substfile2 && | |
e9882c80 RS |
89 | (p=long_path_to_a_file && cd a && |
90 | for depth in 1 2 3 4 5; do mkdir $p && cd $p; done && | |
55292ea2 RS |
91 | echo text >file_with_long_path) |
92 | ' | |
93 | ||
94 | test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' ' | |
95 | ln -s a a/symlink_to_a | |
96 | ' | |
97 | ||
98 | test_expect_success 'prepare file list' ' | |
99 | (cd a && find .) | sort >a.lst | |
100 | ' | |
e9882c80 RS |
101 | |
102 | test_expect_success \ | |
103 | 'add ignored file' \ | |
104 | 'echo ignore me >a/ignored && | |
105 | echo ignored export-ignore >.git/info/attributes' | |
106 | ||
21711ca4 RS |
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 | |
110 | ' | |
e9882c80 | 111 | |
4aff646d RS |
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 && | |
d3c1472f RS |
115 | echo "substfile?" export-subst >>.git/info/attributes && |
116 | git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \ | |
117 | >a/substfile1 | |
118 | ' | |
119 | ||
e9882c80 RS |
120 | test_expect_success \ |
121 | 'create bare clone' \ | |
122 | 'git clone --bare . bare.git && | |
123 | cp .git/info/attributes bare.git/info/attributes' | |
124 | ||
125 | test_expect_success \ | |
126 | 'remove ignored file' \ | |
127 | 'rm a/ignored' | |
128 | ||
129 | test_expect_success \ | |
130 | 'git archive --format=zip' \ | |
131 | 'git archive --format=zip HEAD >d.zip' | |
132 | ||
133 | check_zip d | |
134 | ||
135 | test_expect_success \ | |
136 | 'git archive --format=zip in a bare repo' \ | |
137 | '(cd bare.git && git archive --format=zip HEAD) >d1.zip' | |
138 | ||
139 | test_expect_success \ | |
140 | 'git archive --format=zip vs. the same in a bare repo' \ | |
b93e6e36 | 141 | 'test_cmp_bin d.zip d1.zip' |
e9882c80 RS |
142 | |
143 | test_expect_success 'git archive --format=zip with --output' \ | |
144 | 'git archive --format=zip --output=d2.zip HEAD && | |
b93e6e36 | 145 | test_cmp_bin d.zip d2.zip' |
e9882c80 RS |
146 | |
147 | test_expect_success 'git archive with --output, inferring format' ' | |
148 | git archive --output=d3.zip HEAD && | |
b93e6e36 | 149 | test_cmp_bin d.zip d3.zip |
e9882c80 RS |
150 | ' |
151 | ||
152 | test_expect_success \ | |
153 | 'git archive --format=zip with prefix' \ | |
154 | 'git archive --format=zip --prefix=prefix/ HEAD >e.zip' | |
155 | ||
156 | check_zip e prefix/ | |
157 | ||
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 | |
161 | ' | |
162 | ||
163 | check_zip large | |
164 | ||
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 | |
168 | ' | |
169 | ||
170 | check_zip large-compressed | |
171 | ||
172 | test_done |