]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5558-clone-bundle-uri.sh
Merge branch 'jh/fsmonitor-darwin-modernize'
[thirdparty/git.git] / t / t5558-clone-bundle-uri.sh
1 #!/bin/sh
2
3 test_description='test fetching bundles with --bundle-uri'
4
5 . ./test-lib.sh
6
7 test_expect_success 'fail to clone from non-existent file' '
8 test_when_finished rm -rf test &&
9 git clone --bundle-uri="$(pwd)/does-not-exist" . test 2>err &&
10 grep "failed to download bundle from URI" err
11 '
12
13 test_expect_success 'fail to clone from non-bundle file' '
14 test_when_finished rm -rf test &&
15 echo bogus >bogus &&
16 git clone --bundle-uri="$(pwd)/bogus" . test 2>err &&
17 grep "is not a bundle" err
18 '
19
20 test_expect_success 'create bundle' '
21 git init clone-from &&
22 git -C clone-from checkout -b topic &&
23 test_commit -C clone-from A &&
24 test_commit -C clone-from B &&
25 git -C clone-from bundle create B.bundle topic
26 '
27
28 test_expect_success 'clone with path bundle' '
29 git clone --bundle-uri="clone-from/B.bundle" \
30 clone-from clone-path &&
31 git -C clone-path rev-parse refs/bundles/topic >actual &&
32 git -C clone-from rev-parse topic >expect &&
33 test_cmp expect actual
34 '
35
36 test_expect_success 'clone with file:// bundle' '
37 git clone --bundle-uri="file://$(pwd)/clone-from/B.bundle" \
38 clone-from clone-file &&
39 git -C clone-file rev-parse refs/bundles/topic >actual &&
40 git -C clone-from rev-parse topic >expect &&
41 test_cmp expect actual
42 '
43
44 # To get interesting tests for bundle lists, we need to construct a
45 # somewhat-interesting commit history.
46 #
47 # ---------------- bundle-4
48 #
49 # 4
50 # / \
51 # ----|---|------- bundle-3
52 # | |
53 # | 3
54 # | |
55 # ----|---|------- bundle-2
56 # | |
57 # 2 |
58 # | |
59 # ----|---|------- bundle-1
60 # \ /
61 # 1
62 # |
63 # (previous commits)
64 test_expect_success 'construct incremental bundle list' '
65 (
66 cd clone-from &&
67 git checkout -b base &&
68 test_commit 1 &&
69 git checkout -b left &&
70 test_commit 2 &&
71 git checkout -b right base &&
72 test_commit 3 &&
73 git checkout -b merge left &&
74 git merge right -m "4" &&
75
76 git bundle create bundle-1.bundle base &&
77 git bundle create bundle-2.bundle base..left &&
78 git bundle create bundle-3.bundle base..right &&
79 git bundle create bundle-4.bundle merge --not left right
80 )
81 '
82
83 test_expect_success 'clone bundle list (file, no heuristic)' '
84 cat >bundle-list <<-EOF &&
85 [bundle]
86 version = 1
87 mode = all
88
89 [bundle "bundle-1"]
90 uri = file://$(pwd)/clone-from/bundle-1.bundle
91
92 [bundle "bundle-2"]
93 uri = file://$(pwd)/clone-from/bundle-2.bundle
94
95 [bundle "bundle-3"]
96 uri = file://$(pwd)/clone-from/bundle-3.bundle
97
98 [bundle "bundle-4"]
99 uri = file://$(pwd)/clone-from/bundle-4.bundle
100 EOF
101
102 git clone --bundle-uri="file://$(pwd)/bundle-list" \
103 clone-from clone-list-file 2>err &&
104 ! grep "Repository lacks these prerequisite commits" err &&
105
106 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
107 git -C clone-list-file cat-file --batch-check <oids &&
108
109 git -C clone-list-file for-each-ref --format="%(refname)" >refs &&
110 grep "refs/bundles/" refs >actual &&
111 cat >expect <<-\EOF &&
112 refs/bundles/base
113 refs/bundles/left
114 refs/bundles/merge
115 refs/bundles/right
116 EOF
117 test_cmp expect actual
118 '
119
120 test_expect_success 'clone bundle list (file, all mode, some failures)' '
121 cat >bundle-list <<-EOF &&
122 [bundle]
123 version = 1
124 mode = all
125
126 # Does not exist. Should be skipped.
127 [bundle "bundle-0"]
128 uri = file://$(pwd)/clone-from/bundle-0.bundle
129
130 [bundle "bundle-1"]
131 uri = file://$(pwd)/clone-from/bundle-1.bundle
132
133 [bundle "bundle-2"]
134 uri = file://$(pwd)/clone-from/bundle-2.bundle
135
136 # No bundle-3 means bundle-4 will not apply.
137
138 [bundle "bundle-4"]
139 uri = file://$(pwd)/clone-from/bundle-4.bundle
140
141 # Does not exist. Should be skipped.
142 [bundle "bundle-5"]
143 uri = file://$(pwd)/clone-from/bundle-5.bundle
144 EOF
145
146 GIT_TRACE2_PERF=1 \
147 git clone --bundle-uri="file://$(pwd)/bundle-list" \
148 clone-from clone-all-some 2>err &&
149 ! grep "Repository lacks these prerequisite commits" err &&
150 ! grep "fatal" err &&
151 grep "warning: failed to download bundle from URI" err &&
152
153 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
154 git -C clone-all-some cat-file --batch-check <oids &&
155
156 git -C clone-all-some for-each-ref --format="%(refname)" >refs &&
157 grep "refs/bundles/" refs >actual &&
158 cat >expect <<-\EOF &&
159 refs/bundles/base
160 refs/bundles/left
161 EOF
162 test_cmp expect actual
163 '
164
165 test_expect_success 'clone bundle list (file, all mode, all failures)' '
166 cat >bundle-list <<-EOF &&
167 [bundle]
168 version = 1
169 mode = all
170
171 # Does not exist. Should be skipped.
172 [bundle "bundle-0"]
173 uri = file://$(pwd)/clone-from/bundle-0.bundle
174
175 # Does not exist. Should be skipped.
176 [bundle "bundle-5"]
177 uri = file://$(pwd)/clone-from/bundle-5.bundle
178 EOF
179
180 git clone --bundle-uri="file://$(pwd)/bundle-list" \
181 clone-from clone-all-fail 2>err &&
182 ! grep "Repository lacks these prerequisite commits" err &&
183 ! grep "fatal" err &&
184 grep "warning: failed to download bundle from URI" err &&
185
186 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
187 git -C clone-all-fail cat-file --batch-check <oids &&
188
189 git -C clone-all-fail for-each-ref --format="%(refname)" >refs &&
190 ! grep "refs/bundles/" refs
191 '
192
193 test_expect_success 'clone bundle list (file, any mode)' '
194 cat >bundle-list <<-EOF &&
195 [bundle]
196 version = 1
197 mode = any
198
199 # Does not exist. Should be skipped.
200 [bundle "bundle-0"]
201 uri = file://$(pwd)/clone-from/bundle-0.bundle
202
203 [bundle "bundle-1"]
204 uri = file://$(pwd)/clone-from/bundle-1.bundle
205
206 # Does not exist. Should be skipped.
207 [bundle "bundle-5"]
208 uri = file://$(pwd)/clone-from/bundle-5.bundle
209 EOF
210
211 git clone --bundle-uri="file://$(pwd)/bundle-list" \
212 clone-from clone-any-file 2>err &&
213 ! grep "Repository lacks these prerequisite commits" err &&
214
215 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
216 git -C clone-any-file cat-file --batch-check <oids &&
217
218 git -C clone-any-file for-each-ref --format="%(refname)" >refs &&
219 grep "refs/bundles/" refs >actual &&
220 cat >expect <<-\EOF &&
221 refs/bundles/base
222 EOF
223 test_cmp expect actual
224 '
225
226 test_expect_success 'clone bundle list (file, any mode, all failures)' '
227 cat >bundle-list <<-EOF &&
228 [bundle]
229 version = 1
230 mode = any
231
232 # Does not exist. Should be skipped.
233 [bundle "bundle-0"]
234 uri = $HTTPD_URL/bundle-0.bundle
235
236 # Does not exist. Should be skipped.
237 [bundle "bundle-5"]
238 uri = $HTTPD_URL/bundle-5.bundle
239 EOF
240
241 git clone --bundle-uri="file://$(pwd)/bundle-list" \
242 clone-from clone-any-fail 2>err &&
243 ! grep "fatal" err &&
244 grep "warning: failed to download bundle from URI" err &&
245
246 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
247 git -C clone-any-fail cat-file --batch-check <oids &&
248
249 git -C clone-any-fail for-each-ref --format="%(refname)" >refs &&
250 ! grep "refs/bundles/" refs
251 '
252
253 #########################################################################
254 # HTTP tests begin here
255
256 . "$TEST_DIRECTORY"/lib-httpd.sh
257 start_httpd
258
259 test_expect_success 'fail to fetch from non-existent HTTP URL' '
260 test_when_finished rm -rf test &&
261 git clone --bundle-uri="$HTTPD_URL/does-not-exist" . test 2>err &&
262 grep "failed to download bundle from URI" err
263 '
264
265 test_expect_success 'fail to fetch from non-bundle HTTP URL' '
266 test_when_finished rm -rf test &&
267 echo bogus >"$HTTPD_DOCUMENT_ROOT_PATH/bogus" &&
268 git clone --bundle-uri="$HTTPD_URL/bogus" . test 2>err &&
269 grep "is not a bundle" err
270 '
271
272 test_expect_success 'clone HTTP bundle' '
273 cp clone-from/B.bundle "$HTTPD_DOCUMENT_ROOT_PATH/B.bundle" &&
274
275 git clone --no-local --mirror clone-from \
276 "$HTTPD_DOCUMENT_ROOT_PATH/fetch.git" &&
277
278 git clone --bundle-uri="$HTTPD_URL/B.bundle" \
279 "$HTTPD_URL/smart/fetch.git" clone-http &&
280 git -C clone-http rev-parse refs/bundles/topic >actual &&
281 git -C clone-from rev-parse topic >expect &&
282 test_cmp expect actual &&
283
284 test_config -C clone-http log.excludedecoration refs/bundle/
285 '
286
287 test_expect_success 'clone bundle list (HTTP, no heuristic)' '
288 cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
289 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
290 [bundle]
291 version = 1
292 mode = all
293
294 [bundle "bundle-1"]
295 uri = $HTTPD_URL/bundle-1.bundle
296
297 [bundle "bundle-2"]
298 uri = $HTTPD_URL/bundle-2.bundle
299
300 [bundle "bundle-3"]
301 uri = $HTTPD_URL/bundle-3.bundle
302
303 [bundle "bundle-4"]
304 uri = $HTTPD_URL/bundle-4.bundle
305 EOF
306
307 git clone --bundle-uri="$HTTPD_URL/bundle-list" \
308 clone-from clone-list-http 2>err &&
309 ! grep "Repository lacks these prerequisite commits" err &&
310
311 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
312 git -C clone-list-http cat-file --batch-check <oids
313 '
314
315 test_expect_success 'clone bundle list (HTTP, any mode)' '
316 cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
317 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
318 [bundle]
319 version = 1
320 mode = any
321
322 # Does not exist. Should be skipped.
323 [bundle "bundle-0"]
324 uri = $HTTPD_URL/bundle-0.bundle
325
326 [bundle "bundle-1"]
327 uri = $HTTPD_URL/bundle-1.bundle
328
329 # Does not exist. Should be skipped.
330 [bundle "bundle-5"]
331 uri = $HTTPD_URL/bundle-5.bundle
332 EOF
333
334 git clone --bundle-uri="$HTTPD_URL/bundle-list" \
335 clone-from clone-any-http 2>err &&
336 ! grep "fatal" err &&
337 grep "warning: failed to download bundle from URI" err &&
338
339 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
340 git -C clone-any-http cat-file --batch-check <oids &&
341
342 git -C clone-list-file for-each-ref --format="%(refname)" >refs &&
343 grep "refs/bundles/" refs >actual &&
344 cat >expect <<-\EOF &&
345 refs/bundles/base
346 refs/bundles/left
347 refs/bundles/merge
348 refs/bundles/right
349 EOF
350 test_cmp expect actual
351 '
352
353 # Do not add tests here unless they use the HTTP server, as they will
354 # not run unless the HTTP dependencies exist.
355
356 test_done