Merge branch 'rs/clarify-error-in-write-loose-object'
[alt-git.git] / t / t5558-clone-bundle-uri.sh
blob9155f31fa2cb58db4e09814f451ee87b63c5dfdc
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 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
294 [bundle "bundle-1"]
295 uri = $HTTPD_URL/bundle-1.bundle
297 [bundle "bundle-2"]
298 uri = $HTTPD_URL/bundle-2.bundle
300 [bundle "bundle-3"]
301 uri = $HTTPD_URL/bundle-3.bundle
303 [bundle "bundle-4"]
304 uri = $HTTPD_URL/bundle-4.bundle
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 &&
311 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
312 git -C clone-list-http cat-file --batch-check <oids
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
322 # Does not exist. Should be skipped.
323 [bundle "bundle-0"]
324 uri = $HTTPD_URL/bundle-0.bundle
326 [bundle "bundle-1"]
327 uri = $HTTPD_URL/bundle-1.bundle
329 # Does not exist. Should be skipped.
330 [bundle "bundle-5"]
331 uri = $HTTPD_URL/bundle-5.bundle
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 &&
339 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
340 git -C clone-any-http cat-file --batch-check <oids &&
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
350 test_cmp expect actual
353 # Do not add tests here unless they use the HTTP server, as they will
354 # not run unless the HTTP dependencies exist.
356 test_done