Git 2.46-rc0
[git/gitster.git] / t / t0410-partial-clone.sh
blob2c30c86e7bff138154f8c0771fba078eaa9745a3
1 #!/bin/sh
3 test_description='partial clone'
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-terminal.sh
8 # missing promisor objects cause repacks which write bitmaps to fail
9 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0
10 # When enabled, some commands will write commit-graphs. This causes fsck
11 # to fail when delete_object() is called because fsck will attempt to
12 # verify the out-of-sync commit graph.
13 GIT_TEST_COMMIT_GRAPH=0
15 delete_object () {
16 rm $1/.git/objects/$(echo $2 | sed -e 's|^..|&/|')
19 pack_as_from_promisor () {
20 HASH=$(git -C repo pack-objects .git/objects/pack/pack) &&
21 >repo/.git/objects/pack/pack-$HASH.promisor &&
22 echo $HASH
25 promise_and_delete () {
26 HASH=$(git -C repo rev-parse "$1") &&
27 git -C repo tag -a -m message my_annotated_tag "$HASH" &&
28 git -C repo rev-parse my_annotated_tag | pack_as_from_promisor &&
29 # tag -d prints a message to stdout, so redirect it
30 git -C repo tag -d my_annotated_tag >/dev/null &&
31 delete_object repo "$HASH"
34 test_expect_success 'extensions.partialclone without filter' '
35 test_create_repo server &&
36 git clone --filter="blob:none" "file://$(pwd)/server" client &&
37 git -C client config --unset remote.origin.partialclonefilter &&
38 git -C client fetch origin
41 test_expect_success 'convert shallow clone to partial clone' '
42 rm -fr server client &&
43 test_create_repo server &&
44 test_commit -C server my_commit 1 &&
45 test_commit -C server my_commit2 1 &&
46 git clone --depth=1 "file://$(pwd)/server" client &&
47 git -C client fetch --unshallow --filter="blob:none" &&
48 test_cmp_config -C client true remote.origin.promisor &&
49 test_cmp_config -C client blob:none remote.origin.partialclonefilter &&
50 test_cmp_config -C client 1 core.repositoryformatversion
53 test_expect_success DEFAULT_REPO_FORMAT 'convert to partial clone with noop extension' '
54 rm -fr server client &&
55 test_create_repo server &&
56 test_commit -C server my_commit 1 &&
57 test_commit -C server my_commit2 1 &&
58 git clone --depth=1 "file://$(pwd)/server" client &&
59 test_cmp_config -C client 0 core.repositoryformatversion &&
60 git -C client config extensions.noop true &&
61 git -C client fetch --unshallow --filter="blob:none"
64 test_expect_success DEFAULT_REPO_FORMAT 'converting to partial clone fails with unrecognized extension' '
65 rm -fr server client &&
66 test_create_repo server &&
67 test_commit -C server my_commit 1 &&
68 test_commit -C server my_commit2 1 &&
69 git clone --depth=1 "file://$(pwd)/server" client &&
70 test_cmp_config -C client 0 core.repositoryformatversion &&
71 git -C client config extensions.nonsense true &&
72 test_must_fail git -C client fetch --unshallow --filter="blob:none"
75 test_expect_success 'missing reflog object, but promised by a commit, passes fsck' '
76 rm -rf repo &&
77 test_create_repo repo &&
78 test_commit -C repo my_commit &&
80 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
81 C=$(git -C repo commit-tree -m c -p $A HEAD^{tree}) &&
83 # Reference $A only from reflog, and delete it
84 git -C repo branch my_branch "$A" &&
85 git -C repo branch -f my_branch my_commit &&
86 delete_object repo "$A" &&
88 # State that we got $C, which refers to $A, from promisor
89 printf "$C\n" | pack_as_from_promisor &&
91 # Normally, it fails
92 test_must_fail git -C repo fsck &&
94 # But with the extension, it succeeds
95 git -C repo config core.repositoryformatversion 1 &&
96 git -C repo config extensions.partialclone "arbitrary string" &&
97 git -C repo fsck
100 test_expect_success 'missing reflog object, but promised by a tag, passes fsck' '
101 rm -rf repo &&
102 test_create_repo repo &&
103 test_commit -C repo my_commit &&
105 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
106 git -C repo tag -a -m d my_tag_name $A &&
107 T=$(git -C repo rev-parse my_tag_name) &&
108 git -C repo tag -d my_tag_name &&
110 # Reference $A only from reflog, and delete it
111 git -C repo branch my_branch "$A" &&
112 git -C repo branch -f my_branch my_commit &&
113 delete_object repo "$A" &&
115 # State that we got $T, which refers to $A, from promisor
116 printf "$T\n" | pack_as_from_promisor &&
118 git -C repo config core.repositoryformatversion 1 &&
119 git -C repo config extensions.partialclone "arbitrary string" &&
120 git -C repo fsck
123 test_expect_success 'missing reflog object alone fails fsck, even with extension set' '
124 rm -rf repo &&
125 test_create_repo repo &&
126 test_commit -C repo my_commit &&
128 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
129 B=$(git -C repo commit-tree -m b HEAD^{tree}) &&
131 # Reference $A only from reflog, and delete it
132 git -C repo branch my_branch "$A" &&
133 git -C repo branch -f my_branch my_commit &&
134 delete_object repo "$A" &&
136 git -C repo config core.repositoryformatversion 1 &&
137 git -C repo config extensions.partialclone "arbitrary string" &&
138 test_must_fail git -C repo fsck
141 test_expect_success 'missing ref object, but promised, passes fsck' '
142 rm -rf repo &&
143 test_create_repo repo &&
144 test_commit -C repo my_commit &&
146 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
148 # Reference $A only from ref
149 git -C repo branch my_branch "$A" &&
150 promise_and_delete "$A" &&
152 git -C repo config core.repositoryformatversion 1 &&
153 git -C repo config extensions.partialclone "arbitrary string" &&
154 git -C repo fsck
157 test_expect_success 'missing object, but promised, passes fsck' '
158 rm -rf repo &&
159 test_create_repo repo &&
160 test_commit -C repo 1 &&
161 test_commit -C repo 2 &&
162 test_commit -C repo 3 &&
163 git -C repo tag -a annotated_tag -m "annotated tag" &&
165 C=$(git -C repo rev-parse 1) &&
166 T=$(git -C repo rev-parse 2^{tree}) &&
167 B=$(git hash-object repo/3.t) &&
168 AT=$(git -C repo rev-parse annotated_tag) &&
170 promise_and_delete "$C" &&
171 promise_and_delete "$T" &&
172 promise_and_delete "$B" &&
173 promise_and_delete "$AT" &&
175 git -C repo config core.repositoryformatversion 1 &&
176 git -C repo config extensions.partialclone "arbitrary string" &&
177 git -C repo fsck
180 test_expect_success 'missing CLI object, but promised, passes fsck' '
181 rm -rf repo &&
182 test_create_repo repo &&
183 test_commit -C repo my_commit &&
185 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
186 promise_and_delete "$A" &&
188 git -C repo config core.repositoryformatversion 1 &&
189 git -C repo config extensions.partialclone "arbitrary string" &&
190 git -C repo fsck "$A"
193 test_expect_success 'fetching of missing objects' '
194 rm -rf repo err &&
195 test_create_repo server &&
196 test_commit -C server foo &&
197 git -C server repack -a -d --write-bitmap-index &&
199 git clone "file://$(pwd)/server" repo &&
200 HASH=$(git -C repo rev-parse foo) &&
201 rm -rf repo/.git/objects/* &&
203 git -C repo config core.repositoryformatversion 1 &&
204 git -C repo config extensions.partialclone "origin" &&
205 git -C repo cat-file -p "$HASH" 2>err &&
207 # Ensure that no spurious FETCH_HEAD messages are written
208 ! grep FETCH_HEAD err &&
210 # Ensure that the .promisor file is written, and check that its
211 # associated packfile contains the object
212 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
213 test_line_count = 1 promisorlist &&
214 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
215 git verify-pack --verbose "$IDX" >out &&
216 grep "$HASH" out
219 test_expect_success 'fetching of a promised object that promisor remote no longer has' '
220 rm -f err &&
221 test_create_repo unreliable-server &&
222 git -C unreliable-server config uploadpack.allowanysha1inwant 1 &&
223 git -C unreliable-server config uploadpack.allowfilter 1 &&
224 test_commit -C unreliable-server foo &&
226 git clone --filter=blob:none --no-checkout "file://$(pwd)/unreliable-server" unreliable-client &&
228 rm -rf unreliable-server/.git/objects/* &&
229 test_must_fail git -C unreliable-client checkout HEAD 2>err &&
230 grep "could not fetch.*from promisor remote" err
233 test_expect_success 'fetching of missing objects works with ref-in-want enabled' '
234 # ref-in-want requires protocol version 2
235 git -C server config protocol.version 2 &&
236 git -C server config uploadpack.allowrefinwant 1 &&
237 git -C repo config protocol.version 2 &&
239 rm -rf repo/.git/objects/* &&
240 rm -f trace &&
241 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" &&
242 grep "fetch< fetch=.*ref-in-want" trace
245 test_expect_success 'fetching of missing objects from another promisor remote' '
246 git clone "file://$(pwd)/server" server2 &&
247 test_commit -C server2 bar &&
248 git -C server2 repack -a -d --write-bitmap-index &&
249 HASH2=$(git -C server2 rev-parse bar) &&
251 git -C repo remote add server2 "file://$(pwd)/server2" &&
252 git -C repo config remote.server2.promisor true &&
253 git -C repo cat-file -p "$HASH2" &&
255 git -C repo fetch server2 &&
256 rm -rf repo/.git/objects/* &&
257 git -C repo cat-file -p "$HASH2" &&
259 # Ensure that the .promisor file is written, and check that its
260 # associated packfile contains the object
261 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
262 test_line_count = 1 promisorlist &&
263 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
264 git verify-pack --verbose "$IDX" >out &&
265 grep "$HASH2" out
268 test_expect_success 'fetching of missing objects configures a promisor remote' '
269 git clone "file://$(pwd)/server" server3 &&
270 test_commit -C server3 baz &&
271 git -C server3 repack -a -d --write-bitmap-index &&
272 HASH3=$(git -C server3 rev-parse baz) &&
273 git -C server3 config uploadpack.allowfilter 1 &&
275 rm repo/.git/objects/pack/pack-*.promisor &&
277 git -C repo remote add server3 "file://$(pwd)/server3" &&
278 git -C repo fetch --filter="blob:none" server3 $HASH3 &&
280 test_cmp_config -C repo true remote.server3.promisor &&
282 # Ensure that the .promisor file is written, and check that its
283 # associated packfile contains the object
284 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
285 test_line_count = 1 promisorlist &&
286 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
287 git verify-pack --verbose "$IDX" >out &&
288 grep "$HASH3" out
291 test_expect_success 'fetching of missing blobs works' '
292 rm -rf server server2 repo &&
293 rm -rf server server3 repo &&
294 test_create_repo server &&
295 test_commit -C server foo &&
296 git -C server repack -a -d --write-bitmap-index &&
298 git clone "file://$(pwd)/server" repo &&
299 git hash-object repo/foo.t >blobhash &&
300 rm -rf repo/.git/objects/* &&
302 git -C server config uploadpack.allowanysha1inwant 1 &&
303 git -C server config uploadpack.allowfilter 1 &&
304 git -C repo config core.repositoryformatversion 1 &&
305 git -C repo config extensions.partialclone "origin" &&
307 git -C repo cat-file -p $(cat blobhash)
310 test_expect_success 'fetching of missing trees does not fetch blobs' '
311 rm -rf server repo &&
312 test_create_repo server &&
313 test_commit -C server foo &&
314 git -C server repack -a -d --write-bitmap-index &&
316 git clone "file://$(pwd)/server" repo &&
317 git -C repo rev-parse foo^{tree} >treehash &&
318 git hash-object repo/foo.t >blobhash &&
319 rm -rf repo/.git/objects/* &&
321 git -C server config uploadpack.allowanysha1inwant 1 &&
322 git -C server config uploadpack.allowfilter 1 &&
323 git -C repo config core.repositoryformatversion 1 &&
324 git -C repo config extensions.partialclone "origin" &&
325 git -C repo cat-file -p $(cat treehash) &&
327 # Ensure that the tree, but not the blob, is fetched
328 git -C repo rev-list --objects --missing=print $(cat treehash) >objects &&
329 grep "^$(cat treehash)" objects &&
330 grep "^[?]$(cat blobhash)" objects
333 test_expect_success 'rev-list stops traversal at missing and promised commit' '
334 rm -rf repo &&
335 test_create_repo repo &&
336 test_commit -C repo foo &&
337 test_commit -C repo bar &&
339 FOO=$(git -C repo rev-parse foo) &&
340 promise_and_delete "$FOO" &&
342 git -C repo config core.repositoryformatversion 1 &&
343 git -C repo config extensions.partialclone "arbitrary string" &&
344 git -C repo rev-list --exclude-promisor-objects --objects bar >out &&
345 grep $(git -C repo rev-parse bar) out &&
346 ! grep $FOO out
349 test_expect_success 'missing tree objects with --missing=allow-promisor and --exclude-promisor-objects' '
350 rm -rf repo &&
351 test_create_repo repo &&
352 test_commit -C repo foo &&
353 test_commit -C repo bar &&
354 test_commit -C repo baz &&
356 promise_and_delete $(git -C repo rev-parse bar^{tree}) &&
357 promise_and_delete $(git -C repo rev-parse foo^{tree}) &&
359 git -C repo config core.repositoryformatversion 1 &&
360 git -C repo config extensions.partialclone "arbitrary string" &&
362 git -C repo rev-list --missing=allow-promisor --objects HEAD >objs 2>rev_list_err &&
363 test_must_be_empty rev_list_err &&
364 # 3 commits, 3 blobs, and 1 tree
365 test_line_count = 7 objs &&
367 # Do the same for --exclude-promisor-objects, but with all trees gone.
368 promise_and_delete $(git -C repo rev-parse baz^{tree}) &&
369 git -C repo rev-list --exclude-promisor-objects --objects HEAD >objs 2>rev_list_err &&
370 test_must_be_empty rev_list_err &&
371 # 3 commits, no blobs or trees
372 test_line_count = 3 objs
375 test_expect_success 'missing non-root tree object and rev-list' '
376 rm -rf repo &&
377 test_create_repo repo &&
378 mkdir repo/dir &&
379 echo foo >repo/dir/foo &&
380 git -C repo add dir/foo &&
381 git -C repo commit -m "commit dir/foo" &&
383 promise_and_delete $(git -C repo rev-parse HEAD:dir) &&
385 git -C repo config core.repositoryformatversion 1 &&
386 git -C repo config extensions.partialclone "arbitrary string" &&
388 git -C repo rev-list --missing=allow-any --objects HEAD >objs 2>rev_list_err &&
389 test_must_be_empty rev_list_err &&
390 # 1 commit and 1 tree
391 test_line_count = 2 objs
394 test_expect_success 'rev-list stops traversal at missing and promised tree' '
395 rm -rf repo &&
396 test_create_repo repo &&
397 test_commit -C repo foo &&
398 mkdir repo/a_dir &&
399 echo something >repo/a_dir/something &&
400 git -C repo add a_dir/something &&
401 git -C repo commit -m bar &&
403 # foo^{tree} (tree referenced from commit)
404 TREE=$(git -C repo rev-parse foo^{tree}) &&
406 # a tree referenced by HEAD^{tree} (tree referenced from tree)
407 TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) &&
409 promise_and_delete "$TREE" &&
410 promise_and_delete "$TREE2" &&
412 git -C repo config core.repositoryformatversion 1 &&
413 git -C repo config extensions.partialclone "arbitrary string" &&
414 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
415 grep $(git -C repo rev-parse foo) out &&
416 ! grep $TREE out &&
417 grep $(git -C repo rev-parse HEAD) out &&
418 ! grep $TREE2 out
421 test_expect_success 'rev-list stops traversal at missing and promised blob' '
422 rm -rf repo &&
423 test_create_repo repo &&
424 echo something >repo/something &&
425 git -C repo add something &&
426 git -C repo commit -m foo &&
428 BLOB=$(git -C repo hash-object -w something) &&
429 promise_and_delete "$BLOB" &&
431 git -C repo config core.repositoryformatversion 1 &&
432 git -C repo config extensions.partialclone "arbitrary string" &&
433 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
434 grep $(git -C repo rev-parse HEAD) out &&
435 ! grep $BLOB out
438 test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' '
439 rm -rf repo &&
440 test_create_repo repo &&
441 test_commit -C repo foo &&
442 test_commit -C repo bar &&
443 test_commit -C repo baz &&
445 COMMIT=$(git -C repo rev-parse foo) &&
446 TREE=$(git -C repo rev-parse bar^{tree}) &&
447 BLOB=$(git hash-object repo/baz.t) &&
448 printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor &&
450 git -C repo config core.repositoryformatversion 1 &&
451 git -C repo config extensions.partialclone "arbitrary string" &&
452 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
453 ! grep $COMMIT out &&
454 ! grep $TREE out &&
455 ! grep $BLOB out &&
456 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done
459 test_expect_success 'rev-list dies for missing objects on cmd line' '
460 rm -rf repo &&
461 test_create_repo repo &&
462 test_commit -C repo foo &&
463 test_commit -C repo bar &&
464 test_commit -C repo baz &&
466 COMMIT=$(git -C repo rev-parse foo) &&
467 TREE=$(git -C repo rev-parse bar^{tree}) &&
468 BLOB=$(git hash-object repo/baz.t) &&
470 promise_and_delete $COMMIT &&
471 promise_and_delete $TREE &&
472 promise_and_delete $BLOB &&
474 git -C repo config core.repositoryformatversion 1 &&
475 git -C repo config extensions.partialclone "arbitrary string" &&
477 for OBJ in "$COMMIT" "$TREE" "$BLOB"; do
478 test_must_fail git -C repo rev-list --objects \
479 --exclude-promisor-objects "$OBJ" &&
480 test_must_fail git -C repo rev-list --objects-edge-aggressive \
481 --exclude-promisor-objects "$OBJ" &&
483 # Do not die or crash when --ignore-missing is passed.
484 git -C repo rev-list --ignore-missing --objects \
485 --exclude-promisor-objects "$OBJ" &&
486 git -C repo rev-list --ignore-missing --objects-edge-aggressive \
487 --exclude-promisor-objects "$OBJ" || return 1
488 done
491 test_expect_success 'single promisor remote can be re-initialized gracefully' '
492 # ensure one promisor is in the promisors list
493 rm -rf repo &&
494 test_create_repo repo &&
495 test_create_repo other &&
496 git -C repo remote add foo "file://$(pwd)/other" &&
497 git -C repo config remote.foo.promisor true &&
498 git -C repo config extensions.partialclone foo &&
500 # reinitialize the promisors list
501 git -C repo fetch --filter=blob:none foo
504 test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
505 rm -rf repo &&
506 test_create_repo repo &&
507 test_commit -C repo one &&
508 test_commit -C repo two &&
510 TREE_ONE=$(git -C repo rev-parse one^{tree}) &&
511 printf "$TREE_ONE\n" | pack_as_from_promisor &&
512 TREE_TWO=$(git -C repo rev-parse two^{tree}) &&
513 printf "$TREE_TWO\n" | pack_as_from_promisor &&
515 git -C repo config core.repositoryformatversion 1 &&
516 git -C repo config extensions.partialclone "arbitrary string" &&
517 git -C repo gc &&
519 # Ensure that exactly one promisor packfile exists, and that it
520 # contains the trees but not the commits
521 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
522 test_line_count = 1 promisorlist &&
523 PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) &&
524 git verify-pack $PROMISOR_PACKFILE -v >out &&
525 grep "$TREE_ONE" out &&
526 grep "$TREE_TWO" out &&
527 ! grep "$(git -C repo rev-parse one)" out &&
528 ! grep "$(git -C repo rev-parse two)" out &&
530 # Remove the promisor packfile and associated files
531 rm $(sed "s/.promisor//" <promisorlist).* &&
533 # Ensure that the single other pack contains the commits, but not the
534 # trees
535 ls repo/.git/objects/pack/pack-*.pack >packlist &&
536 test_line_count = 1 packlist &&
537 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
538 grep "$(git -C repo rev-parse one)" out &&
539 grep "$(git -C repo rev-parse two)" out &&
540 ! grep "$TREE_ONE" out &&
541 ! grep "$TREE_TWO" out
544 test_expect_success 'gc does not repack promisor objects if there are none' '
545 rm -rf repo &&
546 test_create_repo repo &&
547 test_commit -C repo one &&
549 git -C repo config core.repositoryformatversion 1 &&
550 git -C repo config extensions.partialclone "arbitrary string" &&
551 git -C repo gc &&
553 # Ensure that only one pack exists
554 ls repo/.git/objects/pack/pack-*.pack >packlist &&
555 test_line_count = 1 packlist
558 repack_and_check () {
559 rm -rf repo2 &&
560 cp -r repo repo2 &&
561 if test x"$1" = "x--must-fail"
562 then
563 shift
564 test_must_fail git -C repo2 repack $1 -d
565 else
566 git -C repo2 repack $1 -d
567 fi &&
568 git -C repo2 fsck &&
570 git -C repo2 cat-file -e $2 &&
571 git -C repo2 cat-file -e $3
574 test_expect_success 'repack -d does not irreversibly delete promisor objects' '
575 rm -rf repo &&
576 test_create_repo repo &&
577 git -C repo config core.repositoryformatversion 1 &&
578 git -C repo config extensions.partialclone "arbitrary string" &&
580 git -C repo commit --allow-empty -m one &&
581 git -C repo commit --allow-empty -m two &&
582 git -C repo commit --allow-empty -m three &&
583 git -C repo commit --allow-empty -m four &&
584 ONE=$(git -C repo rev-parse HEAD^^^) &&
585 TWO=$(git -C repo rev-parse HEAD^^) &&
586 THREE=$(git -C repo rev-parse HEAD^) &&
588 printf "$TWO\n" | pack_as_from_promisor &&
589 printf "$THREE\n" | pack_as_from_promisor &&
590 delete_object repo "$ONE" &&
592 repack_and_check --must-fail -ab "$TWO" "$THREE" &&
593 repack_and_check -a "$TWO" "$THREE" &&
594 repack_and_check -A "$TWO" "$THREE" &&
595 repack_and_check -l "$TWO" "$THREE"
598 test_expect_success 'gc stops traversal when a missing but promised object is reached' '
599 rm -rf repo &&
600 test_create_repo repo &&
601 test_commit -C repo my_commit &&
603 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
604 HASH=$(promise_and_delete $TREE_HASH) &&
606 git -C repo config core.repositoryformatversion 1 &&
607 git -C repo config extensions.partialclone "arbitrary string" &&
608 git -C repo gc &&
610 # Ensure that the promisor packfile still exists, and remove it
611 test -e repo/.git/objects/pack/pack-$HASH.pack &&
612 rm repo/.git/objects/pack/pack-$HASH.* &&
614 # Ensure that the single other pack contains the commit, but not the tree
615 ls repo/.git/objects/pack/pack-*.pack >packlist &&
616 test_line_count = 1 packlist &&
617 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
618 grep "$(git -C repo rev-parse HEAD)" out &&
619 ! grep "$TREE_HASH" out
622 test_expect_success 'do not fetch when checking existence of tree we construct ourselves' '
623 rm -rf repo &&
624 test_create_repo repo &&
625 test_commit -C repo base &&
626 test_commit -C repo side1 &&
627 git -C repo checkout base &&
628 test_commit -C repo side2 &&
630 git -C repo config core.repositoryformatversion 1 &&
631 git -C repo config extensions.partialclone "arbitrary string" &&
633 git -C repo cherry-pick side1
636 test_expect_success 'exact rename does not need to fetch the blob lazily' '
637 rm -rf repo partial.git &&
638 test_create_repo repo &&
639 content="some dummy content" &&
640 test_commit -C repo create-a-file file.txt "$content" &&
641 git -C repo mv file.txt new-file.txt &&
642 git -C repo commit -m rename-the-file &&
643 FILE_HASH=$(git -C repo rev-parse HEAD:new-file.txt) &&
644 test_config -C repo uploadpack.allowfilter 1 &&
645 test_config -C repo uploadpack.allowanysha1inwant 1 &&
647 git clone --filter=blob:none --bare "file://$(pwd)/repo" partial.git &&
648 git -C partial.git rev-list --objects --missing=print HEAD >out &&
649 grep "[?]$FILE_HASH" out &&
650 git -C partial.git log --follow -- new-file.txt &&
651 git -C partial.git rev-list --objects --missing=print HEAD >out &&
652 grep "[?]$FILE_HASH" out
655 test_expect_success 'lazy-fetch when accessing object not in the_repository' '
656 rm -rf full partial.git &&
657 test_create_repo full &&
658 test_commit -C full create-a-file file.txt &&
660 test_config -C full uploadpack.allowfilter 1 &&
661 test_config -C full uploadpack.allowanysha1inwant 1 &&
662 git clone --filter=blob:none --bare "file://$(pwd)/full" partial.git &&
663 FILE_HASH=$(git -C full rev-parse HEAD:file.txt) &&
665 # Sanity check that the file is missing
666 git -C partial.git rev-list --objects --missing=print HEAD >out &&
667 grep "[?]$FILE_HASH" out &&
669 # The no-lazy-fetch mechanism prevents Git from fetching
670 test_must_fail env GIT_NO_LAZY_FETCH=1 \
671 git -C partial.git cat-file -e "$FILE_HASH" &&
673 # The same with command line option to "git"
674 test_must_fail git --no-lazy-fetch -C partial.git cat-file -e "$FILE_HASH" &&
676 # The same, forcing a subprocess via an alias
677 test_must_fail git --no-lazy-fetch -C partial.git \
678 -c alias.foo="!git cat-file" foo -e "$FILE_HASH" &&
680 # Sanity check that the file is still missing
681 git -C partial.git rev-list --objects --missing=print HEAD >out &&
682 grep "[?]$FILE_HASH" out &&
684 git -C full cat-file -s "$FILE_HASH" >expect &&
685 test-tool partial-clone object-info partial.git "$FILE_HASH" >actual &&
686 test_cmp expect actual &&
688 # Sanity check that the file is now present
689 git -C partial.git rev-list --objects --missing=print HEAD >out &&
690 ! grep "[?]$FILE_HASH" out
693 test_expect_success 'push should not fetch new commit objects' '
694 rm -rf server client &&
695 test_create_repo server &&
696 test_config -C server uploadpack.allowfilter 1 &&
697 test_config -C server uploadpack.allowanysha1inwant 1 &&
698 test_commit -C server server1 &&
700 git clone --filter=blob:none "file://$(pwd)/server" client &&
701 test_commit -C client client1 &&
703 test_commit -C server server2 &&
704 COMMIT=$(git -C server rev-parse server2) &&
706 test_must_fail git -C client push 2>err &&
707 grep "fetch first" err &&
708 git -C client rev-list --objects --missing=print "$COMMIT" >objects &&
709 grep "^[?]$COMMIT" objects
712 test_expect_success 'setup for promisor.quiet tests' '
713 rm -rf server &&
714 test_create_repo server &&
715 test_commit -C server foo &&
716 git -C server rm foo.t &&
717 git -C server commit -m remove &&
718 git -C server config uploadpack.allowanysha1inwant 1 &&
719 git -C server config uploadpack.allowfilter 1
722 test_expect_success TTY 'promisor.quiet=false shows progress messages' '
723 rm -rf repo &&
724 git clone --filter=blob:none "file://$(pwd)/server" repo &&
725 git -C repo config promisor.quiet "false" &&
727 test_terminal git -C repo cat-file -p foo:foo.t 2>err &&
729 # Ensure that progress messages are written
730 grep "Receiving objects" err
733 test_expect_success TTY 'promisor.quiet=true does not show progress messages' '
734 rm -rf repo &&
735 git clone --filter=blob:none "file://$(pwd)/server" repo &&
736 git -C repo config promisor.quiet "true" &&
738 test_terminal git -C repo cat-file -p foo:foo.t 2>err &&
740 # Ensure that no progress messages are written
741 ! grep "Receiving objects" err
744 test_expect_success TTY 'promisor.quiet=unconfigured shows progress messages' '
745 rm -rf repo &&
746 git clone --filter=blob:none "file://$(pwd)/server" repo &&
748 test_terminal git -C repo cat-file -p foo:foo.t 2>err &&
750 # Ensure that progress messages are written
751 grep "Receiving objects" err
754 . "$TEST_DIRECTORY"/lib-httpd.sh
755 start_httpd
757 test_expect_success 'fetching of missing objects from an HTTP server' '
758 rm -rf repo &&
759 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
760 test_create_repo "$SERVER" &&
761 test_commit -C "$SERVER" foo &&
762 git -C "$SERVER" repack -a -d --write-bitmap-index &&
764 git clone $HTTPD_URL/smart/server repo &&
765 HASH=$(git -C repo rev-parse foo) &&
766 rm -rf repo/.git/objects/* &&
768 git -C repo config core.repositoryformatversion 1 &&
769 git -C repo config extensions.partialclone "origin" &&
770 git -C repo cat-file -p "$HASH" &&
772 # Ensure that the .promisor file is written, and check that its
773 # associated packfile contains the object
774 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
775 test_line_count = 1 promisorlist &&
776 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
777 git verify-pack --verbose "$IDX" >out &&
778 grep "$HASH" out
781 # DO NOT add non-httpd-specific tests here, because the last part of this
782 # test script is only executed when httpd is available and enabled.
784 test_done