The twelfth batch
[git/gitster.git] / t / t0410-partial-clone.sh
blob34bdb3ab1f23b70115a47bb7b5bb01fb57beae8f
1 #!/bin/sh
3 test_description='partial clone'
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-terminal.sh
8 # When enabled, some commands will write commit-graphs. This causes fsck
9 # to fail when delete_object() is called because fsck will attempt to
10 # verify the out-of-sync commit graph.
11 GIT_TEST_COMMIT_GRAPH=0
13 delete_object () {
14 rm $1/.git/objects/$(echo $2 | sed -e 's|^..|&/|')
17 pack_as_from_promisor () {
18 HASH=$(git -C repo pack-objects .git/objects/pack/pack) &&
19 >repo/.git/objects/pack/pack-$HASH.promisor &&
20 echo $HASH
23 promise_and_delete () {
24 HASH=$(git -C repo rev-parse "$1") &&
25 git -C repo tag -a -m message my_annotated_tag "$HASH" &&
26 git -C repo rev-parse my_annotated_tag | pack_as_from_promisor &&
27 # tag -d prints a message to stdout, so redirect it
28 git -C repo tag -d my_annotated_tag >/dev/null &&
29 delete_object repo "$HASH"
32 test_expect_success 'extensions.partialclone without filter' '
33 test_create_repo server &&
34 git clone --filter="blob:none" "file://$(pwd)/server" client &&
35 git -C client config --unset remote.origin.partialclonefilter &&
36 git -C client fetch origin
39 test_expect_success 'convert shallow clone to partial clone' '
40 rm -fr server client &&
41 test_create_repo server &&
42 test_commit -C server my_commit 1 &&
43 test_commit -C server my_commit2 1 &&
44 git clone --depth=1 "file://$(pwd)/server" client &&
45 git -C client fetch --unshallow --filter="blob:none" &&
46 test_cmp_config -C client true remote.origin.promisor &&
47 test_cmp_config -C client blob:none remote.origin.partialclonefilter &&
48 test_cmp_config -C client 1 core.repositoryformatversion
51 test_expect_success DEFAULT_REPO_FORMAT 'convert to partial clone with noop extension' '
52 rm -fr server client &&
53 test_create_repo server &&
54 test_commit -C server my_commit 1 &&
55 test_commit -C server my_commit2 1 &&
56 git clone --depth=1 "file://$(pwd)/server" client &&
57 test_cmp_config -C client 0 core.repositoryformatversion &&
58 git -C client config extensions.noop true &&
59 git -C client fetch --unshallow --filter="blob:none"
62 test_expect_success DEFAULT_REPO_FORMAT 'converting to partial clone fails with unrecognized extension' '
63 rm -fr server client &&
64 test_create_repo server &&
65 test_commit -C server my_commit 1 &&
66 test_commit -C server my_commit2 1 &&
67 git clone --depth=1 "file://$(pwd)/server" client &&
68 test_cmp_config -C client 0 core.repositoryformatversion &&
69 git -C client config extensions.nonsense true &&
70 test_must_fail git -C client fetch --unshallow --filter="blob:none"
73 test_expect_success 'missing reflog object, but promised by a commit, passes fsck' '
74 rm -rf repo &&
75 test_create_repo repo &&
76 test_commit -C repo my_commit &&
78 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
79 C=$(git -C repo commit-tree -m c -p $A HEAD^{tree}) &&
81 # Reference $A only from reflog, and delete it
82 git -C repo branch my_branch "$A" &&
83 git -C repo branch -f my_branch my_commit &&
84 delete_object repo "$A" &&
86 # State that we got $C, which refers to $A, from promisor
87 printf "$C\n" | pack_as_from_promisor &&
89 # Normally, it fails
90 test_must_fail git -C repo fsck &&
92 # But with the extension, it succeeds
93 git -C repo config core.repositoryformatversion 1 &&
94 git -C repo config extensions.partialclone "arbitrary string" &&
95 git -C repo fsck
98 test_expect_success 'missing reflog object, but promised by a tag, passes fsck' '
99 rm -rf repo &&
100 test_create_repo repo &&
101 test_commit -C repo my_commit &&
103 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
104 git -C repo tag -a -m d my_tag_name $A &&
105 T=$(git -C repo rev-parse my_tag_name) &&
106 git -C repo tag -d my_tag_name &&
108 # Reference $A only from reflog, and delete it
109 git -C repo branch my_branch "$A" &&
110 git -C repo branch -f my_branch my_commit &&
111 delete_object repo "$A" &&
113 # State that we got $T, which refers to $A, from promisor
114 printf "$T\n" | pack_as_from_promisor &&
116 git -C repo config core.repositoryformatversion 1 &&
117 git -C repo config extensions.partialclone "arbitrary string" &&
118 git -C repo fsck
121 test_expect_success 'missing reflog object alone fails fsck, even with extension set' '
122 rm -rf repo &&
123 test_create_repo repo &&
124 test_commit -C repo my_commit &&
126 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
127 B=$(git -C repo commit-tree -m b HEAD^{tree}) &&
129 # Reference $A only from reflog, and delete it
130 git -C repo branch my_branch "$A" &&
131 git -C repo branch -f my_branch my_commit &&
132 delete_object repo "$A" &&
134 git -C repo config core.repositoryformatversion 1 &&
135 git -C repo config extensions.partialclone "arbitrary string" &&
136 test_must_fail git -C repo fsck
139 test_expect_success 'missing ref object, but promised, passes fsck' '
140 rm -rf repo &&
141 test_create_repo repo &&
142 test_commit -C repo my_commit &&
144 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
146 # Reference $A only from ref
147 git -C repo branch my_branch "$A" &&
148 promise_and_delete "$A" &&
150 git -C repo config core.repositoryformatversion 1 &&
151 git -C repo config extensions.partialclone "arbitrary string" &&
152 git -C repo fsck
155 test_expect_success 'missing object, but promised, passes fsck' '
156 rm -rf repo &&
157 test_create_repo repo &&
158 test_commit -C repo 1 &&
159 test_commit -C repo 2 &&
160 test_commit -C repo 3 &&
161 git -C repo tag -a annotated_tag -m "annotated tag" &&
163 C=$(git -C repo rev-parse 1) &&
164 T=$(git -C repo rev-parse 2^{tree}) &&
165 B=$(git hash-object repo/3.t) &&
166 AT=$(git -C repo rev-parse annotated_tag) &&
168 promise_and_delete "$C" &&
169 promise_and_delete "$T" &&
170 promise_and_delete "$B" &&
171 promise_and_delete "$AT" &&
173 git -C repo config core.repositoryformatversion 1 &&
174 git -C repo config extensions.partialclone "arbitrary string" &&
175 git -C repo fsck
178 test_expect_success 'missing CLI object, but promised, passes fsck' '
179 rm -rf repo &&
180 test_create_repo repo &&
181 test_commit -C repo my_commit &&
183 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
184 promise_and_delete "$A" &&
186 git -C repo config core.repositoryformatversion 1 &&
187 git -C repo config extensions.partialclone "arbitrary string" &&
188 git -C repo fsck "$A"
191 test_expect_success 'fetching of missing objects' '
192 rm -rf repo err &&
193 test_create_repo server &&
194 test_commit -C server foo &&
195 git -C server repack -a -d --write-bitmap-index &&
197 git clone "file://$(pwd)/server" repo &&
198 HASH=$(git -C repo rev-parse foo) &&
199 rm -rf repo/.git/objects/* &&
201 git -C repo config core.repositoryformatversion 1 &&
202 git -C repo config extensions.partialclone "origin" &&
203 git -C repo cat-file -p "$HASH" 2>err &&
205 # Ensure that no spurious FETCH_HEAD messages are written
206 ! grep FETCH_HEAD err &&
208 # Ensure that the .promisor file is written, and check that its
209 # associated packfile contains the object
210 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
211 test_line_count = 1 promisorlist &&
212 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
213 git verify-pack --verbose "$IDX" >out &&
214 grep "$HASH" out
217 test_expect_success 'fetching of a promised object that promisor remote no longer has' '
218 rm -f err &&
219 test_create_repo unreliable-server &&
220 git -C unreliable-server config uploadpack.allowanysha1inwant 1 &&
221 git -C unreliable-server config uploadpack.allowfilter 1 &&
222 test_commit -C unreliable-server foo &&
224 git clone --filter=blob:none --no-checkout "file://$(pwd)/unreliable-server" unreliable-client &&
226 rm -rf unreliable-server/.git/objects/* &&
227 test_must_fail git -C unreliable-client checkout HEAD 2>err &&
228 grep "could not fetch.*from promisor remote" err
231 test_expect_success 'fetching of missing objects works with ref-in-want enabled' '
232 # ref-in-want requires protocol version 2
233 git -C server config protocol.version 2 &&
234 git -C server config uploadpack.allowrefinwant 1 &&
235 git -C repo config protocol.version 2 &&
237 rm -rf repo/.git/objects/* &&
238 rm -f trace &&
239 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" &&
240 grep "fetch< fetch=.*ref-in-want" trace
243 test_expect_success 'fetching of missing objects from another promisor remote' '
244 git clone "file://$(pwd)/server" server2 &&
245 test_commit -C server2 bar &&
246 git -C server2 repack -a -d --write-bitmap-index &&
247 HASH2=$(git -C server2 rev-parse bar) &&
249 git -C repo remote add server2 "file://$(pwd)/server2" &&
250 git -C repo config remote.server2.promisor true &&
251 git -C repo cat-file -p "$HASH2" &&
253 git -C repo fetch server2 &&
254 rm -rf repo/.git/objects/* &&
255 git -C repo cat-file -p "$HASH2" &&
257 # Ensure that the .promisor file is written, and check that its
258 # associated packfile contains the object
259 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
260 test_line_count = 1 promisorlist &&
261 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
262 git verify-pack --verbose "$IDX" >out &&
263 grep "$HASH2" out
266 test_expect_success 'fetching of missing objects configures a promisor remote' '
267 git clone "file://$(pwd)/server" server3 &&
268 test_commit -C server3 baz &&
269 git -C server3 repack -a -d --write-bitmap-index &&
270 HASH3=$(git -C server3 rev-parse baz) &&
271 git -C server3 config uploadpack.allowfilter 1 &&
273 rm repo/.git/objects/pack/pack-*.promisor &&
275 git -C repo remote add server3 "file://$(pwd)/server3" &&
276 git -C repo fetch --filter="blob:none" server3 $HASH3 &&
278 test_cmp_config -C repo true remote.server3.promisor &&
280 # Ensure that the .promisor file is written, and check that its
281 # associated packfile contains the object
282 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
283 test_line_count = 1 promisorlist &&
284 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
285 git verify-pack --verbose "$IDX" >out &&
286 grep "$HASH3" out
289 test_expect_success 'fetching of missing blobs works' '
290 rm -rf server server2 repo &&
291 rm -rf server server3 repo &&
292 test_create_repo server &&
293 test_commit -C server foo &&
294 git -C server repack -a -d --write-bitmap-index &&
296 git clone "file://$(pwd)/server" repo &&
297 git hash-object repo/foo.t >blobhash &&
298 rm -rf repo/.git/objects/* &&
300 git -C server config uploadpack.allowanysha1inwant 1 &&
301 git -C server config uploadpack.allowfilter 1 &&
302 git -C repo config core.repositoryformatversion 1 &&
303 git -C repo config extensions.partialclone "origin" &&
305 git -C repo cat-file -p $(cat blobhash)
308 test_expect_success 'fetching of missing trees does not fetch blobs' '
309 rm -rf server repo &&
310 test_create_repo server &&
311 test_commit -C server foo &&
312 git -C server repack -a -d --write-bitmap-index &&
314 git clone "file://$(pwd)/server" repo &&
315 git -C repo rev-parse foo^{tree} >treehash &&
316 git hash-object repo/foo.t >blobhash &&
317 rm -rf repo/.git/objects/* &&
319 git -C server config uploadpack.allowanysha1inwant 1 &&
320 git -C server config uploadpack.allowfilter 1 &&
321 git -C repo config core.repositoryformatversion 1 &&
322 git -C repo config extensions.partialclone "origin" &&
323 git -C repo cat-file -p $(cat treehash) &&
325 # Ensure that the tree, but not the blob, is fetched
326 git -C repo rev-list --objects --missing=print $(cat treehash) >objects &&
327 grep "^$(cat treehash)" objects &&
328 grep "^[?]$(cat blobhash)" objects
331 test_expect_success 'rev-list stops traversal at missing and promised commit' '
332 rm -rf repo &&
333 test_create_repo repo &&
334 test_commit -C repo foo &&
335 test_commit -C repo bar &&
337 FOO=$(git -C repo rev-parse foo) &&
338 promise_and_delete "$FOO" &&
340 git -C repo config core.repositoryformatversion 1 &&
341 git -C repo config extensions.partialclone "arbitrary string" &&
342 git -C repo rev-list --exclude-promisor-objects --objects bar >out &&
343 grep $(git -C repo rev-parse bar) out &&
344 ! grep $FOO out
347 test_expect_success 'missing tree objects with --missing=allow-promisor and --exclude-promisor-objects' '
348 rm -rf repo &&
349 test_create_repo repo &&
350 test_commit -C repo foo &&
351 test_commit -C repo bar &&
352 test_commit -C repo baz &&
354 promise_and_delete $(git -C repo rev-parse bar^{tree}) &&
355 promise_and_delete $(git -C repo rev-parse foo^{tree}) &&
357 git -C repo config core.repositoryformatversion 1 &&
358 git -C repo config extensions.partialclone "arbitrary string" &&
360 git -C repo rev-list --missing=allow-promisor --objects HEAD >objs 2>rev_list_err &&
361 test_must_be_empty rev_list_err &&
362 # 3 commits, 3 blobs, and 1 tree
363 test_line_count = 7 objs &&
365 # Do the same for --exclude-promisor-objects, but with all trees gone.
366 promise_and_delete $(git -C repo rev-parse baz^{tree}) &&
367 git -C repo rev-list --exclude-promisor-objects --objects HEAD >objs 2>rev_list_err &&
368 test_must_be_empty rev_list_err &&
369 # 3 commits, no blobs or trees
370 test_line_count = 3 objs
373 test_expect_success 'missing non-root tree object and rev-list' '
374 rm -rf repo &&
375 test_create_repo repo &&
376 mkdir repo/dir &&
377 echo foo >repo/dir/foo &&
378 git -C repo add dir/foo &&
379 git -C repo commit -m "commit dir/foo" &&
381 promise_and_delete $(git -C repo rev-parse HEAD:dir) &&
383 git -C repo config core.repositoryformatversion 1 &&
384 git -C repo config extensions.partialclone "arbitrary string" &&
386 git -C repo rev-list --missing=allow-any --objects HEAD >objs 2>rev_list_err &&
387 test_must_be_empty rev_list_err &&
388 # 1 commit and 1 tree
389 test_line_count = 2 objs
392 test_expect_success 'rev-list stops traversal at missing and promised tree' '
393 rm -rf repo &&
394 test_create_repo repo &&
395 test_commit -C repo foo &&
396 mkdir repo/a_dir &&
397 echo something >repo/a_dir/something &&
398 git -C repo add a_dir/something &&
399 git -C repo commit -m bar &&
401 # foo^{tree} (tree referenced from commit)
402 TREE=$(git -C repo rev-parse foo^{tree}) &&
404 # a tree referenced by HEAD^{tree} (tree referenced from tree)
405 TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) &&
407 promise_and_delete "$TREE" &&
408 promise_and_delete "$TREE2" &&
410 git -C repo config core.repositoryformatversion 1 &&
411 git -C repo config extensions.partialclone "arbitrary string" &&
412 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
413 grep $(git -C repo rev-parse foo) out &&
414 ! grep $TREE out &&
415 grep $(git -C repo rev-parse HEAD) out &&
416 ! grep $TREE2 out
419 test_expect_success 'rev-list stops traversal at missing and promised blob' '
420 rm -rf repo &&
421 test_create_repo repo &&
422 echo something >repo/something &&
423 git -C repo add something &&
424 git -C repo commit -m foo &&
426 BLOB=$(git -C repo hash-object -w something) &&
427 promise_and_delete "$BLOB" &&
429 git -C repo config core.repositoryformatversion 1 &&
430 git -C repo config extensions.partialclone "arbitrary string" &&
431 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
432 grep $(git -C repo rev-parse HEAD) out &&
433 ! grep $BLOB out
436 test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' '
437 rm -rf repo &&
438 test_create_repo repo &&
439 test_commit -C repo foo &&
440 test_commit -C repo bar &&
441 test_commit -C repo baz &&
443 COMMIT=$(git -C repo rev-parse foo) &&
444 TREE=$(git -C repo rev-parse bar^{tree}) &&
445 BLOB=$(git hash-object repo/baz.t) &&
446 printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor &&
448 git -C repo config core.repositoryformatversion 1 &&
449 git -C repo config extensions.partialclone "arbitrary string" &&
450 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
451 ! grep $COMMIT out &&
452 ! grep $TREE out &&
453 ! grep $BLOB out &&
454 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done
457 test_expect_success 'rev-list dies for missing objects on cmd line' '
458 rm -rf repo &&
459 test_create_repo repo &&
460 test_commit -C repo foo &&
461 test_commit -C repo bar &&
462 test_commit -C repo baz &&
464 COMMIT=$(git -C repo rev-parse foo) &&
465 TREE=$(git -C repo rev-parse bar^{tree}) &&
466 BLOB=$(git hash-object repo/baz.t) &&
468 promise_and_delete $COMMIT &&
469 promise_and_delete $TREE &&
470 promise_and_delete $BLOB &&
472 git -C repo config core.repositoryformatversion 1 &&
473 git -C repo config extensions.partialclone "arbitrary string" &&
475 for OBJ in "$COMMIT" "$TREE" "$BLOB"; do
476 test_must_fail git -C repo rev-list --objects \
477 --exclude-promisor-objects "$OBJ" &&
478 test_must_fail git -C repo rev-list --objects-edge-aggressive \
479 --exclude-promisor-objects "$OBJ" &&
481 # Do not die or crash when --ignore-missing is passed.
482 git -C repo rev-list --ignore-missing --objects \
483 --exclude-promisor-objects "$OBJ" &&
484 git -C repo rev-list --ignore-missing --objects-edge-aggressive \
485 --exclude-promisor-objects "$OBJ" || return 1
486 done
489 test_expect_success 'single promisor remote can be re-initialized gracefully' '
490 # ensure one promisor is in the promisors list
491 rm -rf repo &&
492 test_create_repo repo &&
493 test_create_repo other &&
494 git -C repo remote add foo "file://$(pwd)/other" &&
495 git -C repo config remote.foo.promisor true &&
496 git -C repo config extensions.partialclone foo &&
498 # reinitialize the promisors list
499 git -C repo fetch --filter=blob:none foo
502 test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
503 rm -rf repo &&
504 test_create_repo repo &&
505 test_commit -C repo one &&
506 test_commit -C repo two &&
508 TREE_ONE=$(git -C repo rev-parse one^{tree}) &&
509 printf "$TREE_ONE\n" | pack_as_from_promisor &&
510 TREE_TWO=$(git -C repo rev-parse two^{tree}) &&
511 printf "$TREE_TWO\n" | pack_as_from_promisor &&
513 git -C repo config core.repositoryformatversion 1 &&
514 git -C repo config extensions.partialclone "arbitrary string" &&
515 git -C repo gc &&
517 # Ensure that exactly one promisor packfile exists, and that it
518 # contains the trees but not the commits
519 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
520 test_line_count = 1 promisorlist &&
521 PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) &&
522 git verify-pack $PROMISOR_PACKFILE -v >out &&
523 grep "$TREE_ONE" out &&
524 grep "$TREE_TWO" out &&
525 ! grep "$(git -C repo rev-parse one)" out &&
526 ! grep "$(git -C repo rev-parse two)" out &&
528 # Remove the promisor packfile and associated files
529 rm $(sed "s/.promisor//" <promisorlist).* &&
531 # Ensure that the single other pack contains the commits, but not the
532 # trees
533 ls repo/.git/objects/pack/pack-*.pack >packlist &&
534 test_line_count = 1 packlist &&
535 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
536 grep "$(git -C repo rev-parse one)" out &&
537 grep "$(git -C repo rev-parse two)" out &&
538 ! grep "$TREE_ONE" out &&
539 ! grep "$TREE_TWO" out
542 test_expect_success 'gc does not repack promisor objects if there are none' '
543 rm -rf repo &&
544 test_create_repo repo &&
545 test_commit -C repo one &&
547 git -C repo config core.repositoryformatversion 1 &&
548 git -C repo config extensions.partialclone "arbitrary string" &&
549 git -C repo gc &&
551 # Ensure that only one pack exists
552 ls repo/.git/objects/pack/pack-*.pack >packlist &&
553 test_line_count = 1 packlist
556 repack_and_check () {
557 rm -rf repo2 &&
558 cp -r repo repo2 &&
559 if test x"$1" = "x--must-fail"
560 then
561 shift
562 test_must_fail git -C repo2 repack $1 -d
563 else
564 git -C repo2 repack $1 -d
565 fi &&
566 git -C repo2 fsck &&
568 git -C repo2 cat-file -e $2 &&
569 git -C repo2 cat-file -e $3
572 test_expect_success 'repack -d does not irreversibly delete promisor objects' '
573 rm -rf repo &&
574 test_create_repo repo &&
575 git -C repo config core.repositoryformatversion 1 &&
576 git -C repo config extensions.partialclone "arbitrary string" &&
578 git -C repo commit --allow-empty -m one &&
579 git -C repo commit --allow-empty -m two &&
580 git -C repo commit --allow-empty -m three &&
581 git -C repo commit --allow-empty -m four &&
582 ONE=$(git -C repo rev-parse HEAD^^^) &&
583 TWO=$(git -C repo rev-parse HEAD^^) &&
584 THREE=$(git -C repo rev-parse HEAD^) &&
586 printf "$TWO\n" | pack_as_from_promisor &&
587 printf "$THREE\n" | pack_as_from_promisor &&
588 delete_object repo "$ONE" &&
590 repack_and_check --must-fail -ab "$TWO" "$THREE" &&
591 repack_and_check -a "$TWO" "$THREE" &&
592 repack_and_check -A "$TWO" "$THREE" &&
593 repack_and_check -l "$TWO" "$THREE"
596 test_expect_success 'gc stops traversal when a missing but promised object is reached' '
597 rm -rf repo &&
598 test_create_repo repo &&
599 test_commit -C repo my_commit &&
601 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
602 HASH=$(promise_and_delete $TREE_HASH) &&
604 git -C repo config core.repositoryformatversion 1 &&
605 git -C repo config extensions.partialclone "arbitrary string" &&
606 git -C repo gc &&
608 # Ensure that the promisor packfile still exists, and remove it
609 test -e repo/.git/objects/pack/pack-$HASH.pack &&
610 rm repo/.git/objects/pack/pack-$HASH.* &&
612 # Ensure that the single other pack contains the commit, but not the tree
613 ls repo/.git/objects/pack/pack-*.pack >packlist &&
614 test_line_count = 1 packlist &&
615 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
616 grep "$(git -C repo rev-parse HEAD)" out &&
617 ! grep "$TREE_HASH" out
620 test_expect_success 'do not fetch when checking existence of tree we construct ourselves' '
621 rm -rf repo &&
622 test_create_repo repo &&
623 test_commit -C repo base &&
624 test_commit -C repo side1 &&
625 git -C repo checkout base &&
626 test_commit -C repo side2 &&
628 git -C repo config core.repositoryformatversion 1 &&
629 git -C repo config extensions.partialclone "arbitrary string" &&
631 git -C repo cherry-pick side1
634 test_expect_success 'exact rename does not need to fetch the blob lazily' '
635 rm -rf repo partial.git &&
636 test_create_repo repo &&
637 content="some dummy content" &&
638 test_commit -C repo create-a-file file.txt "$content" &&
639 git -C repo mv file.txt new-file.txt &&
640 git -C repo commit -m rename-the-file &&
641 FILE_HASH=$(git -C repo rev-parse HEAD:new-file.txt) &&
642 test_config -C repo uploadpack.allowfilter 1 &&
643 test_config -C repo uploadpack.allowanysha1inwant 1 &&
645 git clone --filter=blob:none --bare "file://$(pwd)/repo" partial.git &&
646 git -C partial.git rev-list --objects --missing=print HEAD >out &&
647 grep "[?]$FILE_HASH" out &&
648 git -C partial.git log --follow -- new-file.txt &&
649 git -C partial.git rev-list --objects --missing=print HEAD >out &&
650 grep "[?]$FILE_HASH" out
653 test_expect_success 'lazy-fetch when accessing object not in the_repository' '
654 rm -rf full partial.git &&
655 test_create_repo full &&
656 test_commit -C full create-a-file file.txt &&
658 test_config -C full uploadpack.allowfilter 1 &&
659 test_config -C full uploadpack.allowanysha1inwant 1 &&
660 git clone --filter=blob:none --bare "file://$(pwd)/full" partial.git &&
661 FILE_HASH=$(git -C full rev-parse HEAD:file.txt) &&
663 # Sanity check that the file is missing
664 git -C partial.git rev-list --objects --missing=print HEAD >out &&
665 grep "[?]$FILE_HASH" out &&
667 # The no-lazy-fetch mechanism prevents Git from fetching
668 test_must_fail env GIT_NO_LAZY_FETCH=1 \
669 git -C partial.git cat-file -e "$FILE_HASH" &&
671 # The same with command line option to "git"
672 test_must_fail git --no-lazy-fetch -C partial.git cat-file -e "$FILE_HASH" &&
674 # The same, forcing a subprocess via an alias
675 test_must_fail git --no-lazy-fetch -C partial.git \
676 -c alias.foo="!git cat-file" foo -e "$FILE_HASH" &&
678 # Sanity check that the file is still missing
679 git -C partial.git rev-list --objects --missing=print HEAD >out &&
680 grep "[?]$FILE_HASH" out &&
682 git -C full cat-file -s "$FILE_HASH" >expect &&
683 test-tool partial-clone object-info partial.git "$FILE_HASH" >actual &&
684 test_cmp expect actual &&
686 # Sanity check that the file is now present
687 git -C partial.git rev-list --objects --missing=print HEAD >out &&
688 ! grep "[?]$FILE_HASH" out
691 test_expect_success 'push should not fetch new commit objects' '
692 rm -rf server client &&
693 test_create_repo server &&
694 test_config -C server uploadpack.allowfilter 1 &&
695 test_config -C server uploadpack.allowanysha1inwant 1 &&
696 test_commit -C server server1 &&
698 git clone --filter=blob:none "file://$(pwd)/server" client &&
699 test_commit -C client client1 &&
701 test_commit -C server server2 &&
702 COMMIT=$(git -C server rev-parse server2) &&
704 test_must_fail git -C client push 2>err &&
705 grep "fetch first" err &&
706 git -C client rev-list --objects --missing=print "$COMMIT" >objects &&
707 grep "^[?]$COMMIT" objects
710 test_expect_success 'setup for promisor.quiet tests' '
711 rm -rf server &&
712 test_create_repo server &&
713 test_commit -C server foo &&
714 git -C server rm foo.t &&
715 git -C server commit -m remove &&
716 git -C server config uploadpack.allowanysha1inwant 1 &&
717 git -C server config uploadpack.allowfilter 1
720 test_expect_success TTY 'promisor.quiet=false shows progress messages' '
721 rm -rf repo &&
722 git clone --filter=blob:none "file://$(pwd)/server" repo &&
723 git -C repo config promisor.quiet "false" &&
725 test_terminal git -C repo cat-file -p foo:foo.t 2>err &&
727 # Ensure that progress messages are written
728 grep "Receiving objects" err
731 test_expect_success TTY 'promisor.quiet=true does not show progress messages' '
732 rm -rf repo &&
733 git clone --filter=blob:none "file://$(pwd)/server" repo &&
734 git -C repo config promisor.quiet "true" &&
736 test_terminal git -C repo cat-file -p foo:foo.t 2>err &&
738 # Ensure that no progress messages are written
739 ! grep "Receiving objects" err
742 test_expect_success TTY 'promisor.quiet=unconfigured shows progress messages' '
743 rm -rf repo &&
744 git clone --filter=blob:none "file://$(pwd)/server" repo &&
746 test_terminal git -C repo cat-file -p foo:foo.t 2>err &&
748 # Ensure that progress messages are written
749 grep "Receiving objects" err
752 . "$TEST_DIRECTORY"/lib-httpd.sh
753 start_httpd
755 test_expect_success 'fetching of missing objects from an HTTP server' '
756 rm -rf repo &&
757 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
758 test_create_repo "$SERVER" &&
759 test_commit -C "$SERVER" foo &&
760 git -C "$SERVER" repack -a -d --write-bitmap-index &&
762 git clone $HTTPD_URL/smart/server repo &&
763 HASH=$(git -C repo rev-parse foo) &&
764 rm -rf repo/.git/objects/* &&
766 git -C repo config core.repositoryformatversion 1 &&
767 git -C repo config extensions.partialclone "origin" &&
768 git -C repo cat-file -p "$HASH" &&
770 # Ensure that the .promisor file is written, and check that its
771 # associated packfile contains the object
772 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
773 test_line_count = 1 promisorlist &&
774 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
775 git verify-pack --verbose "$IDX" >out &&
776 grep "$HASH" out
779 # DO NOT add non-httpd-specific tests here, because the last part of this
780 # test script is only executed when httpd is available and enabled.
782 test_done