3 test_description
='test fetching bundles with --bundle-uri'
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 &&
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
51 # ----|---|------- bundle-3
55 # ----|---|------- bundle-2
59 # ----|---|------- bundle-1
64 test_expect_success
'construct incremental bundle list' '
67 git checkout -b base &&
69 git checkout -b left &&
71 git checkout -b right base &&
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 &&
90 uri = file://$(pwd)/clone-from/bundle-1.bundle
93 uri = file://$(pwd)/clone-from/bundle-2.bundle
96 uri = file://$(pwd)/clone-from/bundle-3.bundle
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 &&
117 test_cmp expect actual
120 test_expect_success
'clone bundle list (file, all mode, some failures)' '
121 cat >bundle-list <<-EOF &&
126 # Does not exist. Should be skipped.
128 uri = file://$(pwd)/clone-from/bundle-0.bundle
131 uri = file://$(pwd)/clone-from/bundle-1.bundle
134 uri = file://$(pwd)/clone-from/bundle-2.bundle
136 # No bundle-3 means bundle-4 will not apply.
139 uri = file://$(pwd)/clone-from/bundle-4.bundle
141 # Does not exist. Should be skipped.
143 uri = file://$(pwd)/clone-from/bundle-5.bundle
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 &&
162 test_cmp expect actual
165 test_expect_success
'clone bundle list (file, all mode, all failures)' '
166 cat >bundle-list <<-EOF &&
171 # Does not exist. Should be skipped.
173 uri = file://$(pwd)/clone-from/bundle-0.bundle
175 # Does not exist. Should be skipped.
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 &&
199 # Does not exist. Should be skipped.
201 uri = file://$(pwd)/clone-from/bundle-0.bundle
204 uri = file://$(pwd)/clone-from/bundle-1.bundle
206 # Does not exist. Should be skipped.
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 &&
223 test_cmp expect actual
226 test_expect_success
'clone bundle list (file, any mode, all failures)' '
227 cat >bundle-list <<-EOF &&
232 # Does not exist. Should be skipped.
234 uri = $HTTPD_URL/bundle-0.bundle
236 # Does not exist. Should be skipped.
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
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 &&
295 uri = $HTTPD_URL/bundle-1.bundle
298 uri = $HTTPD_URL/bundle-2.bundle
301 uri = $HTTPD_URL/bundle-3.bundle
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 &&
322 # Does not exist. Should be skipped.
324 uri = $HTTPD_URL/bundle-0.bundle
327 uri = $HTTPD_URL/bundle-1.bundle
329 # Does not exist. Should be skipped.
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 &&
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.