clone: set fetch.bundleURI if appropriate
[git/debian.git] / t / t5558-clone-bundle-uri.sh
blobb2d15e141ca0f7096c795a26947fb23b83063308
1 #!/bin/sh
3 test_description='test fetching bundles with --bundle-uri'
5 . ./test-lib.sh
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
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
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
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
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
44 # To get interesting tests for bundle lists, we need to construct a
45 # somewhat-interesting commit history.
47 # ---------------- bundle-4
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' '
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" &&
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
83 test_expect_success 'clone bundle list (file, no heuristic)' '
84 cat >bundle-list <<-EOF &&
85 [bundle]
86 version = 1
87 mode = all
89 [bundle "bundle-1"]
90 uri = file://$(pwd)/clone-from/bundle-1.bundle
92 [bundle "bundle-2"]
93 uri = file://$(pwd)/clone-from/bundle-2.bundle
95 [bundle "bundle-3"]
96 uri = file://$(pwd)/clone-from/bundle-3.bundle
98 [bundle "bundle-4"]
99 uri = file://$(pwd)/clone-from/bundle-4.bundle
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 &&
106 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
107 git -C clone-list-file cat-file --batch-check <oids &&
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
117 test_cmp expect actual
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
126 # Does not exist. Should be skipped.
127 [bundle "bundle-0"]
128 uri = file://$(pwd)/clone-from/bundle-0.bundle
130 [bundle "bundle-1"]
131 uri = file://$(pwd)/clone-from/bundle-1.bundle
133 [bundle "bundle-2"]
134 uri = file://$(pwd)/clone-from/bundle-2.bundle
136 # No bundle-3 means bundle-4 will not apply.
138 [bundle "bundle-4"]
139 uri = file://$(pwd)/clone-from/bundle-4.bundle
141 # Does not exist. Should be skipped.
142 [bundle "bundle-5"]
143 uri = file://$(pwd)/clone-from/bundle-5.bundle
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 &&
153 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
154 git -C clone-all-some cat-file --batch-check <oids &&
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
162 test_cmp expect actual
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
171 # Does not exist. Should be skipped.
172 [bundle "bundle-0"]
173 uri = file://$(pwd)/clone-from/bundle-0.bundle
175 # Does not exist. Should be skipped.
176 [bundle "bundle-5"]
177 uri = file://$(pwd)/clone-from/bundle-5.bundle
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 &&
186 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
187 git -C clone-all-fail cat-file --batch-check <oids &&
189 git -C clone-all-fail for-each-ref --format="%(refname)" >refs &&
190 ! grep "refs/bundles/" refs
193 test_expect_success 'clone bundle list (file, any mode)' '
194 cat >bundle-list <<-EOF &&
195 [bundle]
196 version = 1
197 mode = any
199 # Does not exist. Should be skipped.
200 [bundle "bundle-0"]
201 uri = file://$(pwd)/clone-from/bundle-0.bundle
203 [bundle "bundle-1"]
204 uri = file://$(pwd)/clone-from/bundle-1.bundle
206 # Does not exist. Should be skipped.
207 [bundle "bundle-5"]
208 uri = file://$(pwd)/clone-from/bundle-5.bundle
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 &&
215 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
216 git -C clone-any-file cat-file --batch-check <oids &&
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
223 test_cmp expect actual
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
232 # Does not exist. Should be skipped.
233 [bundle "bundle-0"]
234 uri = $HTTPD_URL/bundle-0.bundle
236 # Does not exist. Should be skipped.
237 [bundle "bundle-5"]
238 uri = $HTTPD_URL/bundle-5.bundle
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 &&
246 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
247 git -C clone-any-fail cat-file --batch-check <oids &&
249 git -C clone-any-fail for-each-ref --format="%(refname)" >refs &&
250 ! grep "refs/bundles/" refs
253 #########################################################################
254 # HTTP tests begin here
256 . "$TEST_DIRECTORY"/lib-httpd.sh
257 start_httpd
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
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
272 test_expect_success 'clone HTTP bundle' '
273 cp clone-from/B.bundle "$HTTPD_DOCUMENT_ROOT_PATH/B.bundle" &&
275 git clone --no-local --mirror clone-from \
276 "$HTTPD_DOCUMENT_ROOT_PATH/fetch.git" &&
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 &&
284 test_config -C clone-http log.excludedecoration refs/bundle/
287 test_expect_success 'clone bundle list (HTTP, no heuristic)' '
288 test_when_finished rm -f trace*.txt &&
290 cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
291 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
292 [bundle]
293 version = 1
294 mode = all
296 [bundle "bundle-1"]
297 uri = $HTTPD_URL/bundle-1.bundle
299 [bundle "bundle-2"]
300 uri = $HTTPD_URL/bundle-2.bundle
302 [bundle "bundle-3"]
303 uri = $HTTPD_URL/bundle-3.bundle
305 [bundle "bundle-4"]
306 uri = $HTTPD_URL/bundle-4.bundle
309 GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" \
310 git clone --bundle-uri="$HTTPD_URL/bundle-list" \
311 clone-from clone-list-http 2>err &&
312 ! grep "Repository lacks these prerequisite commits" err &&
314 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
315 git -C clone-list-http cat-file --batch-check <oids &&
317 cat >expect <<-EOF &&
318 $HTTPD_URL/bundle-1.bundle
319 $HTTPD_URL/bundle-2.bundle
320 $HTTPD_URL/bundle-3.bundle
321 $HTTPD_URL/bundle-4.bundle
322 $HTTPD_URL/bundle-list
325 # Sort the list, since the order is not well-defined
326 # without a heuristic.
327 test_remote_https_urls <trace-clone.txt | sort >actual &&
328 test_cmp expect actual
331 test_expect_success 'clone bundle list (HTTP, any mode)' '
332 cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
333 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
334 [bundle]
335 version = 1
336 mode = any
338 # Does not exist. Should be skipped.
339 [bundle "bundle-0"]
340 uri = $HTTPD_URL/bundle-0.bundle
342 [bundle "bundle-1"]
343 uri = $HTTPD_URL/bundle-1.bundle
345 # Does not exist. Should be skipped.
346 [bundle "bundle-5"]
347 uri = $HTTPD_URL/bundle-5.bundle
350 git clone --bundle-uri="$HTTPD_URL/bundle-list" \
351 clone-from clone-any-http 2>err &&
352 ! grep "fatal" err &&
353 grep "warning: failed to download bundle from URI" err &&
355 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
356 git -C clone-any-http cat-file --batch-check <oids &&
358 git -C clone-list-file for-each-ref --format="%(refname)" >refs &&
359 grep "refs/bundles/" refs >actual &&
360 cat >expect <<-\EOF &&
361 refs/bundles/base
362 refs/bundles/left
363 refs/bundles/merge
364 refs/bundles/right
366 test_cmp expect actual
369 test_expect_success 'clone bundle list (http, creationToken)' '
370 test_when_finished rm -f trace*.txt &&
372 cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
373 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
374 [bundle]
375 version = 1
376 mode = all
377 heuristic = creationToken
379 [bundle "bundle-1"]
380 uri = bundle-1.bundle
381 creationToken = 1
383 [bundle "bundle-2"]
384 uri = bundle-2.bundle
385 creationToken = 2
387 [bundle "bundle-3"]
388 uri = bundle-3.bundle
389 creationToken = 3
391 [bundle "bundle-4"]
392 uri = bundle-4.bundle
393 creationToken = 4
396 GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" git \
397 clone --bundle-uri="$HTTPD_URL/bundle-list" \
398 "$HTTPD_URL/smart/fetch.git" clone-list-http-2 &&
400 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
401 git -C clone-list-http-2 cat-file --batch-check <oids &&
403 cat >expect <<-EOF &&
404 $HTTPD_URL/bundle-list
405 $HTTPD_URL/bundle-4.bundle
406 $HTTPD_URL/bundle-3.bundle
407 $HTTPD_URL/bundle-2.bundle
408 $HTTPD_URL/bundle-1.bundle
411 test_remote_https_urls <trace-clone.txt >actual &&
412 test_cmp expect actual
415 test_expect_success 'clone incomplete bundle list (http, creationToken)' '
416 test_when_finished rm -f trace*.txt &&
418 cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
419 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
420 [bundle]
421 version = 1
422 mode = all
423 heuristic = creationToken
425 [bundle "bundle-1"]
426 uri = bundle-1.bundle
427 creationToken = 1
430 GIT_TRACE2_EVENT=$(pwd)/trace-clone.txt \
431 git clone --bundle-uri="$HTTPD_URL/bundle-list" \
432 --single-branch --branch=base --no-tags \
433 "$HTTPD_URL/smart/fetch.git" clone-token-http &&
435 test_cmp_config -C clone-token-http "$HTTPD_URL/bundle-list" fetch.bundleuri &&
437 cat >expect <<-EOF &&
438 $HTTPD_URL/bundle-list
439 $HTTPD_URL/bundle-1.bundle
442 test_remote_https_urls <trace-clone.txt >actual &&
443 test_cmp expect actual
446 test_expect_success 'http clone with bundle.heuristic creates fetch.bundleURI' '
447 test_when_finished rm -rf fetch-http-4 trace*.txt &&
449 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
450 [bundle]
451 version = 1
452 mode = all
453 heuristic = creationToken
455 [bundle "bundle-1"]
456 uri = bundle-1.bundle
457 creationToken = 1
460 GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" \
461 git clone --single-branch --branch=base \
462 --bundle-uri="$HTTPD_URL/bundle-list" \
463 "$HTTPD_URL/smart/fetch.git" fetch-http-4 &&
465 test_cmp_config -C fetch-http-4 "$HTTPD_URL/bundle-list" fetch.bundleuri &&
467 cat >expect <<-EOF &&
468 $HTTPD_URL/bundle-list
469 $HTTPD_URL/bundle-1.bundle
472 test_remote_https_urls <trace-clone.txt >actual &&
473 test_cmp expect actual &&
475 # only received base ref from bundle-1
476 git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
477 cat >expect <<-\EOF &&
478 refs/bundles/base
480 test_cmp expect refs
483 # Do not add tests here unless they use the HTTP server, as they will
484 # not run unless the HTTP dependencies exist.
486 test_done