]>
Commit | Line | Data |
---|---|---|
55568919 DS |
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 | ||
59c1752a DS |
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 | ||
c23f5921 DS |
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 | ||
70334fc3 DS |
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 | ||
c23f5921 DS |
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 \ | |
70334fc3 DS |
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 | ||
c23f5921 DS |
151 | git -C clone-from for-each-ref --format="%(objectname)" >oids && |
152 | git -C clone-all-some cat-file --batch-check <oids && | |
153 | ||
154 | git -C clone-all-some for-each-ref --format="%(refname)" >refs && | |
155 | grep "refs/bundles/" refs >actual && | |
156 | cat >expect <<-\EOF && | |
157 | refs/bundles/base | |
158 | refs/bundles/left | |
159 | EOF | |
160 | test_cmp expect actual | |
161 | ' | |
162 | ||
163 | test_expect_success 'clone bundle list (file, all mode, all failures)' ' | |
164 | cat >bundle-list <<-EOF && | |
165 | [bundle] | |
166 | version = 1 | |
167 | mode = all | |
168 | ||
169 | # Does not exist. Should be skipped. | |
170 | [bundle "bundle-0"] | |
171 | uri = file://$(pwd)/clone-from/bundle-0.bundle | |
172 | ||
173 | # Does not exist. Should be skipped. | |
174 | [bundle "bundle-5"] | |
175 | uri = file://$(pwd)/clone-from/bundle-5.bundle | |
176 | EOF | |
177 | ||
70334fc3 DS |
178 | git clone --bundle-uri="file://$(pwd)/bundle-list" \ |
179 | clone-from clone-all-fail 2>err && | |
180 | ! grep "Repository lacks these prerequisite commits" err && | |
181 | ||
c23f5921 DS |
182 | git -C clone-from for-each-ref --format="%(objectname)" >oids && |
183 | git -C clone-all-fail cat-file --batch-check <oids && | |
184 | ||
185 | git -C clone-all-fail for-each-ref --format="%(refname)" >refs && | |
186 | ! grep "refs/bundles/" refs | |
187 | ' | |
188 | ||
189 | test_expect_success 'clone bundle list (file, any mode)' ' | |
190 | cat >bundle-list <<-EOF && | |
191 | [bundle] | |
192 | version = 1 | |
193 | mode = any | |
194 | ||
195 | # Does not exist. Should be skipped. | |
196 | [bundle "bundle-0"] | |
197 | uri = file://$(pwd)/clone-from/bundle-0.bundle | |
198 | ||
199 | [bundle "bundle-1"] | |
200 | uri = file://$(pwd)/clone-from/bundle-1.bundle | |
201 | ||
202 | # Does not exist. Should be skipped. | |
203 | [bundle "bundle-5"] | |
204 | uri = file://$(pwd)/clone-from/bundle-5.bundle | |
205 | EOF | |
206 | ||
70334fc3 DS |
207 | git clone --bundle-uri="file://$(pwd)/bundle-list" \ |
208 | clone-from clone-any-file 2>err && | |
209 | ! grep "Repository lacks these prerequisite commits" err && | |
210 | ||
c23f5921 DS |
211 | git -C clone-from for-each-ref --format="%(objectname)" >oids && |
212 | git -C clone-any-file cat-file --batch-check <oids && | |
213 | ||
214 | git -C clone-any-file for-each-ref --format="%(refname)" >refs && | |
215 | grep "refs/bundles/" refs >actual && | |
216 | cat >expect <<-\EOF && | |
217 | refs/bundles/base | |
218 | EOF | |
219 | test_cmp expect actual | |
220 | ' | |
221 | ||
222 | test_expect_success 'clone bundle list (file, any mode, all failures)' ' | |
223 | cat >bundle-list <<-EOF && | |
224 | [bundle] | |
225 | version = 1 | |
226 | mode = any | |
227 | ||
228 | # Does not exist. Should be skipped. | |
229 | [bundle "bundle-0"] | |
230 | uri = $HTTPD_URL/bundle-0.bundle | |
231 | ||
232 | # Does not exist. Should be skipped. | |
233 | [bundle "bundle-5"] | |
234 | uri = $HTTPD_URL/bundle-5.bundle | |
235 | EOF | |
236 | ||
237 | git clone --bundle-uri="file://$(pwd)/bundle-list" clone-from clone-any-fail && | |
238 | git -C clone-from for-each-ref --format="%(objectname)" >oids && | |
239 | git -C clone-any-fail cat-file --batch-check <oids && | |
240 | ||
241 | git -C clone-any-fail for-each-ref --format="%(refname)" >refs && | |
242 | ! grep "refs/bundles/" refs | |
243 | ' | |
244 | ||
59c1752a DS |
245 | ######################################################################### |
246 | # HTTP tests begin here | |
247 | ||
248 | . "$TEST_DIRECTORY"/lib-httpd.sh | |
249 | start_httpd | |
250 | ||
251 | test_expect_success 'fail to fetch from non-existent HTTP URL' ' | |
252 | test_when_finished rm -rf test && | |
253 | git clone --bundle-uri="$HTTPD_URL/does-not-exist" . test 2>err && | |
254 | grep "failed to download bundle from URI" err | |
255 | ' | |
256 | ||
257 | test_expect_success 'fail to fetch from non-bundle HTTP URL' ' | |
258 | test_when_finished rm -rf test && | |
259 | echo bogus >"$HTTPD_DOCUMENT_ROOT_PATH/bogus" && | |
260 | git clone --bundle-uri="$HTTPD_URL/bogus" . test 2>err && | |
261 | grep "is not a bundle" err | |
262 | ' | |
263 | ||
264 | test_expect_success 'clone HTTP bundle' ' | |
265 | cp clone-from/B.bundle "$HTTPD_DOCUMENT_ROOT_PATH/B.bundle" && | |
266 | ||
267 | git clone --no-local --mirror clone-from \ | |
268 | "$HTTPD_DOCUMENT_ROOT_PATH/fetch.git" && | |
269 | ||
270 | git clone --bundle-uri="$HTTPD_URL/B.bundle" \ | |
271 | "$HTTPD_URL/smart/fetch.git" clone-http && | |
272 | git -C clone-http rev-parse refs/bundles/topic >actual && | |
273 | git -C clone-from rev-parse topic >expect && | |
274 | test_cmp expect actual && | |
275 | ||
276 | test_config -C clone-http log.excludedecoration refs/bundle/ | |
277 | ' | |
278 | ||
c23f5921 DS |
279 | test_expect_success 'clone bundle list (HTTP, no heuristic)' ' |
280 | cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" && | |
281 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && | |
282 | [bundle] | |
283 | version = 1 | |
284 | mode = all | |
285 | ||
286 | [bundle "bundle-1"] | |
287 | uri = $HTTPD_URL/bundle-1.bundle | |
288 | ||
289 | [bundle "bundle-2"] | |
290 | uri = $HTTPD_URL/bundle-2.bundle | |
291 | ||
292 | [bundle "bundle-3"] | |
293 | uri = $HTTPD_URL/bundle-3.bundle | |
294 | ||
295 | [bundle "bundle-4"] | |
296 | uri = $HTTPD_URL/bundle-4.bundle | |
297 | EOF | |
298 | ||
70334fc3 DS |
299 | git clone --bundle-uri="$HTTPD_URL/bundle-list" \ |
300 | clone-from clone-list-http 2>err && | |
301 | ! grep "Repository lacks these prerequisite commits" err && | |
302 | ||
c23f5921 DS |
303 | git -C clone-from for-each-ref --format="%(objectname)" >oids && |
304 | git -C clone-list-http cat-file --batch-check <oids | |
305 | ' | |
306 | ||
307 | test_expect_success 'clone bundle list (HTTP, any mode)' ' | |
308 | cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" && | |
309 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && | |
310 | [bundle] | |
311 | version = 1 | |
312 | mode = any | |
313 | ||
314 | # Does not exist. Should be skipped. | |
315 | [bundle "bundle-0"] | |
316 | uri = $HTTPD_URL/bundle-0.bundle | |
317 | ||
318 | [bundle "bundle-1"] | |
319 | uri = $HTTPD_URL/bundle-1.bundle | |
320 | ||
321 | # Does not exist. Should be skipped. | |
322 | [bundle "bundle-5"] | |
323 | uri = $HTTPD_URL/bundle-5.bundle | |
324 | EOF | |
325 | ||
326 | git clone --bundle-uri="$HTTPD_URL/bundle-list" clone-from clone-any-http && | |
327 | git -C clone-from for-each-ref --format="%(objectname)" >oids && | |
328 | git -C clone-any-http cat-file --batch-check <oids && | |
329 | ||
330 | git -C clone-list-file for-each-ref --format="%(refname)" >refs && | |
331 | grep "refs/bundles/" refs >actual && | |
332 | cat >expect <<-\EOF && | |
333 | refs/bundles/base | |
334 | refs/bundles/left | |
335 | refs/bundles/merge | |
336 | refs/bundles/right | |
337 | EOF | |
338 | test_cmp expect actual | |
339 | ' | |
340 | ||
59c1752a DS |
341 | # Do not add tests here unless they use the HTTP server, as they will |
342 | # not run unless the HTTP dependencies exist. | |
343 | ||
55568919 | 344 | test_done |