3 test_description
='git partial clone'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 # create a normal "src" repo where we can later create new commits.
11 # expect_1.oids will contain a list of the OIDs of all blobs.
12 test_expect_success
'setup normal src repo' '
13 echo "{print \$1}" >print_1.awk &&
14 echo "{print \$2}" >print_2.awk &&
19 echo "This is file: $n" > src/file.$n.txt
20 git -C src add file.$n.txt
21 git -C src commit -m "file $n"
22 git -C src ls-files -s file.$n.txt >>temp
24 awk -f print_2.awk <temp | sort >expect_1.oids &&
25 test_line_count = 4 expect_1.oids
28 # bare clone "src" giving "srv.bare" for use as our server.
29 test_expect_success
'setup bare clone for server' '
30 git clone --bare "file://$(pwd)/src" srv.bare &&
31 git -C srv.bare config --local uploadpack.allowfilter 1 &&
32 git -C srv.bare config --local uploadpack.allowanysha1inwant 1
35 # do basic partial clone from "srv.bare"
36 # confirm we are missing all of the known blobs.
37 # confirm partial clone was registered in the local config.
38 test_expect_success
'do partial clone 1' '
39 git clone --no-checkout --filter=blob:none "file://$(pwd)/srv.bare" pc1 &&
41 git -C pc1 rev-list --quiet --objects --missing=print HEAD >revs &&
42 awk -f print_1.awk revs |
44 sort >observed.oids &&
46 test_cmp expect_1.oids observed.oids &&
47 test "$(git -C pc1 config --local core.repositoryformatversion)" = "1" &&
48 test "$(git -C pc1 config --local remote.origin.promisor)" = "true" &&
49 test "$(git -C pc1 config --local remote.origin.partialclonefilter)" = "blob:none"
52 test_expect_success
'verify that .promisor file contains refs fetched' '
53 ls pc1/.git/objects/pack/pack-*.promisor >promisorlist &&
54 test_line_count = 1 promisorlist &&
55 git -C srv.bare rev-parse --verify HEAD >headhash &&
56 grep "$(cat headhash) HEAD" $(cat promisorlist) &&
57 grep "$(cat headhash) refs/heads/main" $(cat promisorlist)
60 # checkout main to force dynamic object fetch of blobs at HEAD.
61 test_expect_success
'verify checkout with dynamic object fetch' '
62 git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&
63 test_line_count = 4 observed &&
64 git -C pc1 checkout main &&
65 git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&
66 test_line_count = 0 observed
69 # create new commits in "src" repo to establish a blame history on file.1.txt
70 # and push to "srv.bare".
71 test_expect_success
'push new commits to server' '
72 git -C src remote add srv "file://$(pwd)/srv.bare" &&
75 echo "Mod file.1.txt $x" >>src/file.1.txt
76 git -C src add file.1.txt
77 git -C src commit -m "mod $x"
79 git -C src blame main -- file.1.txt >expect.blame &&
80 git -C src push -u srv main
83 # (partial) fetch in the partial clone repo from the promisor remote.
84 # verify that fetch inherited the filter-spec from the config and DOES NOT
86 test_expect_success
'partial fetch inherits filter settings' '
87 git -C pc1 fetch origin &&
88 git -C pc1 rev-list --quiet --objects --missing=print \
89 main..origin/main >observed &&
90 test_line_count = 5 observed
93 # force dynamic object fetch using diff.
94 # we should only get 1 new blob (for the file in origin/main).
95 test_expect_success
'verify diff causes dynamic object fetch' '
96 git -C pc1 diff main..origin/main -- file.1.txt &&
97 git -C pc1 rev-list --quiet --objects --missing=print \
98 main..origin/main >observed &&
99 test_line_count = 4 observed
102 # force full dynamic object fetch of the file's history using blame.
103 # we should get the intermediate blobs for the file.
104 test_expect_success
'verify blame causes dynamic object fetch' '
105 git -C pc1 blame origin/main -- file.1.txt >observed.blame &&
106 test_cmp expect.blame observed.blame &&
107 git -C pc1 rev-list --quiet --objects --missing=print \
108 main..origin/main >observed &&
109 test_line_count = 0 observed
112 # create new commits in "src" repo to establish a history on file.2.txt
113 # and push to "srv.bare".
114 test_expect_success
'push new commits to server for file.2.txt' '
117 echo "Mod file.2.txt $x" >>src/file.2.txt
118 git -C src add file.2.txt
119 git -C src commit -m "mod $x"
121 git -C src push -u srv main
124 # Do FULL fetch by disabling inherited filter-spec using --no-filter.
125 # Verify we have all the new blobs.
126 test_expect_success
'override inherited filter-spec using --no-filter' '
127 git -C pc1 fetch --no-filter origin &&
128 git -C pc1 rev-list --quiet --objects --missing=print \
129 main..origin/main >observed &&
130 test_line_count = 0 observed
133 # create new commits in "src" repo to establish a history on file.3.txt
134 # and push to "srv.bare".
135 test_expect_success
'push new commits to server for file.3.txt' '
138 echo "Mod file.3.txt $x" >>src/file.3.txt
139 git -C src add file.3.txt
140 git -C src commit -m "mod $x"
142 git -C src push -u srv main
145 # Do a partial fetch and then try to manually fetch the missing objects.
146 # This can be used as the basis of a pre-command hook to bulk fetch objects
147 # perhaps combined with a command in dry-run mode.
148 test_expect_success
'manual prefetch of missing objects' '
149 git -C pc1 fetch --filter=blob:none origin &&
151 git -C pc1 rev-list --quiet --objects --missing=print \
152 main..origin/main >revs &&
153 awk -f print_1.awk revs |
155 sort >observed.oids &&
157 test_line_count = 6 observed.oids &&
158 git -C pc1 fetch-pack --stdin "file://$(pwd)/srv.bare" <observed.oids &&
160 git -C pc1 rev-list --quiet --objects --missing=print \
161 main..origin/main >revs &&
162 awk -f print_1.awk revs |
164 sort >observed.oids &&
166 test_line_count = 0 observed.oids
169 test_expect_success
'partial clone with transfer.fsckobjects=1 works with submodules' '
170 test_create_repo submodule &&
171 test_commit -C submodule mycommit &&
173 test_create_repo src_with_sub &&
174 test_config -C src_with_sub uploadpack.allowfilter 1 &&
175 test_config -C src_with_sub uploadpack.allowanysha1inwant 1 &&
177 git -C src_with_sub submodule add "file://$(pwd)/submodule" mysub &&
178 git -C src_with_sub commit -m "commit with submodule" &&
180 git -c transfer.fsckobjects=1 \
181 clone --filter="blob:none" "file://$(pwd)/src_with_sub" dst &&
182 test_when_finished rm -rf dst
185 test_expect_success
'partial clone with transfer.fsckobjects=1 uses index-pack --fsck-objects' '
187 test_commit -C src x &&
188 test_config -C src uploadpack.allowfilter 1 &&
189 test_config -C src uploadpack.allowanysha1inwant 1 &&
191 GIT_TRACE="$(pwd)/trace" git -c transfer.fsckobjects=1 \
192 clone --filter="blob:none" "file://$(pwd)/src" dst &&
193 grep "git index-pack.*--fsck-objects" trace
196 test_expect_success
'use fsck before and after manually fetching a missing subtree' '
197 # push new commit so server has a subtree
199 echo "in dir" >src/dir/file.txt &&
200 git -C src add dir/file.txt &&
201 git -C src commit -m "file in dir" &&
202 git -C src push -u srv main &&
203 SUBTREE=$(git -C src rev-parse HEAD:dir) &&
206 git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" dst &&
209 # Make sure we only have commits, and all trees and blobs are missing.
210 git -C dst rev-list --missing=allow-any --objects main \
212 awk -f print_1.awk fetched_objects |
213 xargs -n1 git -C dst cat-file -t >fetched_types &&
215 sort -u fetched_types >unique_types.observed &&
216 echo commit >unique_types.expected &&
217 test_cmp unique_types.expected unique_types.observed &&
219 # Auto-fetch a tree with cat-file.
220 git -C dst cat-file -p $SUBTREE >tree_contents &&
221 grep file.txt tree_contents &&
223 # fsck still works after an auto-fetch of a tree.
226 # Auto-fetch all remaining trees and blobs with --missing=error
227 git -C dst rev-list --missing=error --objects main >fetched_objects &&
228 test_line_count = 70 fetched_objects &&
230 awk -f print_1.awk fetched_objects |
231 xargs -n1 git -C dst cat-file -t >fetched_types &&
233 sort -u fetched_types >unique_types.observed &&
234 test_write_lines blob commit tree >unique_types.expected &&
235 test_cmp unique_types.expected unique_types.observed
238 test_expect_success
'implicitly construct combine: filter with repeated flags' '
239 GIT_TRACE=$(pwd)/trace git clone --bare \
240 --filter=blob:none --filter=tree:1 \
241 "file://$(pwd)/srv.bare" pc2 &&
242 grep "trace:.* git pack-objects .*--filter=combine:blob:none+tree:1" \
244 git -C pc2 rev-list --objects --missing=allow-any HEAD >objects &&
246 # We should have gotten some root trees.
248 # Should not have gotten any non-root trees or blobs.
249 ! grep " ." objects &&
251 xargs -n 1 git -C pc2 cat-file -t <objects >types &&
252 sort -u types >unique_types.actual &&
253 test_write_lines commit tree >unique_types.expected &&
254 test_cmp unique_types.expected unique_types.actual
257 test_expect_success
'upload-pack complains of bogus filter config' '
260 -c uploadpackfilter.tree.maxdepth \
261 upload-pack . >/dev/null 2>err &&
262 test_i18ngrep "unable to parse.*tree.maxdepth" err
265 test_expect_success
'upload-pack fails banned object filters' '
266 test_config -C srv.bare uploadpackfilter.blob:none.allow false &&
267 test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \
268 "file://$(pwd)/srv.bare" pc3 2>err &&
269 test_i18ngrep "filter '\''blob:none'\'' not supported" err
272 test_expect_success
'upload-pack fails banned combine object filters' '
273 test_config -C srv.bare uploadpackfilter.allow false &&
274 test_config -C srv.bare uploadpackfilter.combine.allow true &&
275 test_config -C srv.bare uploadpackfilter.tree.allow true &&
276 test_config -C srv.bare uploadpackfilter.blob:none.allow false &&
277 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \
278 --filter=blob:none "file://$(pwd)/srv.bare" pc3 2>err &&
279 test_i18ngrep "filter '\''blob:none'\'' not supported" err
282 test_expect_success
'upload-pack fails banned object filters with fallback' '
283 test_config -C srv.bare uploadpackfilter.allow false &&
284 test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \
285 "file://$(pwd)/srv.bare" pc3 2>err &&
286 test_i18ngrep "filter '\''blob:none'\'' not supported" err
289 test_expect_success
'upload-pack limits tree depth filters' '
290 test_config -C srv.bare uploadpackfilter.allow false &&
291 test_config -C srv.bare uploadpackfilter.tree.allow true &&
292 test_config -C srv.bare uploadpackfilter.tree.maxDepth 0 &&
293 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \
294 "file://$(pwd)/srv.bare" pc3 2>err &&
295 test_i18ngrep "tree filter allows max depth 0, but got 1" err &&
297 git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" pc4 &&
299 test_config -C srv.bare uploadpackfilter.tree.maxDepth 5 &&
300 git clone --no-checkout --filter=tree:5 "file://$(pwd)/srv.bare" pc5 &&
301 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:6 \
302 "file://$(pwd)/srv.bare" pc6 2>err &&
303 test_i18ngrep "tree filter allows max depth 5, but got 6" err
306 test_expect_success
'partial clone fetches blobs pointed to by refs even if normally filtered out' '
309 test_commit -C src x &&
310 test_config -C src uploadpack.allowfilter 1 &&
311 test_config -C src uploadpack.allowanysha1inwant 1 &&
313 # Create a tag pointing to a blob.
314 BLOB=$(echo blob-contents | git -C src hash-object --stdin -w) &&
315 git -C src tag myblob "$BLOB" &&
317 git clone --filter="blob:none" "file://$(pwd)/src" dst 2>err &&
318 ! grep "does not point to a valid object" err &&
322 test_expect_success
'fetch what is specified on CLI even if already promised' '
323 rm -rf src dst.git &&
325 test_commit -C src foo &&
326 test_config -C src uploadpack.allowfilter 1 &&
327 test_config -C src uploadpack.allowanysha1inwant 1 &&
329 git hash-object --stdin <src/foo.t >blob &&
331 git clone --bare --filter=blob:none "file://$(pwd)/src" dst.git &&
332 git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_before &&
333 grep "?$(cat blob)" missing_before &&
334 git -C dst.git fetch origin $(cat blob) &&
335 git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_after &&
336 ! grep "?$(cat blob)" missing_after
339 test_expect_success
'setup src repo for sparse filter' '
340 git init sparse-src &&
341 git -C sparse-src config --local uploadpack.allowfilter 1 &&
342 git -C sparse-src config --local uploadpack.allowanysha1inwant 1 &&
343 test_commit -C sparse-src one &&
344 test_commit -C sparse-src two &&
345 echo /one.t >sparse-src/only-one &&
346 git -C sparse-src add . &&
347 git -C sparse-src commit -m "add sparse checkout files"
350 test_expect_success
'partial clone with sparse filter succeeds' '
352 git clone --no-local --bare \
353 --filter=sparse:oid=main:only-one \
354 sparse-src dst.git &&
357 git rev-list --objects --missing=print HEAD >out &&
358 grep "^$(git rev-parse HEAD:one.t)" out &&
359 grep "^?$(git rev-parse HEAD:two.t)" out
363 test_expect_success
'partial clone with unresolvable sparse filter fails cleanly' '
365 test_must_fail git clone --no-local --bare \
366 --filter=sparse:oid=main:no-such-name \
367 sparse-src dst.git 2>err &&
368 test_i18ngrep "unable to access sparse blob in .main:no-such-name" err &&
369 test_must_fail git clone --no-local --bare \
370 --filter=sparse:oid=main \
371 sparse-src dst.git 2>err &&
372 test_i18ngrep "unable to parse sparse filter data in" err
376 rm -rf big-blob.txt server client promisor-remote
&&
378 printf "line %d\n" $
(test_seq
1 100) >big-blob.txt
&&
380 # Create a server with 2 commits: a commit with a big tree and a child
381 # commit with an incremental change. Also, create a partial clone
382 # client that only contains the first commit.
384 git
-C server config
--local uploadpack.allowfilter
1 &&
385 for i
in $
(test_seq
1 100)
387 echo "make the tree big" >server
/file$i &&
388 git
-C server add
file$i
390 git
-C server commit
-m "initial" &&
391 git clone
--bare --filter=tree
:0 "file://$(pwd)/server" client
&&
392 echo another line
>>server
/file1
&&
393 git
-C server commit
-am "incremental change" &&
395 # Create a promisor remote that only contains the tree and blob from
397 git init promisor-remote
&&
398 git
-C server config
--local uploadpack.allowanysha1inwant
1 &&
399 TREE_HASH
=$
(git
-C server rev-parse HEAD~
1^
{tree
}) &&
400 git
-C promisor-remote fetch
--keep "file://$(pwd)/server" "$TREE_HASH" &&
401 git
-C promisor-remote count-objects
-v >object-count
&&
402 test_i18ngrep
"count: 0" object-count
&&
403 test_i18ngrep
"in-pack: 2" object-count
&&
405 # Set it as the promisor remote of client. Thus, whenever
406 # the client lazy fetches, the lazy fetch will succeed only if it is
407 # for this tree or blob.
408 test_commit
-C promisor-remote one
&& # so that ref advertisement is not empty
409 git
-C promisor-remote config
--local uploadpack.allowanysha1inwant
1 &&
410 git
-C client remote set-url origin
"file://$(pwd)/promisor-remote"
413 # NEEDSWORK: The tests beginning with "fetch lazy-fetches" below only
414 # test that "fetch" avoid fetching trees and blobs, but not commits or
415 # tags. Revisit this if Git is ever taught to support partial clones
416 # with commits and/or tags filtered out.
418 test_expect_success
'fetch lazy-fetches only to resolve deltas' '
421 # Exercise to make sure it works. Git will not fetch anything from the
422 # promisor remote other than for the big tree (because it needs to
423 # resolve the delta).
424 GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
425 fetch "file://$(pwd)/server" main &&
427 # Verify the assumption that the client needed to fetch the delta base
428 # to resolve the delta.
429 git -C server rev-parse HEAD~1^{tree} >hash &&
430 grep "want $(cat hash)" trace
433 test_expect_success
'fetch lazy-fetches only to resolve deltas, protocol v2' '
436 git -C server config --local protocol.version 2 &&
437 git -C client config --local protocol.version 2 &&
438 git -C promisor-remote config --local protocol.version 2 &&
440 # Exercise to make sure it works. Git will not fetch anything from the
441 # promisor remote other than for the big blob (because it needs to
442 # resolve the delta).
443 GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
444 fetch "file://$(pwd)/server" main &&
446 # Verify that protocol version 2 was used.
447 grep "fetch< version 2" trace &&
449 # Verify the assumption that the client needed to fetch the delta base
450 # to resolve the delta.
451 git -C server rev-parse HEAD~1^{tree} >hash &&
452 grep "want $(cat hash)" trace
455 test_expect_success
'fetch does not lazy-fetch missing targets of its refs' '
456 rm -rf server client trace &&
458 test_create_repo server &&
459 test_config -C server uploadpack.allowfilter 1 &&
460 test_config -C server uploadpack.allowanysha1inwant 1 &&
461 test_commit -C server foo &&
463 git clone --filter=blob:none "file://$(pwd)/server" client &&
464 # Make all refs point to nothing by deleting all objects.
465 rm client/.git/objects/pack/* &&
467 test_commit -C server bar &&
468 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
469 --no-tags --recurse-submodules=no \
470 origin refs/tags/bar &&
471 FOO_HASH=$(git -C server rev-parse foo) &&
472 ! grep "want $FOO_HASH" trace
475 # The following two tests must be in this order. It is important that
476 # the srv.bare repository did not have tags during clone, but has tags
479 test_expect_success
'verify fetch succeeds when asking for new tags' '
480 git clone --filter=blob:none "file://$(pwd)/srv.bare" tag-test &&
483 test_commit -C src $i &&
484 git -C src branch $i || return 1
486 git -C srv.bare fetch --tags origin +refs/heads/*:refs/heads/* &&
487 git -C tag-test -c protocol.version=2 fetch --tags origin
490 test_expect_success
'verify fetch downloads only one pack when updating refs' '
491 git clone --filter=blob:none "file://$(pwd)/srv.bare" pack-test &&
492 ls pack-test/.git/objects/pack/*pack >pack-list &&
493 test_line_count = 2 pack-list &&
496 test_commit -C src $i &&
497 git -C src branch $i || return 1
499 git -C srv.bare fetch origin +refs/heads/*:refs/heads/* &&
500 git -C pack-test fetch origin &&
501 ls pack-test/.git/objects/pack/*pack >pack-list &&
502 test_line_count = 3 pack-list
505 test_expect_success
'single-branch tag following respects partial clone' '
506 git clone --single-branch -b B --filter=blob:none \
507 "file://$(pwd)/srv.bare" single &&
508 git -C single rev-parse --verify refs/tags/B &&
509 git -C single rev-parse --verify refs/tags/A &&
510 test_must_fail git -C single rev-parse --verify refs/tags/C
513 test_expect_success
'fetch from a partial clone, protocol v0' '
514 rm -rf server client trace &&
516 # Pretend that the server is a partial clone
518 git -C server remote add a_remote "file://$(pwd)/" &&
519 test_config -C server core.repositoryformatversion 1 &&
520 test_config -C server extensions.partialclone a_remote &&
521 test_config -C server protocol.version 0 &&
522 test_commit -C server foo &&
524 # Fetch from the server
526 test_config -C client protocol.version 0 &&
527 test_commit -C client bar &&
528 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" &&
529 ! grep "version 2" trace
532 test_expect_success
'fetch from a partial clone, protocol v2' '
533 rm -rf server client trace &&
535 # Pretend that the server is a partial clone
537 git -C server remote add a_remote "file://$(pwd)/" &&
538 test_config -C server core.repositoryformatversion 1 &&
539 test_config -C server extensions.partialclone a_remote &&
540 test_config -C server protocol.version 2 &&
541 test_commit -C server foo &&
543 # Fetch from the server
545 test_config -C client protocol.version 2 &&
546 test_commit -C client bar &&
547 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" &&
548 grep "version 2" trace
551 .
"$TEST_DIRECTORY"/lib-httpd.sh
554 # Converts bytes into their hexadecimal representation. For example,
555 # "printf 'ab\r\n' | hex_unpack" results in '61620d0a'.
557 perl
-e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)'
560 # Inserts $1 at the start of the string and every 2 characters thereafter.
562 sed 's/\(..\)/'$1'\1/g'
565 # Create a one-time-perl command to replace the existing packfile with $1.
566 replace_packfile
() {
567 # The protocol requires that the packfile be sent in sideband 1, hence
568 # the extra \x01 byte at the beginning.
569 cp $1 "$HTTPD_ROOT_PATH/one-time-pack" &&
570 echo 'if (/packfile/) {
572 my $length = -s "one-time-pack";
573 printf "%04x\x01", $length + 5;
574 print `cat one-time-pack` . "0000";
576 }' >"$HTTPD_ROOT_PATH/one-time-perl"
579 test_expect_success
'upon cloning, check that all refs point to objects' '
580 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
581 rm -rf "$SERVER" repo &&
582 test_create_repo "$SERVER" &&
583 test_commit -C "$SERVER" foo &&
584 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
585 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
587 # Create a tag pointing to a blob.
588 BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
589 git -C "$SERVER" tag myblob "$BLOB" &&
591 # Craft a packfile not including that blob.
592 git -C "$SERVER" rev-parse HEAD |
593 git -C "$SERVER" pack-objects --stdout >incomplete.pack &&
595 # Replace the existing packfile with the crafted one. The protocol
596 # requires that the packfile be sent in sideband 1, hence the extra
597 # \x01 byte at the beginning.
598 replace_packfile incomplete.pack &&
600 # Use protocol v2 because the perl command looks for the "packfile"
602 test_config -C "$SERVER" protocol.version 2 &&
603 test_must_fail git -c protocol.version=2 clone \
604 --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2>err &&
606 test_i18ngrep "did not send all necessary objects" err &&
608 # Ensure that the one-time-perl script was used.
609 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
612 test_expect_success
'when partial cloning, tolerate server not sending target of tag' '
613 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
614 rm -rf "$SERVER" repo &&
615 test_create_repo "$SERVER" &&
616 test_commit -C "$SERVER" foo &&
617 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
618 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
620 # Create an annotated tag pointing to a blob.
621 BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
622 git -C "$SERVER" tag -m message -a myblob "$BLOB" &&
624 # Craft a packfile including the tag, but not the blob it points to.
625 # Also, omit objects referenced from HEAD in order to force a second
626 # fetch (to fetch missing objects) upon the automatic checkout that
627 # happens after a clone.
628 printf "%s\n%s\n--not\n%s\n%s\n" \
629 $(git -C "$SERVER" rev-parse HEAD) \
630 $(git -C "$SERVER" rev-parse myblob) \
631 $(git -C "$SERVER" rev-parse HEAD^{tree}) \
632 $(git -C "$SERVER" rev-parse myblob^{blob}) |
633 git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack &&
635 # Replace the existing packfile with the crafted one. The protocol
636 # requires that the packfile be sent in sideband 1, hence the extra
637 # \x01 byte at the beginning.
638 replace_packfile incomplete.pack &&
640 # Use protocol v2 because the perl command looks for the "packfile"
642 test_config -C "$SERVER" protocol.version 2 &&
644 # Exercise to make sure it works.
645 git -c protocol.version=2 clone \
646 --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2> err &&
647 ! grep "missing object referenced by" err &&
649 # Ensure that the one-time-perl script was used.
650 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
653 test_expect_success
'tolerate server sending REF_DELTA against missing promisor objects' '
654 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
655 rm -rf "$SERVER" repo &&
656 test_create_repo "$SERVER" &&
657 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
658 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
660 # Create a commit with 2 blobs to be used as delta bases.
661 for i in $(test_seq 10)
663 echo "this is a line" >>"$SERVER/foo.txt" &&
664 echo "this is another line" >>"$SERVER/have.txt"
666 git -C "$SERVER" add foo.txt have.txt &&
667 git -C "$SERVER" commit -m bar &&
668 git -C "$SERVER" rev-parse HEAD:foo.txt >deltabase_missing &&
669 git -C "$SERVER" rev-parse HEAD:have.txt >deltabase_have &&
671 # Clone. The client has deltabase_have but not deltabase_missing.
672 git -c protocol.version=2 clone --no-checkout \
673 --filter=blob:none $HTTPD_URL/one_time_perl/server repo &&
674 git -C repo hash-object -w -- "$SERVER/have.txt" &&
676 # Sanity check to ensure that the client does not have
678 git -C repo rev-list --objects --ignore-missing \
679 -- $(cat deltabase_missing) >objlist &&
680 test_line_count = 0 objlist &&
682 # Another commit. This commit will be fetched by the client.
683 echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/foo.txt" &&
684 echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/have.txt" &&
685 git -C "$SERVER" add foo.txt have.txt &&
686 git -C "$SERVER" commit -m baz &&
688 # Pack a thin pack containing, among other things, HEAD:foo.txt
689 # delta-ed against HEAD^:foo.txt and HEAD:have.txt delta-ed against
691 printf "%s\n--not\n%s\n" \
692 $(git -C "$SERVER" rev-parse HEAD) \
693 $(git -C "$SERVER" rev-parse HEAD^) |
694 git -C "$SERVER" pack-objects --thin --stdout >thin.pack &&
696 # Ensure that the pack contains one delta against HEAD^:foo.txt. Since
697 # the delta contains at least 26 novel characters, the size cannot be
698 # contained in 4 bits, so the object header will take up 2 bytes. The
699 # most significant nybble of the first byte is 0b1111 (0b1 to indicate
700 # that the header continues, and 0b111 to indicate REF_DELTA), followed
701 # by any 3 nybbles, then the OID of the delta base.
702 printf "f.,..%s" $(intersperse "," <deltabase_missing) >want &&
703 hex_unpack <thin.pack | intersperse "," >have &&
704 grep $(cat want) have &&
706 # Ensure that the pack contains one delta against HEAD^:have.txt,
707 # similar to the above.
708 printf "f.,..%s" $(intersperse "," <deltabase_have) >want &&
709 hex_unpack <thin.pack | intersperse "," >have &&
710 grep $(cat want) have &&
712 replace_packfile thin.pack &&
714 # Use protocol v2 because the perl command looks for the "packfile"
716 test_config -C "$SERVER" protocol.version 2 &&
718 # Fetch the thin pack and ensure that index-pack is able to handle the
719 # REF_DELTA object with a missing promisor delta base.
720 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo -c protocol.version=2 fetch &&
722 # Ensure that the missing delta base was directly fetched, but not the
723 # one that the client has.
724 grep "want $(cat deltabase_missing)" trace &&
725 ! grep "want $(cat deltabase_have)" trace &&
727 # Ensure that the one-time-perl script was used.
728 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
731 # DO NOT add non-httpd-specific tests here, because the last part of this
732 # test script is only executed when httpd is available and enabled.