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 'missing reflog object, but promised by a commit, passes fsck' '
47 test_create_repo repo &&
48 test_commit -C repo my_commit &&
50 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
51 C=$(git -C repo commit-tree -m c -p $A HEAD^{tree}) &&
53 # Reference $A only from reflog, and delete it
54 git -C repo branch my_branch "$A" &&
55 git -C repo branch -f my_branch my_commit &&
56 delete_object repo "$A" &&
58 # State that we got $C, which refers to $A, from promisor
59 printf "$C\n" | pack_as_from_promisor &&
62 test_must_fail git -C repo fsck &&
64 # But with the extension, it succeeds
65 git -C repo config core.repositoryformatversion 1 &&
66 git -C repo config extensions.partialclone "arbitrary string" &&
70 test_expect_success 'missing reflog object, but promised by a tag, passes fsck' '
72 test_create_repo repo &&
73 test_commit -C repo my_commit &&
75 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
76 git -C repo tag -a -m d my_tag_name $A &&
77 T=$(git -C repo rev-parse my_tag_name) &&
78 git -C repo tag -d my_tag_name &&
80 # Reference $A only from reflog, and delete it
81 git -C repo branch my_branch "$A" &&
82 git -C repo branch -f my_branch my_commit &&
83 delete_object repo "$A" &&
85 # State that we got $T, which refers to $A, from promisor
86 printf "$T\n" | pack_as_from_promisor &&
88 git -C repo config core.repositoryformatversion 1 &&
89 git -C repo config extensions.partialclone "arbitrary string" &&
93 test_expect_success 'missing reflog object alone fails fsck, even with extension set' '
95 test_create_repo repo &&
96 test_commit -C repo my_commit &&
98 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
99 B=$(git -C repo commit-tree -m b HEAD^{tree}) &&
101 # Reference $A only from reflog, and delete it
102 git -C repo branch my_branch "$A" &&
103 git -C repo branch -f my_branch my_commit &&
104 delete_object repo "$A" &&
106 git -C repo config core.repositoryformatversion 1 &&
107 git -C repo config extensions.partialclone "arbitrary string" &&
108 test_must_fail git -C repo fsck
111 test_expect_success 'missing ref object, but promised, passes fsck' '
113 test_create_repo repo &&
114 test_commit -C repo my_commit &&
116 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
118 # Reference $A only from ref
119 git -C repo branch my_branch "$A" &&
120 promise_and_delete "$A" &&
122 git -C repo config core.repositoryformatversion 1 &&
123 git -C repo config extensions.partialclone "arbitrary string" &&
127 test_expect_success 'missing object, but promised, passes fsck' '
129 test_create_repo repo &&
130 test_commit -C repo 1 &&
131 test_commit -C repo 2 &&
132 test_commit -C repo 3 &&
133 git -C repo tag -a annotated_tag -m "annotated tag" &&
135 C=$(git -C repo rev-parse 1) &&
136 T=$(git -C repo rev-parse 2^{tree}) &&
137 B=$(git hash-object repo/3.t) &&
138 AT=$(git -C repo rev-parse annotated_tag) &&
140 promise_and_delete "$C" &&
141 promise_and_delete "$T" &&
142 promise_and_delete "$B" &&
143 promise_and_delete "$AT" &&
145 git -C repo config core.repositoryformatversion 1 &&
146 git -C repo config extensions.partialclone "arbitrary string" &&
150 test_expect_success 'missing CLI object, but promised, passes fsck' '
152 test_create_repo repo &&
153 test_commit -C repo my_commit &&
155 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
156 promise_and_delete "$A" &&
158 git -C repo config core.repositoryformatversion 1 &&
159 git -C repo config extensions.partialclone "arbitrary string" &&
160 git -C repo fsck "$A"
163 test_expect_success 'fetching of missing objects' '
165 test_create_repo server &&
166 test_commit -C server foo &&
167 git -C server repack -a -d --write-bitmap-index &&
169 git clone "file://$(pwd)/server" repo &&
170 HASH=$(git -C repo rev-parse foo) &&
171 rm -rf repo/.git/objects/* &&
173 git -C repo config core.repositoryformatversion 1 &&
174 git -C repo config extensions.partialclone "origin" &&
175 git -C repo cat-file -p "$HASH" &&
177 # Ensure that the .promisor file is written, and check that its
178 # associated packfile contains the object
179 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
180 test_line_count = 1 promisorlist &&
181 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
182 git verify-pack --verbose "$IDX" >out &&
186 test_expect_success 'fetching of missing objects works with ref-in-want enabled' '
187 # ref-in-want requires protocol version 2
188 git -C server config protocol.version 2 &&
189 git -C server config uploadpack.allowrefinwant 1 &&
190 git -C repo config protocol.version 2 &&
192 rm -rf repo/.git/objects/* &&
194 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" &&
195 grep "git< fetch=.*ref-in-want" trace
198 test_expect_success 'fetching of missing objects from another promisor remote' '
199 git clone "file://$(pwd)/server" server2 &&
200 test_commit -C server2 bar &&
201 git -C server2 repack -a -d --write-bitmap-index &&
202 HASH2=$(git -C server2 rev-parse bar) &&
204 git -C repo remote add server2 "file://$(pwd)/server2" &&
205 git -C repo config remote.server2.promisor true &&
206 git -C repo cat-file -p "$HASH2" &&
208 git -C repo fetch server2 &&
209 rm -rf repo/.git/objects/* &&
210 git -C repo cat-file -p "$HASH2" &&
212 # Ensure that the .promisor file is written, and check that its
213 # associated packfile contains the object
214 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
215 test_line_count = 1 promisorlist &&
216 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
217 git verify-pack --verbose "$IDX" >out &&
221 test_expect_success 'fetching of missing objects configures a promisor remote' '
222 git clone "file://$(pwd)/server" server3 &&
223 test_commit -C server3 baz &&
224 git -C server3 repack -a -d --write-bitmap-index &&
225 HASH3=$(git -C server3 rev-parse baz) &&
226 git -C server3 config uploadpack.allowfilter 1 &&
228 rm repo/.git/objects/pack/pack-*.promisor &&
230 git -C repo remote add server3 "file://$(pwd)/server3" &&
231 git -C repo fetch --filter="blob:none" server3 $HASH3 &&
233 test_cmp_config -C repo true remote.server3.promisor &&
235 # Ensure that the .promisor file is written, and check that its
236 # associated packfile contains the object
237 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
238 test_line_count = 1 promisorlist &&
239 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
240 git verify-pack --verbose "$IDX" >out &&
244 test_expect_success 'fetching of missing blobs works' '
245 rm -rf server server2 repo &&
246 rm -rf server server3 repo &&
247 test_create_repo server &&
248 test_commit -C server foo &&
249 git -C server repack -a -d --write-bitmap-index &&
251 git clone "file://$(pwd)/server" repo &&
252 git hash-object repo/foo.t >blobhash &&
253 rm -rf repo/.git/objects/* &&
255 git -C server config uploadpack.allowanysha1inwant 1 &&
256 git -C server config uploadpack.allowfilter 1 &&
257 git -C repo config core.repositoryformatversion 1 &&
258 git -C repo config extensions.partialclone "origin" &&
260 git -C repo cat-file -p $(cat blobhash)
263 test_expect_success 'fetching of missing trees does not fetch blobs' '
264 rm -rf server repo &&
265 test_create_repo server &&
266 test_commit -C server foo &&
267 git -C server repack -a -d --write-bitmap-index &&
269 git clone "file://$(pwd)/server" repo &&
270 git -C repo rev-parse foo^{tree} >treehash &&
271 git hash-object repo/foo.t >blobhash &&
272 rm -rf repo/.git/objects/* &&
274 git -C server config uploadpack.allowanysha1inwant 1 &&
275 git -C server config uploadpack.allowfilter 1 &&
276 git -C repo config core.repositoryformatversion 1 &&
277 git -C repo config extensions.partialclone "origin" &&
278 git -C repo cat-file -p $(cat treehash) &&
280 # Ensure that the tree, but not the blob, is fetched
281 git -C repo rev-list --objects --missing=print $(cat treehash) >objects &&
282 grep "^$(cat treehash)" objects &&
283 grep "^[?]$(cat blobhash)" objects
286 test_expect_success 'rev-list stops traversal at missing and promised commit' '
288 test_create_repo repo &&
289 test_commit -C repo foo &&
290 test_commit -C repo bar &&
292 FOO=$(git -C repo rev-parse foo) &&
293 promise_and_delete "$FOO" &&
295 git -C repo config core.repositoryformatversion 1 &&
296 git -C repo config extensions.partialclone "arbitrary string" &&
297 GIT_TEST_COMMIT_GRAPH=0 git -C repo -c core.commitGraph=false rev-list --exclude-promisor-objects --objects bar >out &&
298 grep $(git -C repo rev-parse bar) out &&
302 test_expect_success 'missing tree objects with --missing=allow-promisor and --exclude-promisor-objects' '
304 test_create_repo repo &&
305 test_commit -C repo foo &&
306 test_commit -C repo bar &&
307 test_commit -C repo baz &&
309 promise_and_delete $(git -C repo rev-parse bar^{tree}) &&
310 promise_and_delete $(git -C repo rev-parse foo^{tree}) &&
312 git -C repo config core.repositoryformatversion 1 &&
313 git -C repo config extensions.partialclone "arbitrary string" &&
315 git -C repo rev-list --missing=allow-promisor --objects HEAD >objs 2>rev_list_err &&
316 test_must_be_empty rev_list_err &&
317 # 3 commits, 3 blobs, and 1 tree
318 test_line_count = 7 objs &&
320 # Do the same for --exclude-promisor-objects, but with all trees gone.
321 promise_and_delete $(git -C repo rev-parse baz^{tree}) &&
322 git -C repo rev-list --exclude-promisor-objects --objects HEAD >objs 2>rev_list_err &&
323 test_must_be_empty rev_list_err &&
324 # 3 commits, no blobs or trees
325 test_line_count = 3 objs
328 test_expect_success 'missing non-root tree object and rev-list' '
330 test_create_repo repo &&
332 echo foo >repo/dir/foo &&
333 git -C repo add dir/foo &&
334 git -C repo commit -m "commit dir/foo" &&
336 promise_and_delete $(git -C repo rev-parse HEAD:dir) &&
338 git -C repo config core.repositoryformatversion 1 &&
339 git -C repo config extensions.partialclone "arbitrary string" &&
341 git -C repo rev-list --missing=allow-any --objects HEAD >objs 2>rev_list_err &&
342 test_must_be_empty rev_list_err &&
343 # 1 commit and 1 tree
344 test_line_count = 2 objs
347 test_expect_success 'rev-list stops traversal at missing and promised tree' '
349 test_create_repo repo &&
350 test_commit -C repo foo &&
352 echo something >repo/a_dir/something &&
353 git -C repo add a_dir/something &&
354 git -C repo commit -m bar &&
356 # foo^{tree} (tree referenced from commit)
357 TREE=$(git -C repo rev-parse foo^{tree}) &&
359 # a tree referenced by HEAD^{tree} (tree referenced from tree)
360 TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) &&
362 promise_and_delete "$TREE" &&
363 promise_and_delete "$TREE2" &&
365 git -C repo config core.repositoryformatversion 1 &&
366 git -C repo config extensions.partialclone "arbitrary string" &&
367 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
368 grep $(git -C repo rev-parse foo) out &&
370 grep $(git -C repo rev-parse HEAD) out &&
374 test_expect_success 'rev-list stops traversal at missing and promised blob' '
376 test_create_repo repo &&
377 echo something >repo/something &&
378 git -C repo add something &&
379 git -C repo commit -m foo &&
381 BLOB=$(git -C repo hash-object -w something) &&
382 promise_and_delete "$BLOB" &&
384 git -C repo config core.repositoryformatversion 1 &&
385 git -C repo config extensions.partialclone "arbitrary string" &&
386 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
387 grep $(git -C repo rev-parse HEAD) out &&
391 test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' '
393 test_create_repo repo &&
394 test_commit -C repo foo &&
395 test_commit -C repo bar &&
396 test_commit -C repo baz &&
398 COMMIT=$(git -C repo rev-parse foo) &&
399 TREE=$(git -C repo rev-parse bar^{tree}) &&
400 BLOB=$(git hash-object repo/baz.t) &&
401 printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor &&
403 git -C repo config core.repositoryformatversion 1 &&
404 git -C repo config extensions.partialclone "arbitrary string" &&
405 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
406 ! grep $COMMIT out &&
409 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done
412 test_expect_success 'rev-list dies for missing objects on cmd line' '
414 test_create_repo repo &&
415 test_commit -C repo foo &&
416 test_commit -C repo bar &&
417 test_commit -C repo baz &&
419 COMMIT=$(git -C repo rev-parse foo) &&
420 TREE=$(git -C repo rev-parse bar^{tree}) &&
421 BLOB=$(git hash-object repo/baz.t) &&
423 promise_and_delete $COMMIT &&
424 promise_and_delete $TREE &&
425 promise_and_delete $BLOB &&
427 git -C repo config core.repositoryformatversion 1 &&
428 git -C repo config extensions.partialclone "arbitrary string" &&
430 for OBJ in "$COMMIT" "$TREE" "$BLOB"; do
431 test_must_fail git -C repo rev-list --objects \
432 --exclude-promisor-objects "$OBJ" &&
433 test_must_fail git -C repo rev-list --objects-edge-aggressive \
434 --exclude-promisor-objects "$OBJ" &&
436 # Do not die or crash when --ignore-missing is passed.
437 git -C repo rev-list --ignore-missing --objects \
438 --exclude-promisor-objects "$OBJ" &&
439 git -C repo rev-list --ignore-missing --objects-edge-aggressive \
440 --exclude-promisor-objects "$OBJ"
444 test_expect_success 'single promisor remote can be re-initialized gracefully' '
445 # ensure one promisor is in the promisors list
447 test_create_repo repo &&
448 test_create_repo other &&
449 git -C repo remote add foo "file://$(pwd)/other" &&
450 git -C repo config remote.foo.promisor true &&
451 git -C repo config extensions.partialclone foo &&
453 # reinitialize the promisors list
454 git -C repo fetch --filter=blob:none foo
457 test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
459 test_create_repo repo &&
460 test_commit -C repo one &&
461 test_commit -C repo two &&
463 TREE_ONE=$(git -C repo rev-parse one^{tree}) &&
464 printf "$TREE_ONE\n" | pack_as_from_promisor &&
465 TREE_TWO=$(git -C repo rev-parse two^{tree}) &&
466 printf "$TREE_TWO\n" | pack_as_from_promisor &&
468 git -C repo config core.repositoryformatversion 1 &&
469 git -C repo config extensions.partialclone "arbitrary string" &&
472 # Ensure that exactly one promisor packfile exists, and that it
473 # contains the trees but not the commits
474 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
475 test_line_count = 1 promisorlist &&
476 PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) &&
477 git verify-pack $PROMISOR_PACKFILE -v >out &&
478 grep "$TREE_ONE" out &&
479 grep "$TREE_TWO" out &&
480 ! grep "$(git -C repo rev-parse one)" out &&
481 ! grep "$(git -C repo rev-parse two)" out &&
483 # Remove the promisor packfile and associated files
484 rm $(sed "s/.promisor//" <promisorlist).* &&
486 # Ensure that the single other pack contains the commits, but not the
488 ls repo/.git/objects/pack/pack-*.pack >packlist &&
489 test_line_count = 1 packlist &&
490 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
491 grep "$(git -C repo rev-parse one)" out &&
492 grep "$(git -C repo rev-parse two)" out &&
493 ! grep "$TREE_ONE" out &&
494 ! grep "$TREE_TWO" out
497 test_expect_success 'gc does not repack promisor objects if there are none' '
499 test_create_repo repo &&
500 test_commit -C repo one &&
502 git -C repo config core.repositoryformatversion 1 &&
503 git -C repo config extensions.partialclone "arbitrary string" &&
506 # Ensure that only one pack exists
507 ls repo/.git/objects/pack/pack-*.pack >packlist &&
508 test_line_count = 1 packlist
511 repack_and_check () {
514 git -C repo2 repack $1 -d &&
517 git -C repo2 cat-file -e $2 &&
518 git -C repo2 cat-file -e $3
521 test_expect_success 'repack -d does not irreversibly delete promisor objects' '
523 test_create_repo repo &&
524 git -C repo config core.repositoryformatversion 1 &&
525 git -C repo config extensions.partialclone "arbitrary string" &&
527 git -C repo commit --allow-empty -m one &&
528 git -C repo commit --allow-empty -m two &&
529 git -C repo commit --allow-empty -m three &&
530 git -C repo commit --allow-empty -m four &&
531 ONE=$(git -C repo rev-parse HEAD^^^) &&
532 TWO=$(git -C repo rev-parse HEAD^^) &&
533 THREE=$(git -C repo rev-parse HEAD^) &&
535 printf "$TWO\n" | pack_as_from_promisor &&
536 printf "$THREE\n" | pack_as_from_promisor &&
537 delete_object repo "$ONE" &&
539 repack_and_check -a "$TWO" "$THREE" &&
540 repack_and_check -A "$TWO" "$THREE" &&
541 repack_and_check -l "$TWO" "$THREE"
544 test_expect_success 'gc stops traversal when a missing but promised object is reached' '
546 test_create_repo repo &&
547 test_commit -C repo my_commit &&
549 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
550 HASH=$(promise_and_delete $TREE_HASH) &&
552 git -C repo config core.repositoryformatversion 1 &&
553 git -C repo config extensions.partialclone "arbitrary string" &&
556 # Ensure that the promisor packfile still exists, and remove it
557 test -e repo/.git/objects/pack/pack-$HASH.pack &&
558 rm repo/.git/objects/pack/pack-$HASH.* &&
560 # Ensure that the single other pack contains the commit, but not the tree
561 ls repo/.git/objects/pack/pack-*.pack >packlist &&
562 test_line_count = 1 packlist &&
563 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
564 grep "$(git -C repo rev-parse HEAD)" out &&
565 ! grep "$TREE_HASH" out
568 test_expect_success 'do not fetch when checking existence of tree we construct ourselves' '
570 test_create_repo repo &&
571 test_commit -C repo base &&
572 test_commit -C repo side1 &&
573 git -C repo checkout base &&
574 test_commit -C repo side2 &&
576 git -C repo config core.repositoryformatversion 1 &&
577 git -C repo config extensions.partialclone "arbitrary string" &&
579 git -C repo cherry-pick side1
582 . "$TEST_DIRECTORY"/lib-httpd.sh
585 test_expect_success 'fetching of missing objects from an HTTP server' '
587 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
588 test_create_repo "$SERVER" &&
589 test_commit -C "$SERVER" foo &&
590 git -C "$SERVER" repack -a -d --write-bitmap-index &&
592 git clone $HTTPD_URL/smart/server repo &&
593 HASH=$(git -C repo rev-parse foo) &&
594 rm -rf repo/.git/objects/* &&
596 git -C repo config core.repositoryformatversion 1 &&
597 git -C repo config extensions.partialclone "origin" &&
598 git -C repo cat-file -p "$HASH" &&
600 # Ensure that the .promisor file is written, and check that its
601 # associated packfile contains the object
602 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
603 test_line_count = 1 promisorlist &&
604 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
605 git verify-pack --verbose "$IDX" >out &&
609 # DO NOT add non-httpd-specific tests here, because the last part of this
610 # test script is only executed when httpd is available and enabled.