]>
Commit | Line | Data |
---|---|---|
d3d49c3d RS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (C) 2005 Rene Scharfe | |
4 | # | |
5 | ||
5be60078 | 6 | test_description='git tar-tree and git get-tar-commit-id test |
d3d49c3d | 7 | |
5b860406 RS |
8 | This test covers the topics of file contents, commit date handling and |
9 | commit id embedding: | |
d3d49c3d RS |
10 | |
11 | The contents of the repository is compared to the extracted tar | |
12 | archive. The repository contains simple text files, symlinks and a | |
3dff5379 | 13 | binary file (/bin/sh). Only paths shorter than 99 characters are |
5b860406 | 14 | used. |
d3d49c3d | 15 | |
5be60078 | 16 | git tar-tree applies the commit date to every file in the archive it |
d3d49c3d RS |
17 | creates. The test sets the commit date to a specific value and checks |
18 | if the tar archive contains that value. | |
19 | ||
5be60078 | 20 | When giving git tar-tree a commit id (in contrast to a tree id) it |
d3d49c3d | 21 | embeds this commit id into the tar archive as a comment. The test |
5be60078 | 22 | checks the ability of git get-tar-commit-id to figure it out from the |
d3d49c3d RS |
23 | tar file. |
24 | ||
25 | ' | |
26 | ||
27 | . ./test-lib.sh | |
0e804e09 JK |
28 | GZIP=${GZIP:-gzip} |
29 | GUNZIP=${GUNZIP:-gzip -d} | |
d3d49c3d | 30 | |
38c9c9b7 | 31 | SUBSTFORMAT=%H%n |
8460b2fc | 32 | |
deb9c8ed RS |
33 | check_tar() { |
34 | tarfile=$1.tar | |
35 | listfile=$1.lst | |
36 | dir=$1 | |
37 | dir_with_prefix=$dir/$2 | |
38 | ||
39 | test_expect_success ' extract tar archive' ' | |
40 | (mkdir $dir && cd $dir && "$TAR" xf -) <$tarfile | |
41 | ' | |
42 | ||
43 | test_expect_success ' validate filenames' ' | |
44 | (cd ${dir_with_prefix}a && find .) | sort >$listfile && | |
45 | test_cmp a.lst $listfile | |
46 | ' | |
47 | ||
48 | test_expect_success ' validate file contents' ' | |
49 | diff -r a ${dir_with_prefix}a | |
50 | ' | |
51 | } | |
52 | ||
d3d49c3d RS |
53 | test_expect_success \ |
54 | 'populate workdir' \ | |
1355241b | 55 | 'mkdir a && |
d3d49c3d | 56 | echo simple textfile >a/a && |
d3d49c3d | 57 | mkdir a/bin && |
5b860406 | 58 | cp /bin/sh a/bin && |
760da960 RS |
59 | printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && |
60 | printf "A not substituted O" >a/substfile2 && | |
704a3143 JS |
61 | if test_have_prereq SYMLINKS; then |
62 | ln -s a a/l1 | |
63 | else | |
64 | printf %s a > a/l1 | |
65 | fi && | |
4c691724 RS |
66 | (p=long_path_to_a_file && cd a && |
67 | for depth in 1 2 3 4 5; do mkdir $p && cd $p; done && | |
68 | echo text >file_with_long_path) && | |
d3d49c3d RS |
69 | (cd a && find .) | sort >a.lst' |
70 | ||
008d896d RS |
71 | test_expect_success \ |
72 | 'add ignored file' \ | |
73 | 'echo ignore me >a/ignored && | |
ad94657f | 74 | echo ignored export-ignore >.git/info/attributes' |
008d896d | 75 | |
d3d49c3d RS |
76 | test_expect_success \ |
77 | 'add files to repository' \ | |
5be60078 JH |
78 | 'find a -type f | xargs git update-index --add && |
79 | find a -type l | xargs git update-index --add && | |
80 | treeid=`git write-tree` && | |
d3d49c3d | 81 | echo $treeid >treeid && |
5be60078 JH |
82 | git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \ |
83 | git commit-tree $treeid </dev/null)' | |
d3d49c3d | 84 | |
c420df7b RS |
85 | test_expect_success 'setup export-subst' ' |
86 | echo "substfile?" export-subst >>.git/info/attributes && | |
87 | git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \ | |
88 | >a/substfile1 | |
89 | ' | |
90 | ||
ddff8563 CB |
91 | test_expect_success \ |
92 | 'create bare clone' \ | |
93 | 'git clone --bare . bare.git && | |
ad94657f | 94 | cp .git/info/attributes bare.git/info/attributes' |
ddff8563 | 95 | |
008d896d RS |
96 | test_expect_success \ |
97 | 'remove ignored file' \ | |
98 | 'rm a/ignored' | |
99 | ||
8ff21b1a | 100 | test_expect_success \ |
5be60078 JH |
101 | 'git archive' \ |
102 | 'git archive HEAD >b.tar' | |
8ff21b1a | 103 | |
deb9c8ed RS |
104 | check_tar b |
105 | ||
03d9bc56 RS |
106 | test_expect_success 'git archive --prefix=prefix/' ' |
107 | git archive --prefix=prefix/ HEAD >with_prefix.tar | |
108 | ' | |
109 | ||
110 | check_tar with_prefix prefix/ | |
111 | ||
112 | test_expect_success 'git-archive --prefix=olde-' ' | |
113 | git archive --prefix=olde- HEAD >with_olde-prefix.tar | |
114 | ' | |
115 | ||
116 | check_tar with_olde-prefix olde- | |
117 | ||
5544049d NTND |
118 | test_expect_success 'git archive on large files' ' |
119 | test_config core.bigfilethreshold 1 && | |
120 | git archive HEAD >b3.tar && | |
121 | test_cmp b.tar b3.tar | |
122 | ' | |
123 | ||
ddff8563 CB |
124 | test_expect_success \ |
125 | 'git archive in a bare repo' \ | |
126 | '(cd bare.git && git archive HEAD) >b3.tar' | |
127 | ||
128 | test_expect_success \ | |
129 | 'git archive vs. the same in a bare repo' \ | |
130 | 'test_cmp b.tar b3.tar' | |
131 | ||
aec0c1bb CMDV |
132 | test_expect_success 'git archive with --output' \ |
133 | 'git archive --output=b4.tar HEAD && | |
134 | test_cmp b.tar b4.tar' | |
135 | ||
1bc01efe | 136 | test_expect_success 'git archive --remote' \ |
48139269 TR |
137 | 'git archive --remote=. HEAD >b5.tar && |
138 | test_cmp b.tar b5.tar' | |
139 | ||
d3d49c3d RS |
140 | test_expect_success \ |
141 | 'validate file modification time' \ | |
30684dfa | 142 | 'mkdir extract && |
bfce5087 | 143 | "$TAR" xf b.tar -C extract a/a && |
111539a3 | 144 | test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime && |
30684dfa | 145 | echo "1117231200" >expected.mtime && |
188c3827 | 146 | test_cmp expected.mtime b.mtime' |
d3d49c3d RS |
147 | |
148 | test_expect_success \ | |
5be60078 JH |
149 | 'git get-tar-commit-id' \ |
150 | 'git get-tar-commit-id <b.tar >b.commitid && | |
188c3827 | 151 | test_cmp .git/$(git symbolic-ref HEAD) b.commitid' |
d3d49c3d | 152 | |
0a00ee58 RS |
153 | test_expect_success 'git tar-tree' ' |
154 | git tar-tree HEAD >tar-tree.tar && | |
155 | test_cmp b.tar tar-tree.tar | |
156 | ' | |
d3d49c3d | 157 | |
0a00ee58 RS |
158 | test_expect_success 'git tar-tree with prefix' ' |
159 | git tar-tree HEAD prefix >tar-tree_with_prefix.tar && | |
160 | test_cmp with_prefix.tar tar-tree_with_prefix.tar | |
161 | ' | |
d3d49c3d | 162 | |
fe12d8e8 RS |
163 | test_expect_success 'git archive with --output, override inferred format' ' |
164 | git archive --format=tar --output=d4.zip HEAD && | |
165 | test_cmp b.tar d4.zip | |
166 | ' | |
167 | ||
265d5280 | 168 | test_expect_success \ |
5be60078 JH |
169 | 'git archive --list outside of a git repo' \ |
170 | 'GIT_DIR=some/non-existing/directory git archive --list' | |
265d5280 | 171 | |
ee27ca4a JK |
172 | test_expect_success 'clients cannot access unreachable commits' ' |
173 | test_commit unreachable && | |
174 | sha1=`git rev-parse HEAD` && | |
175 | git reset --hard HEAD^ && | |
176 | git archive $sha1 >remote.tar && | |
177 | test_must_fail git archive --remote=. $sha1 >remote.tar | |
178 | ' | |
179 | ||
767cf457 JK |
180 | test_expect_success 'setup tar filters' ' |
181 | git config tar.tar.foo.command "tr ab ba" && | |
7b97730b | 182 | git config tar.bar.command "tr ab ba" && |
785a0429 JK |
183 | git config tar.bar.remote true && |
184 | git config tar.invalid baz | |
767cf457 JK |
185 | ' |
186 | ||
187 | test_expect_success 'archive --list mentions user filter' ' | |
188 | git archive --list >output && | |
189 | grep "^tar\.foo\$" output && | |
190 | grep "^bar\$" output | |
191 | ' | |
192 | ||
1bc01efe | 193 | test_expect_success 'archive --list shows only enabled remote filters' ' |
767cf457 | 194 | git archive --list --remote=. >output && |
7b97730b | 195 | ! grep "^tar\.foo\$" output && |
767cf457 JK |
196 | grep "^bar\$" output |
197 | ' | |
198 | ||
199 | test_expect_success 'invoke tar filter by format' ' | |
200 | git archive --format=tar.foo HEAD >config.tar.foo && | |
201 | tr ab ba <config.tar.foo >config.tar && | |
202 | test_cmp b.tar config.tar && | |
203 | git archive --format=bar HEAD >config.bar && | |
204 | tr ab ba <config.bar >config.tar && | |
205 | test_cmp b.tar config.tar | |
206 | ' | |
207 | ||
208 | test_expect_success 'invoke tar filter by extension' ' | |
209 | git archive -o config-implicit.tar.foo HEAD && | |
210 | test_cmp config.tar.foo config-implicit.tar.foo && | |
211 | git archive -o config-implicit.bar HEAD && | |
212 | test_cmp config.tar.foo config-implicit.bar | |
213 | ' | |
214 | ||
215 | test_expect_success 'default output format remains tar' ' | |
216 | git archive -o config-implicit.baz HEAD && | |
217 | test_cmp b.tar config-implicit.baz | |
218 | ' | |
219 | ||
220 | test_expect_success 'extension matching requires dot' ' | |
221 | git archive -o config-implicittar.foo HEAD && | |
222 | test_cmp b.tar config-implicittar.foo | |
223 | ' | |
224 | ||
1bc01efe | 225 | test_expect_success 'only enabled filters are available remotely' ' |
7b97730b JK |
226 | test_must_fail git archive --remote=. --format=tar.foo HEAD \ |
227 | >remote.tar.foo && | |
228 | git archive --remote=. --format=bar >remote.bar HEAD && | |
229 | test_cmp remote.bar config.bar | |
230 | ' | |
231 | ||
0e804e09 JK |
232 | if $GZIP --version >/dev/null 2>&1; then |
233 | test_set_prereq GZIP | |
234 | else | |
235 | say "Skipping some tar.gz tests because gzip not found" | |
236 | fi | |
237 | ||
238 | test_expect_success GZIP 'git archive --format=tgz' ' | |
239 | git archive --format=tgz HEAD >j.tgz | |
240 | ' | |
241 | ||
242 | test_expect_success GZIP 'git archive --format=tar.gz' ' | |
243 | git archive --format=tar.gz HEAD >j1.tar.gz && | |
244 | test_cmp j.tgz j1.tar.gz | |
245 | ' | |
246 | ||
247 | test_expect_success GZIP 'infer tgz from .tgz filename' ' | |
248 | git archive --output=j2.tgz HEAD && | |
249 | test_cmp j.tgz j2.tgz | |
250 | ' | |
251 | ||
252 | test_expect_success GZIP 'infer tgz from .tar.gz filename' ' | |
253 | git archive --output=j3.tar.gz HEAD && | |
254 | test_cmp j.tgz j3.tar.gz | |
255 | ' | |
256 | ||
257 | if $GUNZIP --version >/dev/null 2>&1; then | |
258 | test_set_prereq GUNZIP | |
259 | else | |
260 | say "Skipping some tar.gz tests because gunzip was not found" | |
261 | fi | |
262 | ||
263 | test_expect_success GZIP,GUNZIP 'extract tgz file' ' | |
264 | $GUNZIP -c <j.tgz >j.tar && | |
265 | test_cmp b.tar j.tar | |
266 | ' | |
267 | ||
1bc01efe | 268 | test_expect_success GZIP 'remote tar.gz is allowed by default' ' |
7b97730b JK |
269 | git archive --remote=. --format=tar.gz HEAD >remote.tar.gz && |
270 | test_cmp j.tgz remote.tar.gz | |
271 | ' | |
272 | ||
1bc01efe | 273 | test_expect_success GZIP 'remote tar.gz can be disabled' ' |
7b97730b JK |
274 | git config tar.tar.gz.remote false && |
275 | test_must_fail git archive --remote=. --format=tar.gz HEAD \ | |
276 | >remote.tar.gz | |
277 | ' | |
278 | ||
d3d49c3d | 279 | test_done |