]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0410-partial-clone.sh
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / t / t0410-partial-clone.sh
1 #!/bin/sh
2
3 test_description='partial clone'
4
5 . ./test-lib.sh
6
7 # missing promisor objects cause repacks which write bitmaps to fail
8 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0
9 # When enabled, some commands will write commit-graphs. This causes fsck
10 # to fail when delete_object() is called because fsck will attempt to
11 # verify the out-of-sync commit graph.
12 GIT_TEST_COMMIT_GRAPH=0
13
14 delete_object () {
15 rm $1/.git/objects/$(echo $2 | sed -e 's|^..|&/|')
16 }
17
18 pack_as_from_promisor () {
19 HASH=$(git -C repo pack-objects .git/objects/pack/pack) &&
20 >repo/.git/objects/pack/pack-$HASH.promisor &&
21 echo $HASH
22 }
23
24 promise_and_delete () {
25 HASH=$(git -C repo rev-parse "$1") &&
26 git -C repo tag -a -m message my_annotated_tag "$HASH" &&
27 git -C repo rev-parse my_annotated_tag | pack_as_from_promisor &&
28 # tag -d prints a message to stdout, so redirect it
29 git -C repo tag -d my_annotated_tag >/dev/null &&
30 delete_object repo "$HASH"
31 }
32
33 test_expect_success 'extensions.partialclone without filter' '
34 test_create_repo server &&
35 git clone --filter="blob:none" "file://$(pwd)/server" client &&
36 git -C client config --unset remote.origin.partialclonefilter &&
37 git -C client fetch origin
38 '
39
40 test_expect_success 'convert shallow clone to partial clone' '
41 rm -fr server client &&
42 test_create_repo server &&
43 test_commit -C server my_commit 1 &&
44 test_commit -C server my_commit2 1 &&
45 git clone --depth=1 "file://$(pwd)/server" client &&
46 git -C client fetch --unshallow --filter="blob:none" &&
47 test_cmp_config -C client true remote.origin.promisor &&
48 test_cmp_config -C client blob:none remote.origin.partialclonefilter &&
49 test_cmp_config -C client 1 core.repositoryformatversion
50 '
51
52 test_expect_success SHA1 'convert to partial clone with noop extension' '
53 rm -fr server client &&
54 test_create_repo server &&
55 test_commit -C server my_commit 1 &&
56 test_commit -C server my_commit2 1 &&
57 git clone --depth=1 "file://$(pwd)/server" client &&
58 test_cmp_config -C client 0 core.repositoryformatversion &&
59 git -C client config extensions.noop true &&
60 git -C client fetch --unshallow --filter="blob:none"
61 '
62
63 test_expect_success SHA1 'converting to partial clone fails with unrecognized extension' '
64 rm -fr server client &&
65 test_create_repo server &&
66 test_commit -C server my_commit 1 &&
67 test_commit -C server my_commit2 1 &&
68 git clone --depth=1 "file://$(pwd)/server" client &&
69 test_cmp_config -C client 0 core.repositoryformatversion &&
70 git -C client config extensions.nonsense true &&
71 test_must_fail git -C client fetch --unshallow --filter="blob:none"
72 '
73
74 test_expect_success 'missing reflog object, but promised by a commit, passes fsck' '
75 rm -rf repo &&
76 test_create_repo repo &&
77 test_commit -C repo my_commit &&
78
79 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
80 C=$(git -C repo commit-tree -m c -p $A HEAD^{tree}) &&
81
82 # Reference $A only from reflog, and delete it
83 git -C repo branch my_branch "$A" &&
84 git -C repo branch -f my_branch my_commit &&
85 delete_object repo "$A" &&
86
87 # State that we got $C, which refers to $A, from promisor
88 printf "$C\n" | pack_as_from_promisor &&
89
90 # Normally, it fails
91 test_must_fail git -C repo fsck &&
92
93 # But with the extension, it succeeds
94 git -C repo config core.repositoryformatversion 1 &&
95 git -C repo config extensions.partialclone "arbitrary string" &&
96 git -C repo fsck
97 '
98
99 test_expect_success 'missing reflog object, but promised by a tag, passes fsck' '
100 rm -rf repo &&
101 test_create_repo repo &&
102 test_commit -C repo my_commit &&
103
104 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
105 git -C repo tag -a -m d my_tag_name $A &&
106 T=$(git -C repo rev-parse my_tag_name) &&
107 git -C repo tag -d my_tag_name &&
108
109 # Reference $A only from reflog, and delete it
110 git -C repo branch my_branch "$A" &&
111 git -C repo branch -f my_branch my_commit &&
112 delete_object repo "$A" &&
113
114 # State that we got $T, which refers to $A, from promisor
115 printf "$T\n" | pack_as_from_promisor &&
116
117 git -C repo config core.repositoryformatversion 1 &&
118 git -C repo config extensions.partialclone "arbitrary string" &&
119 git -C repo fsck
120 '
121
122 test_expect_success 'missing reflog object alone fails fsck, even with extension set' '
123 rm -rf repo &&
124 test_create_repo repo &&
125 test_commit -C repo my_commit &&
126
127 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
128 B=$(git -C repo commit-tree -m b HEAD^{tree}) &&
129
130 # Reference $A only from reflog, and delete it
131 git -C repo branch my_branch "$A" &&
132 git -C repo branch -f my_branch my_commit &&
133 delete_object repo "$A" &&
134
135 git -C repo config core.repositoryformatversion 1 &&
136 git -C repo config extensions.partialclone "arbitrary string" &&
137 test_must_fail git -C repo fsck
138 '
139
140 test_expect_success 'missing ref object, but promised, passes fsck' '
141 rm -rf repo &&
142 test_create_repo repo &&
143 test_commit -C repo my_commit &&
144
145 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
146
147 # Reference $A only from ref
148 git -C repo branch my_branch "$A" &&
149 promise_and_delete "$A" &&
150
151 git -C repo config core.repositoryformatversion 1 &&
152 git -C repo config extensions.partialclone "arbitrary string" &&
153 git -C repo fsck
154 '
155
156 test_expect_success 'missing object, but promised, passes fsck' '
157 rm -rf repo &&
158 test_create_repo repo &&
159 test_commit -C repo 1 &&
160 test_commit -C repo 2 &&
161 test_commit -C repo 3 &&
162 git -C repo tag -a annotated_tag -m "annotated tag" &&
163
164 C=$(git -C repo rev-parse 1) &&
165 T=$(git -C repo rev-parse 2^{tree}) &&
166 B=$(git hash-object repo/3.t) &&
167 AT=$(git -C repo rev-parse annotated_tag) &&
168
169 promise_and_delete "$C" &&
170 promise_and_delete "$T" &&
171 promise_and_delete "$B" &&
172 promise_and_delete "$AT" &&
173
174 git -C repo config core.repositoryformatversion 1 &&
175 git -C repo config extensions.partialclone "arbitrary string" &&
176 git -C repo fsck
177 '
178
179 test_expect_success 'missing CLI object, but promised, passes fsck' '
180 rm -rf repo &&
181 test_create_repo repo &&
182 test_commit -C repo my_commit &&
183
184 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
185 promise_and_delete "$A" &&
186
187 git -C repo config core.repositoryformatversion 1 &&
188 git -C repo config extensions.partialclone "arbitrary string" &&
189 git -C repo fsck "$A"
190 '
191
192 test_expect_success 'fetching of missing objects' '
193 rm -rf repo err &&
194 test_create_repo server &&
195 test_commit -C server foo &&
196 git -C server repack -a -d --write-bitmap-index &&
197
198 git clone "file://$(pwd)/server" repo &&
199 HASH=$(git -C repo rev-parse foo) &&
200 rm -rf repo/.git/objects/* &&
201
202 git -C repo config core.repositoryformatversion 1 &&
203 git -C repo config extensions.partialclone "origin" &&
204 git -C repo cat-file -p "$HASH" 2>err &&
205
206 # Ensure that no spurious FETCH_HEAD messages are written
207 ! grep FETCH_HEAD err &&
208
209 # Ensure that the .promisor file is written, and check that its
210 # associated packfile contains the object
211 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
212 test_line_count = 1 promisorlist &&
213 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
214 git verify-pack --verbose "$IDX" >out &&
215 grep "$HASH" out
216 '
217
218 test_expect_success 'fetching of missing objects works with ref-in-want enabled' '
219 # ref-in-want requires protocol version 2
220 git -C server config protocol.version 2 &&
221 git -C server config uploadpack.allowrefinwant 1 &&
222 git -C repo config protocol.version 2 &&
223
224 rm -rf repo/.git/objects/* &&
225 rm -f trace &&
226 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" &&
227 grep "fetch< fetch=.*ref-in-want" trace
228 '
229
230 test_expect_success 'fetching of missing objects from another promisor remote' '
231 git clone "file://$(pwd)/server" server2 &&
232 test_commit -C server2 bar &&
233 git -C server2 repack -a -d --write-bitmap-index &&
234 HASH2=$(git -C server2 rev-parse bar) &&
235
236 git -C repo remote add server2 "file://$(pwd)/server2" &&
237 git -C repo config remote.server2.promisor true &&
238 git -C repo cat-file -p "$HASH2" &&
239
240 git -C repo fetch server2 &&
241 rm -rf repo/.git/objects/* &&
242 git -C repo cat-file -p "$HASH2" &&
243
244 # Ensure that the .promisor file is written, and check that its
245 # associated packfile contains the object
246 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
247 test_line_count = 1 promisorlist &&
248 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
249 git verify-pack --verbose "$IDX" >out &&
250 grep "$HASH2" out
251 '
252
253 test_expect_success 'fetching of missing objects configures a promisor remote' '
254 git clone "file://$(pwd)/server" server3 &&
255 test_commit -C server3 baz &&
256 git -C server3 repack -a -d --write-bitmap-index &&
257 HASH3=$(git -C server3 rev-parse baz) &&
258 git -C server3 config uploadpack.allowfilter 1 &&
259
260 rm repo/.git/objects/pack/pack-*.promisor &&
261
262 git -C repo remote add server3 "file://$(pwd)/server3" &&
263 git -C repo fetch --filter="blob:none" server3 $HASH3 &&
264
265 test_cmp_config -C repo true remote.server3.promisor &&
266
267 # Ensure that the .promisor file is written, and check that its
268 # associated packfile contains the object
269 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
270 test_line_count = 1 promisorlist &&
271 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
272 git verify-pack --verbose "$IDX" >out &&
273 grep "$HASH3" out
274 '
275
276 test_expect_success 'fetching of missing blobs works' '
277 rm -rf server server2 repo &&
278 rm -rf server server3 repo &&
279 test_create_repo server &&
280 test_commit -C server foo &&
281 git -C server repack -a -d --write-bitmap-index &&
282
283 git clone "file://$(pwd)/server" repo &&
284 git hash-object repo/foo.t >blobhash &&
285 rm -rf repo/.git/objects/* &&
286
287 git -C server config uploadpack.allowanysha1inwant 1 &&
288 git -C server config uploadpack.allowfilter 1 &&
289 git -C repo config core.repositoryformatversion 1 &&
290 git -C repo config extensions.partialclone "origin" &&
291
292 git -C repo cat-file -p $(cat blobhash)
293 '
294
295 test_expect_success 'fetching of missing trees does not fetch blobs' '
296 rm -rf server repo &&
297 test_create_repo server &&
298 test_commit -C server foo &&
299 git -C server repack -a -d --write-bitmap-index &&
300
301 git clone "file://$(pwd)/server" repo &&
302 git -C repo rev-parse foo^{tree} >treehash &&
303 git hash-object repo/foo.t >blobhash &&
304 rm -rf repo/.git/objects/* &&
305
306 git -C server config uploadpack.allowanysha1inwant 1 &&
307 git -C server config uploadpack.allowfilter 1 &&
308 git -C repo config core.repositoryformatversion 1 &&
309 git -C repo config extensions.partialclone "origin" &&
310 git -C repo cat-file -p $(cat treehash) &&
311
312 # Ensure that the tree, but not the blob, is fetched
313 git -C repo rev-list --objects --missing=print $(cat treehash) >objects &&
314 grep "^$(cat treehash)" objects &&
315 grep "^[?]$(cat blobhash)" objects
316 '
317
318 test_expect_success 'rev-list stops traversal at missing and promised commit' '
319 rm -rf repo &&
320 test_create_repo repo &&
321 test_commit -C repo foo &&
322 test_commit -C repo bar &&
323
324 FOO=$(git -C repo rev-parse foo) &&
325 promise_and_delete "$FOO" &&
326
327 git -C repo config core.repositoryformatversion 1 &&
328 git -C repo config extensions.partialclone "arbitrary string" &&
329 git -C repo rev-list --exclude-promisor-objects --objects bar >out &&
330 grep $(git -C repo rev-parse bar) out &&
331 ! grep $FOO out
332 '
333
334 test_expect_success 'missing tree objects with --missing=allow-promisor and --exclude-promisor-objects' '
335 rm -rf repo &&
336 test_create_repo repo &&
337 test_commit -C repo foo &&
338 test_commit -C repo bar &&
339 test_commit -C repo baz &&
340
341 promise_and_delete $(git -C repo rev-parse bar^{tree}) &&
342 promise_and_delete $(git -C repo rev-parse foo^{tree}) &&
343
344 git -C repo config core.repositoryformatversion 1 &&
345 git -C repo config extensions.partialclone "arbitrary string" &&
346
347 git -C repo rev-list --missing=allow-promisor --objects HEAD >objs 2>rev_list_err &&
348 test_must_be_empty rev_list_err &&
349 # 3 commits, 3 blobs, and 1 tree
350 test_line_count = 7 objs &&
351
352 # Do the same for --exclude-promisor-objects, but with all trees gone.
353 promise_and_delete $(git -C repo rev-parse baz^{tree}) &&
354 git -C repo rev-list --exclude-promisor-objects --objects HEAD >objs 2>rev_list_err &&
355 test_must_be_empty rev_list_err &&
356 # 3 commits, no blobs or trees
357 test_line_count = 3 objs
358 '
359
360 test_expect_success 'missing non-root tree object and rev-list' '
361 rm -rf repo &&
362 test_create_repo repo &&
363 mkdir repo/dir &&
364 echo foo >repo/dir/foo &&
365 git -C repo add dir/foo &&
366 git -C repo commit -m "commit dir/foo" &&
367
368 promise_and_delete $(git -C repo rev-parse HEAD:dir) &&
369
370 git -C repo config core.repositoryformatversion 1 &&
371 git -C repo config extensions.partialclone "arbitrary string" &&
372
373 git -C repo rev-list --missing=allow-any --objects HEAD >objs 2>rev_list_err &&
374 test_must_be_empty rev_list_err &&
375 # 1 commit and 1 tree
376 test_line_count = 2 objs
377 '
378
379 test_expect_success 'rev-list stops traversal at missing and promised tree' '
380 rm -rf repo &&
381 test_create_repo repo &&
382 test_commit -C repo foo &&
383 mkdir repo/a_dir &&
384 echo something >repo/a_dir/something &&
385 git -C repo add a_dir/something &&
386 git -C repo commit -m bar &&
387
388 # foo^{tree} (tree referenced from commit)
389 TREE=$(git -C repo rev-parse foo^{tree}) &&
390
391 # a tree referenced by HEAD^{tree} (tree referenced from tree)
392 TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) &&
393
394 promise_and_delete "$TREE" &&
395 promise_and_delete "$TREE2" &&
396
397 git -C repo config core.repositoryformatversion 1 &&
398 git -C repo config extensions.partialclone "arbitrary string" &&
399 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
400 grep $(git -C repo rev-parse foo) out &&
401 ! grep $TREE out &&
402 grep $(git -C repo rev-parse HEAD) out &&
403 ! grep $TREE2 out
404 '
405
406 test_expect_success 'rev-list stops traversal at missing and promised blob' '
407 rm -rf repo &&
408 test_create_repo repo &&
409 echo something >repo/something &&
410 git -C repo add something &&
411 git -C repo commit -m foo &&
412
413 BLOB=$(git -C repo hash-object -w something) &&
414 promise_and_delete "$BLOB" &&
415
416 git -C repo config core.repositoryformatversion 1 &&
417 git -C repo config extensions.partialclone "arbitrary string" &&
418 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
419 grep $(git -C repo rev-parse HEAD) out &&
420 ! grep $BLOB out
421 '
422
423 test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' '
424 rm -rf repo &&
425 test_create_repo repo &&
426 test_commit -C repo foo &&
427 test_commit -C repo bar &&
428 test_commit -C repo baz &&
429
430 COMMIT=$(git -C repo rev-parse foo) &&
431 TREE=$(git -C repo rev-parse bar^{tree}) &&
432 BLOB=$(git hash-object repo/baz.t) &&
433 printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor &&
434
435 git -C repo config core.repositoryformatversion 1 &&
436 git -C repo config extensions.partialclone "arbitrary string" &&
437 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
438 ! grep $COMMIT out &&
439 ! grep $TREE out &&
440 ! grep $BLOB out &&
441 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done
442 '
443
444 test_expect_success 'rev-list dies for missing objects on cmd line' '
445 rm -rf repo &&
446 test_create_repo repo &&
447 test_commit -C repo foo &&
448 test_commit -C repo bar &&
449 test_commit -C repo baz &&
450
451 COMMIT=$(git -C repo rev-parse foo) &&
452 TREE=$(git -C repo rev-parse bar^{tree}) &&
453 BLOB=$(git hash-object repo/baz.t) &&
454
455 promise_and_delete $COMMIT &&
456 promise_and_delete $TREE &&
457 promise_and_delete $BLOB &&
458
459 git -C repo config core.repositoryformatversion 1 &&
460 git -C repo config extensions.partialclone "arbitrary string" &&
461
462 for OBJ in "$COMMIT" "$TREE" "$BLOB"; do
463 test_must_fail git -C repo rev-list --objects \
464 --exclude-promisor-objects "$OBJ" &&
465 test_must_fail git -C repo rev-list --objects-edge-aggressive \
466 --exclude-promisor-objects "$OBJ" &&
467
468 # Do not die or crash when --ignore-missing is passed.
469 git -C repo rev-list --ignore-missing --objects \
470 --exclude-promisor-objects "$OBJ" &&
471 git -C repo rev-list --ignore-missing --objects-edge-aggressive \
472 --exclude-promisor-objects "$OBJ" || return 1
473 done
474 '
475
476 test_expect_success 'single promisor remote can be re-initialized gracefully' '
477 # ensure one promisor is in the promisors list
478 rm -rf repo &&
479 test_create_repo repo &&
480 test_create_repo other &&
481 git -C repo remote add foo "file://$(pwd)/other" &&
482 git -C repo config remote.foo.promisor true &&
483 git -C repo config extensions.partialclone foo &&
484
485 # reinitialize the promisors list
486 git -C repo fetch --filter=blob:none foo
487 '
488
489 test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
490 rm -rf repo &&
491 test_create_repo repo &&
492 test_commit -C repo one &&
493 test_commit -C repo two &&
494
495 TREE_ONE=$(git -C repo rev-parse one^{tree}) &&
496 printf "$TREE_ONE\n" | pack_as_from_promisor &&
497 TREE_TWO=$(git -C repo rev-parse two^{tree}) &&
498 printf "$TREE_TWO\n" | pack_as_from_promisor &&
499
500 git -C repo config core.repositoryformatversion 1 &&
501 git -C repo config extensions.partialclone "arbitrary string" &&
502 git -C repo gc &&
503
504 # Ensure that exactly one promisor packfile exists, and that it
505 # contains the trees but not the commits
506 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
507 test_line_count = 1 promisorlist &&
508 PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) &&
509 git verify-pack $PROMISOR_PACKFILE -v >out &&
510 grep "$TREE_ONE" out &&
511 grep "$TREE_TWO" out &&
512 ! grep "$(git -C repo rev-parse one)" out &&
513 ! grep "$(git -C repo rev-parse two)" out &&
514
515 # Remove the promisor packfile and associated files
516 rm $(sed "s/.promisor//" <promisorlist).* &&
517
518 # Ensure that the single other pack contains the commits, but not the
519 # trees
520 ls repo/.git/objects/pack/pack-*.pack >packlist &&
521 test_line_count = 1 packlist &&
522 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
523 grep "$(git -C repo rev-parse one)" out &&
524 grep "$(git -C repo rev-parse two)" out &&
525 ! grep "$TREE_ONE" out &&
526 ! grep "$TREE_TWO" out
527 '
528
529 test_expect_success 'gc does not repack promisor objects if there are none' '
530 rm -rf repo &&
531 test_create_repo repo &&
532 test_commit -C repo one &&
533
534 git -C repo config core.repositoryformatversion 1 &&
535 git -C repo config extensions.partialclone "arbitrary string" &&
536 git -C repo gc &&
537
538 # Ensure that only one pack exists
539 ls repo/.git/objects/pack/pack-*.pack >packlist &&
540 test_line_count = 1 packlist
541 '
542
543 repack_and_check () {
544 rm -rf repo2 &&
545 cp -r repo repo2 &&
546 if test x"$1" = "x--must-fail"
547 then
548 shift
549 test_must_fail git -C repo2 repack $1 -d
550 else
551 git -C repo2 repack $1 -d
552 fi &&
553 git -C repo2 fsck &&
554
555 git -C repo2 cat-file -e $2 &&
556 git -C repo2 cat-file -e $3
557 }
558
559 test_expect_success 'repack -d does not irreversibly delete promisor objects' '
560 rm -rf repo &&
561 test_create_repo repo &&
562 git -C repo config core.repositoryformatversion 1 &&
563 git -C repo config extensions.partialclone "arbitrary string" &&
564
565 git -C repo commit --allow-empty -m one &&
566 git -C repo commit --allow-empty -m two &&
567 git -C repo commit --allow-empty -m three &&
568 git -C repo commit --allow-empty -m four &&
569 ONE=$(git -C repo rev-parse HEAD^^^) &&
570 TWO=$(git -C repo rev-parse HEAD^^) &&
571 THREE=$(git -C repo rev-parse HEAD^) &&
572
573 printf "$TWO\n" | pack_as_from_promisor &&
574 printf "$THREE\n" | pack_as_from_promisor &&
575 delete_object repo "$ONE" &&
576
577 repack_and_check --must-fail -ab "$TWO" "$THREE" &&
578 repack_and_check -a "$TWO" "$THREE" &&
579 repack_and_check -A "$TWO" "$THREE" &&
580 repack_and_check -l "$TWO" "$THREE"
581 '
582
583 test_expect_success 'gc stops traversal when a missing but promised object is reached' '
584 rm -rf repo &&
585 test_create_repo repo &&
586 test_commit -C repo my_commit &&
587
588 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
589 HASH=$(promise_and_delete $TREE_HASH) &&
590
591 git -C repo config core.repositoryformatversion 1 &&
592 git -C repo config extensions.partialclone "arbitrary string" &&
593 git -C repo gc &&
594
595 # Ensure that the promisor packfile still exists, and remove it
596 test -e repo/.git/objects/pack/pack-$HASH.pack &&
597 rm repo/.git/objects/pack/pack-$HASH.* &&
598
599 # Ensure that the single other pack contains the commit, but not the tree
600 ls repo/.git/objects/pack/pack-*.pack >packlist &&
601 test_line_count = 1 packlist &&
602 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
603 grep "$(git -C repo rev-parse HEAD)" out &&
604 ! grep "$TREE_HASH" out
605 '
606
607 test_expect_success 'do not fetch when checking existence of tree we construct ourselves' '
608 rm -rf repo &&
609 test_create_repo repo &&
610 test_commit -C repo base &&
611 test_commit -C repo side1 &&
612 git -C repo checkout base &&
613 test_commit -C repo side2 &&
614
615 git -C repo config core.repositoryformatversion 1 &&
616 git -C repo config extensions.partialclone "arbitrary string" &&
617
618 git -C repo cherry-pick side1
619 '
620
621 test_expect_success 'lazy-fetch when accessing object not in the_repository' '
622 rm -rf full partial.git &&
623 test_create_repo full &&
624 test_commit -C full create-a-file file.txt &&
625
626 test_config -C full uploadpack.allowfilter 1 &&
627 test_config -C full uploadpack.allowanysha1inwant 1 &&
628 git clone --filter=blob:none --bare "file://$(pwd)/full" partial.git &&
629 FILE_HASH=$(git -C full rev-parse HEAD:file.txt) &&
630
631 # Sanity check that the file is missing
632 git -C partial.git rev-list --objects --missing=print HEAD >out &&
633 grep "[?]$FILE_HASH" out &&
634
635 git -C full cat-file -s "$FILE_HASH" >expect &&
636 test-tool partial-clone object-info partial.git "$FILE_HASH" >actual &&
637 test_cmp expect actual &&
638
639 # Sanity check that the file is now present
640 git -C partial.git rev-list --objects --missing=print HEAD >out &&
641 ! grep "[?]$FILE_HASH" out
642 '
643
644 . "$TEST_DIRECTORY"/lib-httpd.sh
645 start_httpd
646
647 test_expect_success 'fetching of missing objects from an HTTP server' '
648 rm -rf repo &&
649 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
650 test_create_repo "$SERVER" &&
651 test_commit -C "$SERVER" foo &&
652 git -C "$SERVER" repack -a -d --write-bitmap-index &&
653
654 git clone $HTTPD_URL/smart/server repo &&
655 HASH=$(git -C repo rev-parse foo) &&
656 rm -rf repo/.git/objects/* &&
657
658 git -C repo config core.repositoryformatversion 1 &&
659 git -C repo config extensions.partialclone "origin" &&
660 git -C repo cat-file -p "$HASH" &&
661
662 # Ensure that the .promisor file is written, and check that its
663 # associated packfile contains the object
664 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
665 test_line_count = 1 promisorlist &&
666 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
667 git verify-pack --verbose "$IDX" >out &&
668 grep "$HASH" out
669 '
670
671 # DO NOT add non-httpd-specific tests here, because the last part of this
672 # test script is only executed when httpd is available and enabled.
673
674 test_done