3 test_description='partial clone'
8 rm $1/.git/objects/$(echo $2 | sed -e 's|^..|&/|')
11 pack_as_from_promisor () {
12 HASH=$(git -C repo pack-objects .git/objects/pack/pack) &&
13 >repo/.git/objects/pack/pack-$HASH.promisor &&
17 promise_and_delete () {
18 HASH=$(git -C repo rev-parse "$1") &&
19 git -C repo tag -a -m message my_annotated_tag "$HASH" &&
20 git -C repo rev-parse my_annotated_tag | pack_as_from_promisor &&
21 # tag -d prints a message to stdout, so redirect it
22 git -C repo tag -d my_annotated_tag >/dev/null &&
23 delete_object repo "$HASH"
26 test_expect_success 'extensions.partialclone without filter' '
27 test_create_repo server &&
28 git clone --filter="blob:none" "file://$(pwd)/server" client &&
29 git -C client config --unset remote.origin.partialclonefilter &&
30 git -C client fetch origin
33 test_expect_success 'convert shallow clone to partial clone' '
34 rm -fr server client &&
35 test_create_repo server &&
36 test_commit -C server my_commit 1 &&
37 test_commit -C server my_commit2 1 &&
38 git clone --depth=1 "file://$(pwd)/server" client &&
39 git -C client fetch --unshallow --filter="blob:none" &&
40 test_cmp_config -C client true remote.origin.promisor &&
41 test_cmp_config -C client blob:none remote.origin.partialclonefilter &&
42 test_cmp_config -C client 1 core.repositoryformatversion
45 test_expect_success SHA1 'convert to partial clone with noop extension' '
46 rm -fr server client &&
47 test_create_repo server &&
48 test_commit -C server my_commit 1 &&
49 test_commit -C server my_commit2 1 &&
50 git clone --depth=1 "file://$(pwd)/server" client &&
51 test_cmp_config -C client 0 core.repositoryformatversion &&
52 git -C client config extensions.noop true &&
53 git -C client fetch --unshallow --filter="blob:none"
56 test_expect_success SHA1 'converting to partial clone fails with unrecognized extension' '
57 rm -fr server client &&
58 test_create_repo server &&
59 test_commit -C server my_commit 1 &&
60 test_commit -C server my_commit2 1 &&
61 git clone --depth=1 "file://$(pwd)/server" client &&
62 test_cmp_config -C client 0 core.repositoryformatversion &&
63 git -C client config extensions.nonsense true &&
64 test_must_fail git -C client fetch --unshallow --filter="blob:none"
67 test_expect_success 'missing reflog object, but promised by a commit, passes fsck' '
69 test_create_repo repo &&
70 test_commit -C repo my_commit &&
72 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
73 C=$(git -C repo commit-tree -m c -p $A HEAD^{tree}) &&
75 # Reference $A only from reflog, and delete it
76 git -C repo branch my_branch "$A" &&
77 git -C repo branch -f my_branch my_commit &&
78 delete_object repo "$A" &&
80 # State that we got $C, which refers to $A, from promisor
81 printf "$C\n" | pack_as_from_promisor &&
84 test_must_fail git -C repo fsck &&
86 # But with the extension, it succeeds
87 git -C repo config core.repositoryformatversion 1 &&
88 git -C repo config extensions.partialclone "arbitrary string" &&
92 test_expect_success 'missing reflog object, but promised by a tag, passes fsck' '
94 test_create_repo repo &&
95 test_commit -C repo my_commit &&
97 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
98 git -C repo tag -a -m d my_tag_name $A &&
99 T=$(git -C repo rev-parse my_tag_name) &&
100 git -C repo tag -d my_tag_name &&
102 # Reference $A only from reflog, and delete it
103 git -C repo branch my_branch "$A" &&
104 git -C repo branch -f my_branch my_commit &&
105 delete_object repo "$A" &&
107 # State that we got $T, which refers to $A, from promisor
108 printf "$T\n" | pack_as_from_promisor &&
110 git -C repo config core.repositoryformatversion 1 &&
111 git -C repo config extensions.partialclone "arbitrary string" &&
115 test_expect_success 'missing reflog object alone fails fsck, even with extension set' '
117 test_create_repo repo &&
118 test_commit -C repo my_commit &&
120 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
121 B=$(git -C repo commit-tree -m b HEAD^{tree}) &&
123 # Reference $A only from reflog, and delete it
124 git -C repo branch my_branch "$A" &&
125 git -C repo branch -f my_branch my_commit &&
126 delete_object repo "$A" &&
128 git -C repo config core.repositoryformatversion 1 &&
129 git -C repo config extensions.partialclone "arbitrary string" &&
130 test_must_fail git -C repo fsck
133 test_expect_success 'missing ref object, but promised, passes fsck' '
135 test_create_repo repo &&
136 test_commit -C repo my_commit &&
138 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
140 # Reference $A only from ref
141 git -C repo branch my_branch "$A" &&
142 promise_and_delete "$A" &&
144 git -C repo config core.repositoryformatversion 1 &&
145 git -C repo config extensions.partialclone "arbitrary string" &&
149 test_expect_success 'missing object, but promised, passes fsck' '
151 test_create_repo repo &&
152 test_commit -C repo 1 &&
153 test_commit -C repo 2 &&
154 test_commit -C repo 3 &&
155 git -C repo tag -a annotated_tag -m "annotated tag" &&
157 C=$(git -C repo rev-parse 1) &&
158 T=$(git -C repo rev-parse 2^{tree}) &&
159 B=$(git hash-object repo/3.t) &&
160 AT=$(git -C repo rev-parse annotated_tag) &&
162 promise_and_delete "$C" &&
163 promise_and_delete "$T" &&
164 promise_and_delete "$B" &&
165 promise_and_delete "$AT" &&
167 git -C repo config core.repositoryformatversion 1 &&
168 git -C repo config extensions.partialclone "arbitrary string" &&
172 test_expect_success 'missing CLI object, but promised, passes fsck' '
174 test_create_repo repo &&
175 test_commit -C repo my_commit &&
177 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
178 promise_and_delete "$A" &&
180 git -C repo config core.repositoryformatversion 1 &&
181 git -C repo config extensions.partialclone "arbitrary string" &&
182 git -C repo fsck "$A"
185 test_expect_success 'fetching of missing objects' '
187 test_create_repo server &&
188 test_commit -C server foo &&
189 git -C server repack -a -d --write-bitmap-index &&
191 git clone "file://$(pwd)/server" repo &&
192 HASH=$(git -C repo rev-parse foo) &&
193 rm -rf repo/.git/objects/* &&
195 git -C repo config core.repositoryformatversion 1 &&
196 git -C repo config extensions.partialclone "origin" &&
197 git -C repo cat-file -p "$HASH" &&
199 # Ensure that the .promisor file is written, and check that its
200 # associated packfile contains the object
201 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
202 test_line_count = 1 promisorlist &&
203 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
204 git verify-pack --verbose "$IDX" >out &&
208 test_expect_success 'fetching of missing objects works with ref-in-want enabled' '
209 # ref-in-want requires protocol version 2
210 git -C server config protocol.version 2 &&
211 git -C server config uploadpack.allowrefinwant 1 &&
212 git -C repo config protocol.version 2 &&
214 rm -rf repo/.git/objects/* &&
216 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" &&
217 grep "git< fetch=.*ref-in-want" trace
220 test_expect_success 'fetching of missing objects from another promisor remote' '
221 git clone "file://$(pwd)/server" server2 &&
222 test_commit -C server2 bar &&
223 git -C server2 repack -a -d --write-bitmap-index &&
224 HASH2=$(git -C server2 rev-parse bar) &&
226 git -C repo remote add server2 "file://$(pwd)/server2" &&
227 git -C repo config remote.server2.promisor true &&
228 git -C repo cat-file -p "$HASH2" &&
230 git -C repo fetch server2 &&
231 rm -rf repo/.git/objects/* &&
232 git -C repo cat-file -p "$HASH2" &&
234 # Ensure that the .promisor file is written, and check that its
235 # associated packfile contains the object
236 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
237 test_line_count = 1 promisorlist &&
238 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
239 git verify-pack --verbose "$IDX" >out &&
243 test_expect_success 'fetching of missing objects configures a promisor remote' '
244 git clone "file://$(pwd)/server" server3 &&
245 test_commit -C server3 baz &&
246 git -C server3 repack -a -d --write-bitmap-index &&
247 HASH3=$(git -C server3 rev-parse baz) &&
248 git -C server3 config uploadpack.allowfilter 1 &&
250 rm repo/.git/objects/pack/pack-*.promisor &&
252 git -C repo remote add server3 "file://$(pwd)/server3" &&
253 git -C repo fetch --filter="blob:none" server3 $HASH3 &&
255 test_cmp_config -C repo true remote.server3.promisor &&
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 &&
266 test_expect_success 'fetching of missing blobs works' '
267 rm -rf server server2 repo &&
268 rm -rf server server3 repo &&
269 test_create_repo server &&
270 test_commit -C server foo &&
271 git -C server repack -a -d --write-bitmap-index &&
273 git clone "file://$(pwd)/server" repo &&
274 git hash-object repo/foo.t >blobhash &&
275 rm -rf repo/.git/objects/* &&
277 git -C server config uploadpack.allowanysha1inwant 1 &&
278 git -C server config uploadpack.allowfilter 1 &&
279 git -C repo config core.repositoryformatversion 1 &&
280 git -C repo config extensions.partialclone "origin" &&
282 git -C repo cat-file -p $(cat blobhash)
285 test_expect_success 'fetching of missing trees does not fetch blobs' '
286 rm -rf server repo &&
287 test_create_repo server &&
288 test_commit -C server foo &&
289 git -C server repack -a -d --write-bitmap-index &&
291 git clone "file://$(pwd)/server" repo &&
292 git -C repo rev-parse foo^{tree} >treehash &&
293 git hash-object repo/foo.t >blobhash &&
294 rm -rf repo/.git/objects/* &&
296 git -C server config uploadpack.allowanysha1inwant 1 &&
297 git -C server config uploadpack.allowfilter 1 &&
298 git -C repo config core.repositoryformatversion 1 &&
299 git -C repo config extensions.partialclone "origin" &&
300 git -C repo cat-file -p $(cat treehash) &&
302 # Ensure that the tree, but not the blob, is fetched
303 git -C repo rev-list --objects --missing=print $(cat treehash) >objects &&
304 grep "^$(cat treehash)" objects &&
305 grep "^[?]$(cat blobhash)" objects
308 test_expect_success 'rev-list stops traversal at missing and promised commit' '
310 test_create_repo repo &&
311 test_commit -C repo foo &&
312 test_commit -C repo bar &&
314 FOO=$(git -C repo rev-parse foo) &&
315 promise_and_delete "$FOO" &&
317 git -C repo config core.repositoryformatversion 1 &&
318 git -C repo config extensions.partialclone "arbitrary string" &&
319 GIT_TEST_COMMIT_GRAPH=0 git -C repo -c core.commitGraph=false rev-list --exclude-promisor-objects --objects bar >out &&
320 grep $(git -C repo rev-parse bar) out &&
324 test_expect_success 'missing tree objects with --missing=allow-promisor and --exclude-promisor-objects' '
326 test_create_repo repo &&
327 test_commit -C repo foo &&
328 test_commit -C repo bar &&
329 test_commit -C repo baz &&
331 promise_and_delete $(git -C repo rev-parse bar^{tree}) &&
332 promise_and_delete $(git -C repo rev-parse foo^{tree}) &&
334 git -C repo config core.repositoryformatversion 1 &&
335 git -C repo config extensions.partialclone "arbitrary string" &&
337 git -C repo rev-list --missing=allow-promisor --objects HEAD >objs 2>rev_list_err &&
338 test_must_be_empty rev_list_err &&
339 # 3 commits, 3 blobs, and 1 tree
340 test_line_count = 7 objs &&
342 # Do the same for --exclude-promisor-objects, but with all trees gone.
343 promise_and_delete $(git -C repo rev-parse baz^{tree}) &&
344 git -C repo rev-list --exclude-promisor-objects --objects HEAD >objs 2>rev_list_err &&
345 test_must_be_empty rev_list_err &&
346 # 3 commits, no blobs or trees
347 test_line_count = 3 objs
350 test_expect_success 'missing non-root tree object and rev-list' '
352 test_create_repo repo &&
354 echo foo >repo/dir/foo &&
355 git -C repo add dir/foo &&
356 git -C repo commit -m "commit dir/foo" &&
358 promise_and_delete $(git -C repo rev-parse HEAD:dir) &&
360 git -C repo config core.repositoryformatversion 1 &&
361 git -C repo config extensions.partialclone "arbitrary string" &&
363 git -C repo rev-list --missing=allow-any --objects HEAD >objs 2>rev_list_err &&
364 test_must_be_empty rev_list_err &&
365 # 1 commit and 1 tree
366 test_line_count = 2 objs
369 test_expect_success 'rev-list stops traversal at missing and promised tree' '
371 test_create_repo repo &&
372 test_commit -C repo foo &&
374 echo something >repo/a_dir/something &&
375 git -C repo add a_dir/something &&
376 git -C repo commit -m bar &&
378 # foo^{tree} (tree referenced from commit)
379 TREE=$(git -C repo rev-parse foo^{tree}) &&
381 # a tree referenced by HEAD^{tree} (tree referenced from tree)
382 TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) &&
384 promise_and_delete "$TREE" &&
385 promise_and_delete "$TREE2" &&
387 git -C repo config core.repositoryformatversion 1 &&
388 git -C repo config extensions.partialclone "arbitrary string" &&
389 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
390 grep $(git -C repo rev-parse foo) out &&
392 grep $(git -C repo rev-parse HEAD) out &&
396 test_expect_success 'rev-list stops traversal at missing and promised blob' '
398 test_create_repo repo &&
399 echo something >repo/something &&
400 git -C repo add something &&
401 git -C repo commit -m foo &&
403 BLOB=$(git -C repo hash-object -w something) &&
404 promise_and_delete "$BLOB" &&
406 git -C repo config core.repositoryformatversion 1 &&
407 git -C repo config extensions.partialclone "arbitrary string" &&
408 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
409 grep $(git -C repo rev-parse HEAD) out &&
413 test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' '
415 test_create_repo repo &&
416 test_commit -C repo foo &&
417 test_commit -C repo bar &&
418 test_commit -C repo baz &&
420 COMMIT=$(git -C repo rev-parse foo) &&
421 TREE=$(git -C repo rev-parse bar^{tree}) &&
422 BLOB=$(git hash-object repo/baz.t) &&
423 printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor &&
425 git -C repo config core.repositoryformatversion 1 &&
426 git -C repo config extensions.partialclone "arbitrary string" &&
427 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
428 ! grep $COMMIT out &&
431 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done
434 test_expect_success 'rev-list dies for missing objects on cmd line' '
436 test_create_repo repo &&
437 test_commit -C repo foo &&
438 test_commit -C repo bar &&
439 test_commit -C repo baz &&
441 COMMIT=$(git -C repo rev-parse foo) &&
442 TREE=$(git -C repo rev-parse bar^{tree}) &&
443 BLOB=$(git hash-object repo/baz.t) &&
445 promise_and_delete $COMMIT &&
446 promise_and_delete $TREE &&
447 promise_and_delete $BLOB &&
449 git -C repo config core.repositoryformatversion 1 &&
450 git -C repo config extensions.partialclone "arbitrary string" &&
452 for OBJ in "$COMMIT" "$TREE" "$BLOB"; do
453 test_must_fail git -C repo rev-list --objects \
454 --exclude-promisor-objects "$OBJ" &&
455 test_must_fail git -C repo rev-list --objects-edge-aggressive \
456 --exclude-promisor-objects "$OBJ" &&
458 # Do not die or crash when --ignore-missing is passed.
459 git -C repo rev-list --ignore-missing --objects \
460 --exclude-promisor-objects "$OBJ" &&
461 git -C repo rev-list --ignore-missing --objects-edge-aggressive \
462 --exclude-promisor-objects "$OBJ"
466 test_expect_success 'single promisor remote can be re-initialized gracefully' '
467 # ensure one promisor is in the promisors list
469 test_create_repo repo &&
470 test_create_repo other &&
471 git -C repo remote add foo "file://$(pwd)/other" &&
472 git -C repo config remote.foo.promisor true &&
473 git -C repo config extensions.partialclone foo &&
475 # reinitialize the promisors list
476 git -C repo fetch --filter=blob:none foo
479 test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
481 test_create_repo repo &&
482 test_commit -C repo one &&
483 test_commit -C repo two &&
485 TREE_ONE=$(git -C repo rev-parse one^{tree}) &&
486 printf "$TREE_ONE\n" | pack_as_from_promisor &&
487 TREE_TWO=$(git -C repo rev-parse two^{tree}) &&
488 printf "$TREE_TWO\n" | pack_as_from_promisor &&
490 git -C repo config core.repositoryformatversion 1 &&
491 git -C repo config extensions.partialclone "arbitrary string" &&
494 # Ensure that exactly one promisor packfile exists, and that it
495 # contains the trees but not the commits
496 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
497 test_line_count = 1 promisorlist &&
498 PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) &&
499 git verify-pack $PROMISOR_PACKFILE -v >out &&
500 grep "$TREE_ONE" out &&
501 grep "$TREE_TWO" out &&
502 ! grep "$(git -C repo rev-parse one)" out &&
503 ! grep "$(git -C repo rev-parse two)" out &&
505 # Remove the promisor packfile and associated files
506 rm $(sed "s/.promisor//" <promisorlist).* &&
508 # Ensure that the single other pack contains the commits, but not the
510 ls repo/.git/objects/pack/pack-*.pack >packlist &&
511 test_line_count = 1 packlist &&
512 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
513 grep "$(git -C repo rev-parse one)" out &&
514 grep "$(git -C repo rev-parse two)" out &&
515 ! grep "$TREE_ONE" out &&
516 ! grep "$TREE_TWO" out
519 test_expect_success 'gc does not repack promisor objects if there are none' '
521 test_create_repo repo &&
522 test_commit -C repo one &&
524 git -C repo config core.repositoryformatversion 1 &&
525 git -C repo config extensions.partialclone "arbitrary string" &&
528 # Ensure that only one pack exists
529 ls repo/.git/objects/pack/pack-*.pack >packlist &&
530 test_line_count = 1 packlist
533 repack_and_check () {
536 git -C repo2 repack $1 -d &&
539 git -C repo2 cat-file -e $2 &&
540 git -C repo2 cat-file -e $3
543 test_expect_success 'repack -d does not irreversibly delete promisor objects' '
545 test_create_repo repo &&
546 git -C repo config core.repositoryformatversion 1 &&
547 git -C repo config extensions.partialclone "arbitrary string" &&
549 git -C repo commit --allow-empty -m one &&
550 git -C repo commit --allow-empty -m two &&
551 git -C repo commit --allow-empty -m three &&
552 git -C repo commit --allow-empty -m four &&
553 ONE=$(git -C repo rev-parse HEAD^^^) &&
554 TWO=$(git -C repo rev-parse HEAD^^) &&
555 THREE=$(git -C repo rev-parse HEAD^) &&
557 printf "$TWO\n" | pack_as_from_promisor &&
558 printf "$THREE\n" | pack_as_from_promisor &&
559 delete_object repo "$ONE" &&
561 repack_and_check -a "$TWO" "$THREE" &&
562 repack_and_check -A "$TWO" "$THREE" &&
563 repack_and_check -l "$TWO" "$THREE"
566 test_expect_success 'gc stops traversal when a missing but promised object is reached' '
568 test_create_repo repo &&
569 test_commit -C repo my_commit &&
571 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
572 HASH=$(promise_and_delete $TREE_HASH) &&
574 git -C repo config core.repositoryformatversion 1 &&
575 git -C repo config extensions.partialclone "arbitrary string" &&
578 # Ensure that the promisor packfile still exists, and remove it
579 test -e repo/.git/objects/pack/pack-$HASH.pack &&
580 rm repo/.git/objects/pack/pack-$HASH.* &&
582 # Ensure that the single other pack contains the commit, but not the tree
583 ls repo/.git/objects/pack/pack-*.pack >packlist &&
584 test_line_count = 1 packlist &&
585 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
586 grep "$(git -C repo rev-parse HEAD)" out &&
587 ! grep "$TREE_HASH" out
590 test_expect_success 'do not fetch when checking existence of tree we construct ourselves' '
592 test_create_repo repo &&
593 test_commit -C repo base &&
594 test_commit -C repo side1 &&
595 git -C repo checkout base &&
596 test_commit -C repo side2 &&
598 git -C repo config core.repositoryformatversion 1 &&
599 git -C repo config extensions.partialclone "arbitrary string" &&
601 git -C repo cherry-pick side1
604 . "$TEST_DIRECTORY"/lib-httpd.sh
607 test_expect_success 'fetching of missing objects from an HTTP server' '
609 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
610 test_create_repo "$SERVER" &&
611 test_commit -C "$SERVER" foo &&
612 git -C "$SERVER" repack -a -d --write-bitmap-index &&
614 git clone $HTTPD_URL/smart/server repo &&
615 HASH=$(git -C repo rev-parse foo) &&
616 rm -rf repo/.git/objects/* &&
618 git -C repo config core.repositoryformatversion 1 &&
619 git -C repo config extensions.partialclone "origin" &&
620 git -C repo cat-file -p "$HASH" &&
622 # Ensure that the .promisor file is written, and check that its
623 # associated packfile contains the object
624 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
625 test_line_count = 1 promisorlist &&
626 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
627 git verify-pack --verbose "$IDX" >out &&
631 # DO NOT add non-httpd-specific tests here, because the last part of this
632 # test script is only executed when httpd is available and enabled.