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