3 test_description
='git partial clone'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 # create a normal "src" repo where we can later create new commits.
12 # expect_1.oids will contain a list of the OIDs of all blobs.
13 test_expect_success
'setup normal src repo' '
14 echo "{print \$1}" >print_1.awk &&
15 echo "{print \$2}" >print_2.awk &&
20 echo "This is file: $n" > src/file.$n.txt &&
21 git -C src add file.$n.txt &&
22 git -C src commit -m "file $n" &&
23 git -C src ls-files -s file.$n.txt >>temp || return 1
25 awk -f print_2.awk <temp | sort >expect_1.oids &&
26 test_line_count = 4 expect_1.oids
29 # bare clone "src" giving "srv.bare" for use as our server.
30 test_expect_success
'setup bare clone for server' '
31 git clone --bare "file://$(pwd)/src" srv.bare &&
32 git -C srv.bare config --local uploadpack.allowfilter 1 &&
33 git -C srv.bare config --local uploadpack.allowanysha1inwant 1
36 # do basic partial clone from "srv.bare"
37 # confirm we are missing all of the known blobs.
38 # confirm partial clone was registered in the local config.
39 test_expect_success
'do partial clone 1' '
40 git clone --no-checkout --filter=blob:none "file://$(pwd)/srv.bare" pc1 &&
42 git -C pc1 rev-list --quiet --objects --missing=print HEAD >revs &&
43 awk -f print_1.awk revs |
45 sort >observed.oids &&
47 test_cmp expect_1.oids observed.oids &&
48 test "$(git -C pc1 config --local core.repositoryformatversion)" = "1" &&
49 test "$(git -C pc1 config --local remote.origin.promisor)" = "true" &&
50 test "$(git -C pc1 config --local remote.origin.partialclonefilter)" = "blob:none"
53 test_expect_success
'rev-list --missing=allow-promisor on partial clone' '
54 git -C pc1 rev-list --objects --missing=allow-promisor HEAD >actual &&
55 git -C pc1 rev-list --objects --missing=print HEAD >expect.raw &&
56 grep -v "^?" expect.raw >expect &&
57 test_cmp expect actual
60 test_expect_success
'verify that .promisor file contains refs fetched' '
61 ls pc1/.git/objects/pack/pack-*.promisor >promisorlist &&
62 test_line_count = 1 promisorlist &&
63 git -C srv.bare rev-parse --verify HEAD >headhash &&
64 grep "$(cat headhash) HEAD" $(cat promisorlist) &&
65 grep "$(cat headhash) refs/heads/main" $(cat promisorlist)
68 # checkout main to force dynamic object fetch of blobs at HEAD.
69 test_expect_success
'verify checkout with dynamic object fetch' '
70 git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&
71 test_line_count = 4 observed &&
72 git -C pc1 checkout main &&
73 git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&
74 test_line_count = 0 observed
77 # create new commits in "src" repo to establish a blame history on file.1.txt
78 # and push to "srv.bare".
79 test_expect_success
'push new commits to server' '
80 git -C src remote add srv "file://$(pwd)/srv.bare" &&
83 echo "Mod file.1.txt $x" >>src/file.1.txt &&
84 git -C src add file.1.txt &&
85 git -C src commit -m "mod $x" || return 1
87 git -C src blame main -- file.1.txt >expect.blame &&
88 git -C src push -u srv main
91 # (partial) fetch in the partial clone repo from the promisor remote.
92 # verify that fetch inherited the filter-spec from the config and DOES NOT
94 test_expect_success
'partial fetch inherits filter settings' '
95 git -C pc1 fetch origin &&
96 git -C pc1 rev-list --quiet --objects --missing=print \
97 main..origin/main >observed &&
98 test_line_count = 5 observed
101 # force dynamic object fetch using diff.
102 # we should only get 1 new blob (for the file in origin/main).
103 test_expect_success
'verify diff causes dynamic object fetch' '
104 git -C pc1 diff main..origin/main -- file.1.txt &&
105 git -C pc1 rev-list --quiet --objects --missing=print \
106 main..origin/main >observed &&
107 test_line_count = 4 observed
110 # force full dynamic object fetch of the file's history using blame.
111 # we should get the intermediate blobs for the file.
112 test_expect_success
'verify blame causes dynamic object fetch' '
113 git -C pc1 blame origin/main -- file.1.txt >observed.blame &&
114 test_cmp expect.blame observed.blame &&
115 git -C pc1 rev-list --quiet --objects --missing=print \
116 main..origin/main >observed &&
117 test_line_count = 0 observed
120 # create new commits in "src" repo to establish a history on file.2.txt
121 # and push to "srv.bare".
122 test_expect_success
'push new commits to server for file.2.txt' '
125 echo "Mod file.2.txt $x" >>src/file.2.txt &&
126 git -C src add file.2.txt &&
127 git -C src commit -m "mod $x" || return 1
129 git -C src push -u srv main
132 # Do FULL fetch by disabling inherited filter-spec using --no-filter.
133 # Verify we have all the new blobs.
134 test_expect_success
'override inherited filter-spec using --no-filter' '
135 git -C pc1 fetch --no-filter origin &&
136 git -C pc1 rev-list --quiet --objects --missing=print \
137 main..origin/main >observed &&
138 test_line_count = 0 observed
141 # create new commits in "src" repo to establish a history on file.3.txt
142 # and push to "srv.bare".
143 test_expect_success
'push new commits to server for file.3.txt' '
146 echo "Mod file.3.txt $x" >>src/file.3.txt &&
147 git -C src add file.3.txt &&
148 git -C src commit -m "mod $x" || return 1
150 git -C src push -u srv main
153 # Do a partial fetch and then try to manually fetch the missing objects.
154 # This can be used as the basis of a pre-command hook to bulk fetch objects
155 # perhaps combined with a command in dry-run mode.
156 test_expect_success
'manual prefetch of missing objects' '
157 git -C pc1 fetch --filter=blob:none origin &&
159 git -C pc1 rev-list --quiet --objects --missing=print \
160 main..origin/main >revs &&
161 awk -f print_1.awk revs |
163 sort >observed.oids &&
165 test_line_count = 6 observed.oids &&
166 git -C pc1 fetch-pack --stdin "file://$(pwd)/srv.bare" <observed.oids &&
168 git -C pc1 rev-list --quiet --objects --missing=print \
169 main..origin/main >revs &&
170 awk -f print_1.awk revs |
172 sort >observed.oids &&
174 test_line_count = 0 observed.oids
177 # create new commits in "src" repo to establish a history on file.4.txt
178 # and push to "srv.bare".
179 test_expect_success
'push new commits to server for file.4.txt' '
182 echo "Mod file.4.txt $x" >src/file.4.txt &&
183 if list_contains "a,b" "$x"; then
184 printf "%10000s" X >>src/file.4.txt
186 if list_contains "c,d" "$x"; then
187 printf "%20000s" X >>src/file.4.txt
189 git -C src add file.4.txt &&
190 git -C src commit -m "mod $x" || return 1
192 git -C src push -u srv main
195 # Do partial fetch to fetch smaller files; then verify that without --refetch
196 # applying a new filter does not refetch missing large objects. Then use
197 # --refetch to apply the new filter on existing commits. Test it under both
199 test_expect_success
'apply a different filter using --refetch' '
200 git -C pc1 fetch --filter=blob:limit=999 origin &&
201 git -C pc1 rev-list --quiet --objects --missing=print \
202 main..origin/main >observed &&
203 test_line_count = 4 observed &&
205 git -C pc1 fetch --filter=blob:limit=19999 --refetch origin &&
206 git -C pc1 rev-list --quiet --objects --missing=print \
207 main..origin/main >observed &&
208 test_line_count = 2 observed &&
210 git -c protocol.version=0 -C pc1 fetch --filter=blob:limit=29999 \
212 git -C pc1 rev-list --quiet --objects --missing=print \
213 main..origin/main >observed &&
214 test_line_count = 0 observed
217 test_expect_success
'fetch --refetch works with a shallow clone' '
218 git clone --no-checkout --depth=1 --filter=blob:none "file://$(pwd)/srv.bare" pc1s &&
219 git -C pc1s rev-list --objects --missing=print HEAD >observed &&
220 test_line_count = 6 observed &&
222 GIT_TRACE=1 git -C pc1s fetch --filter=blob:limit=999 --refetch origin &&
223 git -C pc1s rev-list --objects --missing=print HEAD >observed &&
224 test_line_count = 6 observed
227 test_expect_success
'fetch --refetch triggers repacking' '
228 GIT_TRACE2_CONFIG_PARAMS=gc.autoPackLimit,maintenance.incremental-repack.auto &&
229 export GIT_TRACE2_CONFIG_PARAMS &&
231 GIT_TRACE2_EVENT="$PWD/trace1.event" \
232 git -C pc1 fetch --refetch origin &&
233 test_subcommand git maintenance run --auto --no-quiet --detach <trace1.event &&
234 grep \"param\":\"gc.autopacklimit\",\"value\":\"1\" trace1.event &&
235 grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"-1\" trace1.event &&
237 GIT_TRACE2_EVENT="$PWD/trace2.event" \
238 git -c protocol.version=0 \
239 -c gc.autoPackLimit=0 \
240 -c maintenance.incremental-repack.auto=1234 \
241 -C pc1 fetch --refetch origin &&
242 test_subcommand git maintenance run --auto --no-quiet --detach <trace2.event &&
243 grep \"param\":\"gc.autopacklimit\",\"value\":\"0\" trace2.event &&
244 grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"-1\" trace2.event &&
246 GIT_TRACE2_EVENT="$PWD/trace3.event" \
247 git -c protocol.version=0 \
248 -c gc.autoPackLimit=1234 \
249 -c maintenance.incremental-repack.auto=0 \
250 -C pc1 fetch --refetch origin &&
251 test_subcommand git maintenance run --auto --no-quiet --detach <trace3.event &&
252 grep \"param\":\"gc.autopacklimit\",\"value\":\"1\" trace3.event &&
253 grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"0\" trace3.event
256 test_expect_success
'partial clone with transfer.fsckobjects=1 works with submodules' '
257 test_create_repo submodule &&
258 test_commit -C submodule mycommit &&
260 test_create_repo src_with_sub &&
261 git -C src_with_sub config uploadpack.allowfilter 1 &&
262 git -C src_with_sub config uploadpack.allowanysha1inwant 1 &&
264 test_config_global protocol.file.allow always &&
266 git -C src_with_sub submodule add "file://$(pwd)/submodule" mysub &&
267 git -C src_with_sub commit -m "commit with submodule" &&
269 git -c transfer.fsckobjects=1 \
270 clone --filter="blob:none" "file://$(pwd)/src_with_sub" dst &&
271 test_when_finished rm -rf dst
274 test_expect_success
'lazily fetched .gitmodules works' '
275 git clone --filter="blob:none" --no-checkout "file://$(pwd)/src_with_sub" dst &&
277 test_when_finished rm -rf dst
280 test_expect_success
'partial clone with transfer.fsckobjects=1 uses index-pack --fsck-objects' '
282 test_commit -C src x &&
283 test_config -C src uploadpack.allowfilter 1 &&
284 test_config -C src uploadpack.allowanysha1inwant 1 &&
286 GIT_TRACE="$(pwd)/trace" git -c transfer.fsckobjects=1 \
287 clone --filter="blob:none" "file://$(pwd)/src" dst &&
288 grep "git index-pack.*--fsck-objects" trace
291 test_expect_success
'use fsck before and after manually fetching a missing subtree' '
292 # push new commit so server has a subtree
294 echo "in dir" >src/dir/file.txt &&
295 git -C src add dir/file.txt &&
296 git -C src commit -m "file in dir" &&
297 git -C src push -u srv main &&
298 SUBTREE=$(git -C src rev-parse HEAD:dir) &&
301 git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" dst &&
304 # Make sure we only have commits, and all trees and blobs are missing.
305 git -C dst rev-list --missing=allow-any --objects main \
307 awk -f print_1.awk fetched_objects |
308 xargs -n1 git -C dst cat-file -t >fetched_types &&
310 sort -u fetched_types >unique_types.observed &&
311 echo commit >unique_types.expected &&
312 test_cmp unique_types.expected unique_types.observed &&
314 # Auto-fetch a tree with cat-file.
315 git -C dst cat-file -p $SUBTREE >tree_contents &&
316 grep file.txt tree_contents &&
318 # fsck still works after an auto-fetch of a tree.
321 # Auto-fetch all remaining trees and blobs with --missing=error
322 git -C dst rev-list --missing=error --objects main >fetched_objects &&
323 test_line_count = 88 fetched_objects &&
325 awk -f print_1.awk fetched_objects |
326 xargs -n1 git -C dst cat-file -t >fetched_types &&
328 sort -u fetched_types >unique_types.observed &&
329 test_write_lines blob commit tree >unique_types.expected &&
330 test_cmp unique_types.expected unique_types.observed
333 test_expect_success
'implicitly construct combine: filter with repeated flags' '
334 GIT_TRACE=$(pwd)/trace git clone --bare \
335 --filter=blob:none --filter=tree:1 \
336 "file://$(pwd)/srv.bare" pc2 &&
337 grep "trace:.* git pack-objects .*--filter=combine:blob:none+tree:1" \
339 git -C pc2 rev-list --objects --missing=allow-any HEAD >objects &&
341 # We should have gotten some root trees.
343 # Should not have gotten any non-root trees or blobs.
344 ! grep " ." objects &&
346 xargs -n 1 git -C pc2 cat-file -t <objects >types &&
347 sort -u types >unique_types.actual &&
348 test_write_lines commit tree >unique_types.expected &&
349 test_cmp unique_types.expected unique_types.actual
352 test_expect_success
'upload-pack complains of bogus filter config' '
355 -c uploadpackfilter.tree.maxdepth \
356 upload-pack . >/dev/null 2>err &&
357 test_grep "unable to parse.*tree.maxdepth" err
360 test_expect_success
'upload-pack fails banned object filters' '
361 test_config -C srv.bare uploadpackfilter.blob:none.allow false &&
362 test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \
363 "file://$(pwd)/srv.bare" pc3 2>err &&
364 test_grep "filter '\''blob:none'\'' not supported" err
367 test_expect_success
'upload-pack fails banned combine object filters' '
368 test_config -C srv.bare uploadpackfilter.allow false &&
369 test_config -C srv.bare uploadpackfilter.combine.allow true &&
370 test_config -C srv.bare uploadpackfilter.tree.allow true &&
371 test_config -C srv.bare uploadpackfilter.blob:none.allow false &&
372 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \
373 --filter=blob:none "file://$(pwd)/srv.bare" pc3 2>err &&
374 test_grep "filter '\''blob:none'\'' not supported" err
377 test_expect_success
'upload-pack fails banned object filters with fallback' '
378 test_config -C srv.bare uploadpackfilter.allow false &&
379 test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \
380 "file://$(pwd)/srv.bare" pc3 2>err &&
381 test_grep "filter '\''blob:none'\'' not supported" err
384 test_expect_success
'upload-pack limits tree depth filters' '
385 test_config -C srv.bare uploadpackfilter.allow false &&
386 test_config -C srv.bare uploadpackfilter.tree.allow true &&
387 test_config -C srv.bare uploadpackfilter.tree.maxDepth 0 &&
388 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \
389 "file://$(pwd)/srv.bare" pc3 2>err &&
390 test_grep "tree filter allows max depth 0, but got 1" err &&
392 git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" pc4 &&
394 test_config -C srv.bare uploadpackfilter.tree.maxDepth 5 &&
395 git clone --no-checkout --filter=tree:5 "file://$(pwd)/srv.bare" pc5 &&
396 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:6 \
397 "file://$(pwd)/srv.bare" pc6 2>err &&
398 test_grep "tree filter allows max depth 5, but got 6" err
401 test_expect_success
'partial clone fetches blobs pointed to by refs even if normally filtered out' '
404 test_commit -C src x &&
405 test_config -C src uploadpack.allowfilter 1 &&
406 test_config -C src uploadpack.allowanysha1inwant 1 &&
408 # Create a tag pointing to a blob.
409 BLOB=$(echo blob-contents | git -C src hash-object --stdin -w) &&
410 git -C src tag myblob "$BLOB" &&
412 git clone --filter="blob:none" "file://$(pwd)/src" dst 2>err &&
413 ! grep "does not point to a valid object" err &&
417 test_expect_success
'fetch what is specified on CLI even if already promised' '
418 rm -rf src dst.git &&
420 test_commit -C src foo &&
421 test_config -C src uploadpack.allowfilter 1 &&
422 test_config -C src uploadpack.allowanysha1inwant 1 &&
424 git hash-object --stdin <src/foo.t >blob &&
426 git clone --bare --filter=blob:none "file://$(pwd)/src" dst.git &&
427 git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_before &&
428 grep "?$(cat blob)" missing_before &&
429 git -C dst.git fetch origin $(cat blob) &&
430 git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_after &&
431 ! grep "?$(cat blob)" missing_after
434 test_expect_success
'setup src repo for sparse filter' '
435 git init sparse-src &&
436 git -C sparse-src config --local uploadpack.allowfilter 1 &&
437 git -C sparse-src config --local uploadpack.allowanysha1inwant 1 &&
438 test_commit -C sparse-src one &&
439 test_commit -C sparse-src two &&
440 echo /one.t >sparse-src/only-one &&
441 git -C sparse-src add . &&
442 git -C sparse-src commit -m "add sparse checkout files"
445 test_expect_success
'partial clone with sparse filter succeeds' '
447 git clone --no-local --bare \
448 --filter=sparse:oid=main:only-one \
449 sparse-src dst.git &&
452 git rev-list --objects --missing=print HEAD >out &&
453 grep "^$(git rev-parse HEAD:one.t)" out &&
454 grep "^?$(git rev-parse HEAD:two.t)" out
458 test_expect_success
'partial clone with unresolvable sparse filter fails cleanly' '
460 test_must_fail git clone --no-local --bare \
461 --filter=sparse:oid=main:no-such-name \
462 sparse-src dst.git 2>err &&
463 test_grep "unable to access sparse blob in .main:no-such-name" err &&
464 test_must_fail git clone --no-local --bare \
465 --filter=sparse:oid=main \
466 sparse-src dst.git 2>err &&
467 test_grep "unable to parse sparse filter data in" err
471 rm -rf big-blob.txt server client promisor-remote
&&
473 printf "line %d\n" $
(test_seq
1 100) >big-blob.txt
&&
475 # Create a server with 2 commits: a commit with a big tree and a child
476 # commit with an incremental change. Also, create a partial clone
477 # client that only contains the first commit.
479 git
-C server config
--local uploadpack.allowfilter
1 &&
480 for i
in $
(test_seq
1 100)
482 echo "make the tree big" >server
/file$i &&
483 git
-C server add
file$i ||
return 1
485 git
-C server commit
-m "initial" &&
486 git clone
--bare --filter=tree
:0 "file://$(pwd)/server" client
&&
487 echo another line
>>server
/file1
&&
488 git
-C server commit
-am "incremental change" &&
490 # Create a promisor remote that only contains the tree and blob from
492 git init promisor-remote
&&
493 git
-C server config
--local uploadpack.allowanysha1inwant
1 &&
494 TREE_HASH
=$
(git
-C server rev-parse HEAD~
1^
{tree
}) &&
495 git
-C promisor-remote fetch
--keep "file://$(pwd)/server" "$TREE_HASH" &&
496 git
-C promisor-remote count-objects
-v >object-count
&&
497 test_grep
"count: 0" object-count
&&
498 test_grep
"in-pack: 2" object-count
&&
500 # Set it as the promisor remote of client. Thus, whenever
501 # the client lazy fetches, the lazy fetch will succeed only if it is
502 # for this tree or blob.
503 test_commit
-C promisor-remote one
&& # so that ref advertisement is not empty
504 git
-C promisor-remote config
--local uploadpack.allowanysha1inwant
1 &&
505 git
-C client remote set-url origin
"file://$(pwd)/promisor-remote"
508 # NEEDSWORK: The tests beginning with "fetch lazy-fetches" below only
509 # test that "fetch" avoid fetching trees and blobs, but not commits or
510 # tags. Revisit this if Git is ever taught to support partial clones
511 # with commits and/or tags filtered out.
513 test_expect_success
'fetch lazy-fetches only to resolve deltas' '
516 # Exercise to make sure it works. Git will not fetch anything from the
517 # promisor remote other than for the big tree (because it needs to
518 # resolve the delta).
519 GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
520 fetch "file://$(pwd)/server" main &&
522 # Verify the assumption that the client needed to fetch the delta base
523 # to resolve the delta.
524 git -C server rev-parse HEAD~1^{tree} >hash &&
525 grep "want $(cat hash)" trace
528 test_expect_success
'fetch lazy-fetches only to resolve deltas, protocol v2' '
531 git -C server config --local protocol.version 2 &&
532 git -C client config --local protocol.version 2 &&
533 git -C promisor-remote config --local protocol.version 2 &&
535 # Exercise to make sure it works. Git will not fetch anything from the
536 # promisor remote other than for the big blob (because it needs to
537 # resolve the delta).
538 GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
539 fetch "file://$(pwd)/server" main &&
541 # Verify that protocol version 2 was used.
542 grep "fetch< version 2" trace &&
544 # Verify the assumption that the client needed to fetch the delta base
545 # to resolve the delta.
546 git -C server rev-parse HEAD~1^{tree} >hash &&
547 grep "want $(cat hash)" trace
550 test_expect_success
'fetch does not lazy-fetch missing targets of its refs' '
551 rm -rf server client trace &&
553 test_create_repo server &&
554 test_config -C server uploadpack.allowfilter 1 &&
555 test_config -C server uploadpack.allowanysha1inwant 1 &&
556 test_commit -C server foo &&
558 git clone --filter=blob:none "file://$(pwd)/server" client &&
559 # Make all refs point to nothing by deleting all objects.
560 rm client/.git/objects/pack/* &&
562 test_commit -C server bar &&
563 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
564 --no-tags --recurse-submodules=no \
565 origin refs/tags/bar &&
566 FOO_HASH=$(git -C server rev-parse foo) &&
567 ! grep "want $FOO_HASH" trace
570 # The following two tests must be in this order. It is important that
571 # the srv.bare repository did not have tags during clone, but has tags
574 test_expect_success
'verify fetch succeeds when asking for new tags' '
575 git clone --filter=blob:none "file://$(pwd)/srv.bare" tag-test &&
578 test_commit -C src $i &&
579 git -C src branch $i || return 1
581 git -C srv.bare fetch --tags origin +refs/heads/*:refs/heads/* &&
582 git -C tag-test -c protocol.version=2 fetch --tags origin
585 test_expect_success
'verify fetch downloads only one pack when updating refs' '
586 git clone --filter=blob:none "file://$(pwd)/srv.bare" pack-test &&
587 ls pack-test/.git/objects/pack/*pack >pack-list &&
588 test_line_count = 2 pack-list &&
591 test_commit -C src $i &&
592 git -C src branch $i || return 1
594 git -C srv.bare fetch origin +refs/heads/*:refs/heads/* &&
595 git -C pack-test fetch origin &&
596 ls pack-test/.git/objects/pack/*pack >pack-list &&
597 test_line_count = 3 pack-list
600 test_expect_success
'single-branch tag following respects partial clone' '
601 git clone --single-branch -b B --filter=blob:none \
602 "file://$(pwd)/srv.bare" single &&
603 git -C single rev-parse --verify refs/tags/B &&
604 git -C single rev-parse --verify refs/tags/A &&
605 test_must_fail git -C single rev-parse --verify refs/tags/C
608 test_expect_success
'fetch from a partial clone, protocol v0' '
609 rm -rf server client trace &&
611 # Pretend that the server is a partial clone
613 git -C server remote add a_remote "file://$(pwd)/" &&
614 test_config -C server core.repositoryformatversion 1 &&
615 test_config -C server extensions.partialclone a_remote &&
616 test_config -C server protocol.version 0 &&
617 test_commit -C server foo &&
619 # Fetch from the server
621 test_config -C client protocol.version 0 &&
622 test_commit -C client bar &&
623 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" &&
624 ! grep "version 2" trace
627 test_expect_success
'fetch from a partial clone, protocol v2' '
628 rm -rf server client trace &&
630 # Pretend that the server is a partial clone
632 git -C server remote add a_remote "file://$(pwd)/" &&
633 test_config -C server core.repositoryformatversion 1 &&
634 test_config -C server extensions.partialclone a_remote &&
635 test_config -C server protocol.version 2 &&
636 test_commit -C server foo &&
638 # Fetch from the server
640 test_config -C client protocol.version 2 &&
641 test_commit -C client bar &&
642 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" &&
643 grep "version 2" trace
646 test_expect_success
'repack does not loosen promisor objects' '
647 rm -rf client trace &&
648 git clone --bare --filter=blob:none "file://$(pwd)/srv.bare" client &&
649 test_when_finished "rm -rf client trace" &&
650 GIT_TRACE2_PERF="$(pwd)/trace" git -C client repack -A -d &&
651 grep "loosen_unused_packed_objects/loosened:0" trace
654 test_expect_success
'lazy-fetch in submodule succeeds' '
656 test_config_global protocol.file.allow always &&
658 test_when_finished "rm -rf src-sub" &&
660 git -C src-sub config uploadpack.allowfilter 1 &&
661 git -C src-sub config uploadpack.allowanysha1inwant 1 &&
663 # This blob must be missing in the subsequent commit.
664 echo foo >src-sub/file &&
665 git -C src-sub add file &&
666 git -C src-sub commit -m "submodule one" &&
667 SUB_ONE=$(git -C src-sub rev-parse HEAD) &&
669 echo bar >src-sub/file &&
670 git -C src-sub add file &&
671 git -C src-sub commit -m "submodule two" &&
672 SUB_TWO=$(git -C src-sub rev-parse HEAD) &&
674 test_when_finished "rm -rf src-super" &&
675 git init src-super &&
676 git -C src-super config uploadpack.allowfilter 1 &&
677 git -C src-super config uploadpack.allowanysha1inwant 1 &&
678 git -C src-super submodule add ../src-sub src-sub &&
680 git -C src-super/src-sub checkout $SUB_ONE &&
681 git -C src-super add src-sub &&
682 git -C src-super commit -m "superproject one" &&
684 git -C src-super/src-sub checkout $SUB_TWO &&
685 git -C src-super add src-sub &&
686 git -C src-super commit -m "superproject two" &&
689 test_when_finished "rm -rf client" &&
690 git clone --filter=blob:none --also-filter-submodules \
691 --recurse-submodules "file://$(pwd)/src-super" client &&
693 # Trigger lazy-fetch from the superproject
694 git -C client restore --recurse-submodules --source=HEAD^ :/
697 test_expect_success
'after fetching descendants of non-promisor commits, gc works' '
700 git -C full config uploadpack.allowfilter 1 &&
701 git -C full config uploadpack.allowanysha1inwant 1 &&
703 git -C full add foo &&
704 git -C full commit -m "commit 1" &&
705 git -C full checkout --detach &&
707 # Partial clone and push commit to remote
708 git clone "file://$(pwd)/full" --filter=blob:none partial &&
709 echo "hello" > partial/foo &&
710 git -C partial commit -a -m "commit 2" &&
711 git -C partial push &&
714 git -C partial gc --prune=now &&
716 # Create another commit in normal repo
717 git -C full checkout main &&
718 echo " world" >> full/foo &&
719 git -C full commit -a -m "commit 3" &&
721 # Pull from remote in partial repo, and run gc again
722 git -C partial pull &&
723 git -C partial gc --prune=now
727 .
"$TEST_DIRECTORY"/lib-httpd.sh
730 # Converts bytes into their hexadecimal representation. For example,
731 # "printf 'ab\r\n' | hex_unpack" results in '61620d0a'.
733 perl
-e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)'
736 # Inserts $1 at the start of the string and every 2 characters thereafter.
738 sed 's/\(..\)/'$1'\1/g'
741 # Create a one-time-perl command to replace the existing packfile with $1.
742 replace_packfile
() {
743 # The protocol requires that the packfile be sent in sideband 1, hence
744 # the extra \x01 byte at the beginning.
745 cp $1 "$HTTPD_ROOT_PATH/one-time-pack" &&
746 echo 'if (/packfile/) {
748 my $length = -s "one-time-pack";
749 printf "%04x\x01", $length + 5;
750 print `cat one-time-pack` . "0000";
752 }' >"$HTTPD_ROOT_PATH/one-time-perl"
755 test_expect_success
'upon cloning, check that all refs point to objects' '
756 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
757 rm -rf "$SERVER" repo &&
758 test_create_repo "$SERVER" &&
759 test_commit -C "$SERVER" foo &&
760 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
761 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
763 # Create a tag pointing to a blob.
764 BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
765 git -C "$SERVER" tag myblob "$BLOB" &&
767 # Craft a packfile not including that blob.
768 git -C "$SERVER" rev-parse HEAD |
769 git -C "$SERVER" pack-objects --stdout >incomplete.pack &&
771 # Replace the existing packfile with the crafted one. The protocol
772 # requires that the packfile be sent in sideband 1, hence the extra
773 # \x01 byte at the beginning.
774 replace_packfile incomplete.pack &&
776 # Use protocol v2 because the perl command looks for the "packfile"
778 test_config -C "$SERVER" protocol.version 2 &&
779 test_must_fail git -c protocol.version=2 clone \
780 --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2>err &&
782 test_grep "did not send all necessary objects" err &&
784 # Ensure that the one-time-perl script was used.
785 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
788 test_expect_success
'when partial cloning, tolerate server not sending target of tag' '
789 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
790 rm -rf "$SERVER" repo &&
791 test_create_repo "$SERVER" &&
792 test_commit -C "$SERVER" foo &&
793 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
794 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
796 # Create an annotated tag pointing to a blob.
797 BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
798 git -C "$SERVER" tag -m message -a myblob "$BLOB" &&
800 # Craft a packfile including the tag, but not the blob it points to.
801 # Also, omit objects referenced from HEAD in order to force a second
802 # fetch (to fetch missing objects) upon the automatic checkout that
803 # happens after a clone.
804 printf "%s\n%s\n--not\n%s\n%s\n" \
805 $(git -C "$SERVER" rev-parse HEAD) \
806 $(git -C "$SERVER" rev-parse myblob) \
807 $(git -C "$SERVER" rev-parse HEAD^{tree}) \
808 $(git -C "$SERVER" rev-parse myblob^{blob}) |
809 git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack &&
811 # Replace the existing packfile with the crafted one. The protocol
812 # requires that the packfile be sent in sideband 1, hence the extra
813 # \x01 byte at the beginning.
814 replace_packfile incomplete.pack &&
816 # Use protocol v2 because the perl command looks for the "packfile"
818 test_config -C "$SERVER" protocol.version 2 &&
820 # Exercise to make sure it works.
821 git -c protocol.version=2 clone \
822 --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2> err &&
823 ! grep "missing object referenced by" err &&
825 # Ensure that the one-time-perl script was used.
826 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
829 test_expect_success
'tolerate server sending REF_DELTA against missing promisor objects' '
830 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
831 rm -rf "$SERVER" repo &&
832 test_create_repo "$SERVER" &&
833 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
834 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
836 # Create a commit with 2 blobs to be used as delta bases.
837 for i in $(test_seq 10)
839 echo "this is a line" >>"$SERVER/foo.txt" &&
840 echo "this is another line" >>"$SERVER/have.txt" || return 1
842 git -C "$SERVER" add foo.txt have.txt &&
843 git -C "$SERVER" commit -m bar &&
844 git -C "$SERVER" rev-parse HEAD:foo.txt >deltabase_missing &&
845 git -C "$SERVER" rev-parse HEAD:have.txt >deltabase_have &&
847 # Clone. The client has deltabase_have but not deltabase_missing.
848 git -c protocol.version=2 clone --no-checkout \
849 --filter=blob:none $HTTPD_URL/one_time_perl/server repo &&
850 git -C repo hash-object -w -- "$SERVER/have.txt" &&
852 # Sanity check to ensure that the client does not have
854 git -C repo rev-list --objects --ignore-missing \
855 -- $(cat deltabase_missing) >objlist &&
856 test_line_count = 0 objlist &&
858 # Another commit. This commit will be fetched by the client.
859 echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/foo.txt" &&
860 echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/have.txt" &&
861 git -C "$SERVER" add foo.txt have.txt &&
862 git -C "$SERVER" commit -m baz &&
864 # Pack a thin pack containing, among other things, HEAD:foo.txt
865 # delta-ed against HEAD^:foo.txt and HEAD:have.txt delta-ed against
867 printf "%s\n--not\n%s\n" \
868 $(git -C "$SERVER" rev-parse HEAD) \
869 $(git -C "$SERVER" rev-parse HEAD^) |
870 git -C "$SERVER" pack-objects --thin --stdout >thin.pack &&
872 # Ensure that the pack contains one delta against HEAD^:foo.txt. Since
873 # the delta contains at least 26 novel characters, the size cannot be
874 # contained in 4 bits, so the object header will take up 2 bytes. The
875 # most significant nybble of the first byte is 0b1111 (0b1 to indicate
876 # that the header continues, and 0b111 to indicate REF_DELTA), followed
877 # by any 3 nybbles, then the OID of the delta base.
878 printf "f.,..%s" $(intersperse "," <deltabase_missing) >want &&
879 hex_unpack <thin.pack | intersperse "," >have &&
880 grep $(cat want) have &&
882 # Ensure that the pack contains one delta against HEAD^:have.txt,
883 # similar to the above.
884 printf "f.,..%s" $(intersperse "," <deltabase_have) >want &&
885 hex_unpack <thin.pack | intersperse "," >have &&
886 grep $(cat want) have &&
888 replace_packfile thin.pack &&
890 # Use protocol v2 because the perl command looks for the "packfile"
892 test_config -C "$SERVER" protocol.version 2 &&
894 # Fetch the thin pack and ensure that index-pack is able to handle the
895 # REF_DELTA object with a missing promisor delta base.
896 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo -c protocol.version=2 fetch &&
898 # Ensure that the missing delta base was directly fetched, but not the
899 # one that the client has.
900 grep "want $(cat deltabase_missing)" trace &&
901 ! grep "want $(cat deltabase_have)" trace &&
903 # Ensure that the one-time-perl script was used.
904 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
907 # DO NOT add non-httpd-specific tests here, because the last part of this
908 # test script is only executed when httpd is available and enabled.