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" 2>err &&
199 # Ensure that no spurious FETCH_HEAD messages are written
200 ! grep FETCH_HEAD err &&
202 # Ensure that the .promisor file is written, and check that its
203 # associated packfile contains the object
204 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
205 test_line_count = 1 promisorlist &&
206 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
207 git verify-pack --verbose "$IDX" >out &&
211 test_expect_success 'fetching of missing objects works with ref-in-want enabled' '
212 # ref-in-want requires protocol version 2
213 git -C server config protocol.version 2 &&
214 git -C server config uploadpack.allowrefinwant 1 &&
215 git -C repo config protocol.version 2 &&
217 rm -rf repo/.git/objects/* &&
219 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" &&
220 grep "fetch< fetch=.*ref-in-want" trace
223 test_expect_success 'fetching of missing objects from another promisor remote' '
224 git clone "file://$(pwd)/server" server2 &&
225 test_commit -C server2 bar &&
226 git -C server2 repack -a -d --write-bitmap-index &&
227 HASH2=$(git -C server2 rev-parse bar) &&
229 git -C repo remote add server2 "file://$(pwd)/server2" &&
230 git -C repo config remote.server2.promisor true &&
231 git -C repo cat-file -p "$HASH2" &&
233 git -C repo fetch server2 &&
234 rm -rf repo/.git/objects/* &&
235 git -C repo cat-file -p "$HASH2" &&
237 # Ensure that the .promisor file is written, and check that its
238 # associated packfile contains the object
239 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
240 test_line_count = 1 promisorlist &&
241 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
242 git verify-pack --verbose "$IDX" >out &&
246 test_expect_success 'fetching of missing objects configures a promisor remote' '
247 git clone "file://$(pwd)/server" server3 &&
248 test_commit -C server3 baz &&
249 git -C server3 repack -a -d --write-bitmap-index &&
250 HASH3=$(git -C server3 rev-parse baz) &&
251 git -C server3 config uploadpack.allowfilter 1 &&
253 rm repo/.git/objects/pack/pack-*.promisor &&
255 git -C repo remote add server3 "file://$(pwd)/server3" &&
256 git -C repo fetch --filter="blob:none" server3 $HASH3 &&
258 test_cmp_config -C repo true remote.server3.promisor &&
260 # Ensure that the .promisor file is written, and check that its
261 # associated packfile contains the object
262 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
263 test_line_count = 1 promisorlist &&
264 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
265 git verify-pack --verbose "$IDX" >out &&
269 test_expect_success 'fetching of missing blobs works' '
270 rm -rf server server2 repo &&
271 rm -rf server server3 repo &&
272 test_create_repo server &&
273 test_commit -C server foo &&
274 git -C server repack -a -d --write-bitmap-index &&
276 git clone "file://$(pwd)/server" repo &&
277 git hash-object repo/foo.t >blobhash &&
278 rm -rf repo/.git/objects/* &&
280 git -C server config uploadpack.allowanysha1inwant 1 &&
281 git -C server config uploadpack.allowfilter 1 &&
282 git -C repo config core.repositoryformatversion 1 &&
283 git -C repo config extensions.partialclone "origin" &&
285 git -C repo cat-file -p $(cat blobhash)
288 test_expect_success 'fetching of missing trees does not fetch blobs' '
289 rm -rf server repo &&
290 test_create_repo server &&
291 test_commit -C server foo &&
292 git -C server repack -a -d --write-bitmap-index &&
294 git clone "file://$(pwd)/server" repo &&
295 git -C repo rev-parse foo^{tree} >treehash &&
296 git hash-object repo/foo.t >blobhash &&
297 rm -rf repo/.git/objects/* &&
299 git -C server config uploadpack.allowanysha1inwant 1 &&
300 git -C server config uploadpack.allowfilter 1 &&
301 git -C repo config core.repositoryformatversion 1 &&
302 git -C repo config extensions.partialclone "origin" &&
303 git -C repo cat-file -p $(cat treehash) &&
305 # Ensure that the tree, but not the blob, is fetched
306 git -C repo rev-list --objects --missing=print $(cat treehash) >objects &&
307 grep "^$(cat treehash)" objects &&
308 grep "^[?]$(cat blobhash)" objects
311 test_expect_success 'rev-list stops traversal at missing and promised commit' '
313 test_create_repo repo &&
314 test_commit -C repo foo &&
315 test_commit -C repo bar &&
317 FOO=$(git -C repo rev-parse foo) &&
318 promise_and_delete "$FOO" &&
320 git -C repo config core.repositoryformatversion 1 &&
321 git -C repo config extensions.partialclone "arbitrary string" &&
322 GIT_TEST_COMMIT_GRAPH=0 git -C repo -c core.commitGraph=false rev-list --exclude-promisor-objects --objects bar >out &&
323 grep $(git -C repo rev-parse bar) out &&
327 test_expect_success 'missing tree objects with --missing=allow-promisor and --exclude-promisor-objects' '
329 test_create_repo repo &&
330 test_commit -C repo foo &&
331 test_commit -C repo bar &&
332 test_commit -C repo baz &&
334 promise_and_delete $(git -C repo rev-parse bar^{tree}) &&
335 promise_and_delete $(git -C repo rev-parse foo^{tree}) &&
337 git -C repo config core.repositoryformatversion 1 &&
338 git -C repo config extensions.partialclone "arbitrary string" &&
340 git -C repo rev-list --missing=allow-promisor --objects HEAD >objs 2>rev_list_err &&
341 test_must_be_empty rev_list_err &&
342 # 3 commits, 3 blobs, and 1 tree
343 test_line_count = 7 objs &&
345 # Do the same for --exclude-promisor-objects, but with all trees gone.
346 promise_and_delete $(git -C repo rev-parse baz^{tree}) &&
347 git -C repo rev-list --exclude-promisor-objects --objects HEAD >objs 2>rev_list_err &&
348 test_must_be_empty rev_list_err &&
349 # 3 commits, no blobs or trees
350 test_line_count = 3 objs
353 test_expect_success 'missing non-root tree object and rev-list' '
355 test_create_repo repo &&
357 echo foo >repo/dir/foo &&
358 git -C repo add dir/foo &&
359 git -C repo commit -m "commit dir/foo" &&
361 promise_and_delete $(git -C repo rev-parse HEAD:dir) &&
363 git -C repo config core.repositoryformatversion 1 &&
364 git -C repo config extensions.partialclone "arbitrary string" &&
366 git -C repo rev-list --missing=allow-any --objects HEAD >objs 2>rev_list_err &&
367 test_must_be_empty rev_list_err &&
368 # 1 commit and 1 tree
369 test_line_count = 2 objs
372 test_expect_success 'rev-list stops traversal at missing and promised tree' '
374 test_create_repo repo &&
375 test_commit -C repo foo &&
377 echo something >repo/a_dir/something &&
378 git -C repo add a_dir/something &&
379 git -C repo commit -m bar &&
381 # foo^{tree} (tree referenced from commit)
382 TREE=$(git -C repo rev-parse foo^{tree}) &&
384 # a tree referenced by HEAD^{tree} (tree referenced from tree)
385 TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) &&
387 promise_and_delete "$TREE" &&
388 promise_and_delete "$TREE2" &&
390 git -C repo config core.repositoryformatversion 1 &&
391 git -C repo config extensions.partialclone "arbitrary string" &&
392 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
393 grep $(git -C repo rev-parse foo) out &&
395 grep $(git -C repo rev-parse HEAD) out &&
399 test_expect_success 'rev-list stops traversal at missing and promised blob' '
401 test_create_repo repo &&
402 echo something >repo/something &&
403 git -C repo add something &&
404 git -C repo commit -m foo &&
406 BLOB=$(git -C repo hash-object -w something) &&
407 promise_and_delete "$BLOB" &&
409 git -C repo config core.repositoryformatversion 1 &&
410 git -C repo config extensions.partialclone "arbitrary string" &&
411 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
412 grep $(git -C repo rev-parse HEAD) out &&
416 test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' '
418 test_create_repo repo &&
419 test_commit -C repo foo &&
420 test_commit -C repo bar &&
421 test_commit -C repo baz &&
423 COMMIT=$(git -C repo rev-parse foo) &&
424 TREE=$(git -C repo rev-parse bar^{tree}) &&
425 BLOB=$(git hash-object repo/baz.t) &&
426 printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor &&
428 git -C repo config core.repositoryformatversion 1 &&
429 git -C repo config extensions.partialclone "arbitrary string" &&
430 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
431 ! grep $COMMIT out &&
434 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done
437 test_expect_success 'rev-list dies for missing objects on cmd line' '
439 test_create_repo repo &&
440 test_commit -C repo foo &&
441 test_commit -C repo bar &&
442 test_commit -C repo baz &&
444 COMMIT=$(git -C repo rev-parse foo) &&
445 TREE=$(git -C repo rev-parse bar^{tree}) &&
446 BLOB=$(git hash-object repo/baz.t) &&
448 promise_and_delete $COMMIT &&
449 promise_and_delete $TREE &&
450 promise_and_delete $BLOB &&
452 git -C repo config core.repositoryformatversion 1 &&
453 git -C repo config extensions.partialclone "arbitrary string" &&
455 for OBJ in "$COMMIT" "$TREE" "$BLOB"; do
456 test_must_fail git -C repo rev-list --objects \
457 --exclude-promisor-objects "$OBJ" &&
458 test_must_fail git -C repo rev-list --objects-edge-aggressive \
459 --exclude-promisor-objects "$OBJ" &&
461 # Do not die or crash when --ignore-missing is passed.
462 git -C repo rev-list --ignore-missing --objects \
463 --exclude-promisor-objects "$OBJ" &&
464 git -C repo rev-list --ignore-missing --objects-edge-aggressive \
465 --exclude-promisor-objects "$OBJ"
469 test_expect_success 'single promisor remote can be re-initialized gracefully' '
470 # ensure one promisor is in the promisors list
472 test_create_repo repo &&
473 test_create_repo other &&
474 git -C repo remote add foo "file://$(pwd)/other" &&
475 git -C repo config remote.foo.promisor true &&
476 git -C repo config extensions.partialclone foo &&
478 # reinitialize the promisors list
479 git -C repo fetch --filter=blob:none foo
482 test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
484 test_create_repo repo &&
485 test_commit -C repo one &&
486 test_commit -C repo two &&
488 TREE_ONE=$(git -C repo rev-parse one^{tree}) &&
489 printf "$TREE_ONE\n" | pack_as_from_promisor &&
490 TREE_TWO=$(git -C repo rev-parse two^{tree}) &&
491 printf "$TREE_TWO\n" | pack_as_from_promisor &&
493 git -C repo config core.repositoryformatversion 1 &&
494 git -C repo config extensions.partialclone "arbitrary string" &&
497 # Ensure that exactly one promisor packfile exists, and that it
498 # contains the trees but not the commits
499 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
500 test_line_count = 1 promisorlist &&
501 PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) &&
502 git verify-pack $PROMISOR_PACKFILE -v >out &&
503 grep "$TREE_ONE" out &&
504 grep "$TREE_TWO" out &&
505 ! grep "$(git -C repo rev-parse one)" out &&
506 ! grep "$(git -C repo rev-parse two)" out &&
508 # Remove the promisor packfile and associated files
509 rm $(sed "s/.promisor//" <promisorlist).* &&
511 # Ensure that the single other pack contains the commits, but not the
513 ls repo/.git/objects/pack/pack-*.pack >packlist &&
514 test_line_count = 1 packlist &&
515 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
516 grep "$(git -C repo rev-parse one)" out &&
517 grep "$(git -C repo rev-parse two)" out &&
518 ! grep "$TREE_ONE" out &&
519 ! grep "$TREE_TWO" out
522 test_expect_success 'gc does not repack promisor objects if there are none' '
524 test_create_repo repo &&
525 test_commit -C repo one &&
527 git -C repo config core.repositoryformatversion 1 &&
528 git -C repo config extensions.partialclone "arbitrary string" &&
531 # Ensure that only one pack exists
532 ls repo/.git/objects/pack/pack-*.pack >packlist &&
533 test_line_count = 1 packlist
536 repack_and_check () {
539 git -C repo2 repack $1 -d &&
542 git -C repo2 cat-file -e $2 &&
543 git -C repo2 cat-file -e $3
546 test_expect_success 'repack -d does not irreversibly delete promisor objects' '
548 test_create_repo repo &&
549 git -C repo config core.repositoryformatversion 1 &&
550 git -C repo config extensions.partialclone "arbitrary string" &&
552 git -C repo commit --allow-empty -m one &&
553 git -C repo commit --allow-empty -m two &&
554 git -C repo commit --allow-empty -m three &&
555 git -C repo commit --allow-empty -m four &&
556 ONE=$(git -C repo rev-parse HEAD^^^) &&
557 TWO=$(git -C repo rev-parse HEAD^^) &&
558 THREE=$(git -C repo rev-parse HEAD^) &&
560 printf "$TWO\n" | pack_as_from_promisor &&
561 printf "$THREE\n" | pack_as_from_promisor &&
562 delete_object repo "$ONE" &&
564 repack_and_check -a "$TWO" "$THREE" &&
565 repack_and_check -A "$TWO" "$THREE" &&
566 repack_and_check -l "$TWO" "$THREE"
569 test_expect_success 'gc stops traversal when a missing but promised object is reached' '
571 test_create_repo repo &&
572 test_commit -C repo my_commit &&
574 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
575 HASH=$(promise_and_delete $TREE_HASH) &&
577 git -C repo config core.repositoryformatversion 1 &&
578 git -C repo config extensions.partialclone "arbitrary string" &&
581 # Ensure that the promisor packfile still exists, and remove it
582 test -e repo/.git/objects/pack/pack-$HASH.pack &&
583 rm repo/.git/objects/pack/pack-$HASH.* &&
585 # Ensure that the single other pack contains the commit, but not the tree
586 ls repo/.git/objects/pack/pack-*.pack >packlist &&
587 test_line_count = 1 packlist &&
588 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
589 grep "$(git -C repo rev-parse HEAD)" out &&
590 ! grep "$TREE_HASH" out
593 test_expect_success 'do not fetch when checking existence of tree we construct ourselves' '
595 test_create_repo repo &&
596 test_commit -C repo base &&
597 test_commit -C repo side1 &&
598 git -C repo checkout base &&
599 test_commit -C repo side2 &&
601 git -C repo config core.repositoryformatversion 1 &&
602 git -C repo config extensions.partialclone "arbitrary string" &&
604 git -C repo cherry-pick side1
607 . "$TEST_DIRECTORY"/lib-httpd.sh
610 test_expect_success 'fetching of missing objects from an HTTP server' '
612 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
613 test_create_repo "$SERVER" &&
614 test_commit -C "$SERVER" foo &&
615 git -C "$SERVER" repack -a -d --write-bitmap-index &&
617 git clone $HTTPD_URL/smart/server repo &&
618 HASH=$(git -C repo rev-parse foo) &&
619 rm -rf repo/.git/objects/* &&
621 git -C repo config core.repositoryformatversion 1 &&
622 git -C repo config extensions.partialclone "origin" &&
623 git -C repo cat-file -p "$HASH" &&
625 # Ensure that the .promisor file is written, and check that its
626 # associated packfile contains the object
627 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
628 test_line_count = 1 promisorlist &&
629 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
630 git verify-pack --verbose "$IDX" >out &&
634 # DO NOT add non-httpd-specific tests here, because the last part of this
635 # test script is only executed when httpd is available and enabled.