Git 2.30.9
[git.git] / t / t5616-partial-clone.sh
bloba6138e8cfc334d667521d64fb74f4434a1e549cb
1 #!/bin/sh
3 test_description='git partial clone'
5 . ./test-lib.sh
7 # create a normal "src" repo where we can later create new commits.
8 # expect_1.oids will contain a list of the OIDs of all blobs.
9 test_expect_success 'setup normal src repo' '
10 echo "{print \$1}" >print_1.awk &&
11 echo "{print \$2}" >print_2.awk &&
13 git init src &&
14 for n in 1 2 3 4
16 echo "This is file: $n" > src/file.$n.txt
17 git -C src add file.$n.txt
18 git -C src commit -m "file $n"
19 git -C src ls-files -s file.$n.txt >>temp
20 done &&
21 awk -f print_2.awk <temp | sort >expect_1.oids &&
22 test_line_count = 4 expect_1.oids
25 # bare clone "src" giving "srv.bare" for use as our server.
26 test_expect_success 'setup bare clone for server' '
27 git clone --bare "file://$(pwd)/src" srv.bare &&
28 git -C srv.bare config --local uploadpack.allowfilter 1 &&
29 git -C srv.bare config --local uploadpack.allowanysha1inwant 1
32 # do basic partial clone from "srv.bare"
33 # confirm we are missing all of the known blobs.
34 # confirm partial clone was registered in the local config.
35 test_expect_success 'do partial clone 1' '
36 git clone --no-checkout --filter=blob:none "file://$(pwd)/srv.bare" pc1 &&
38 git -C pc1 rev-list --quiet --objects --missing=print HEAD >revs &&
39 awk -f print_1.awk revs |
40 sed "s/?//" |
41 sort >observed.oids &&
43 test_cmp expect_1.oids observed.oids &&
44 test "$(git -C pc1 config --local core.repositoryformatversion)" = "1" &&
45 test "$(git -C pc1 config --local remote.origin.promisor)" = "true" &&
46 test "$(git -C pc1 config --local remote.origin.partialclonefilter)" = "blob:none"
49 test_expect_success 'verify that .promisor file contains refs fetched' '
50 ls pc1/.git/objects/pack/pack-*.promisor >promisorlist &&
51 test_line_count = 1 promisorlist &&
52 git -C srv.bare rev-parse --verify HEAD >headhash &&
53 grep "$(cat headhash) HEAD" $(cat promisorlist) &&
54 grep "$(cat headhash) refs/heads/master" $(cat promisorlist)
57 # checkout master to force dynamic object fetch of blobs at HEAD.
58 test_expect_success 'verify checkout with dynamic object fetch' '
59 git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&
60 test_line_count = 4 observed &&
61 git -C pc1 checkout master &&
62 git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&
63 test_line_count = 0 observed
66 # create new commits in "src" repo to establish a blame history on file.1.txt
67 # and push to "srv.bare".
68 test_expect_success 'push new commits to server' '
69 git -C src remote add srv "file://$(pwd)/srv.bare" &&
70 for x in a b c d e
72 echo "Mod file.1.txt $x" >>src/file.1.txt
73 git -C src add file.1.txt
74 git -C src commit -m "mod $x"
75 done &&
76 git -C src blame master -- file.1.txt >expect.blame &&
77 git -C src push -u srv master
80 # (partial) fetch in the partial clone repo from the promisor remote.
81 # verify that fetch inherited the filter-spec from the config and DOES NOT
82 # have the new blobs.
83 test_expect_success 'partial fetch inherits filter settings' '
84 git -C pc1 fetch origin &&
85 git -C pc1 rev-list --quiet --objects --missing=print \
86 master..origin/master >observed &&
87 test_line_count = 5 observed
90 # force dynamic object fetch using diff.
91 # we should only get 1 new blob (for the file in origin/master).
92 test_expect_success 'verify diff causes dynamic object fetch' '
93 git -C pc1 diff master..origin/master -- file.1.txt &&
94 git -C pc1 rev-list --quiet --objects --missing=print \
95 master..origin/master >observed &&
96 test_line_count = 4 observed
99 # force full dynamic object fetch of the file's history using blame.
100 # we should get the intermediate blobs for the file.
101 test_expect_success 'verify blame causes dynamic object fetch' '
102 git -C pc1 blame origin/master -- file.1.txt >observed.blame &&
103 test_cmp expect.blame observed.blame &&
104 git -C pc1 rev-list --quiet --objects --missing=print \
105 master..origin/master >observed &&
106 test_line_count = 0 observed
109 # create new commits in "src" repo to establish a history on file.2.txt
110 # and push to "srv.bare".
111 test_expect_success 'push new commits to server for file.2.txt' '
112 for x in a b c d e f
114 echo "Mod file.2.txt $x" >>src/file.2.txt
115 git -C src add file.2.txt
116 git -C src commit -m "mod $x"
117 done &&
118 git -C src push -u srv master
121 # Do FULL fetch by disabling inherited filter-spec using --no-filter.
122 # Verify we have all the new blobs.
123 test_expect_success 'override inherited filter-spec using --no-filter' '
124 git -C pc1 fetch --no-filter origin &&
125 git -C pc1 rev-list --quiet --objects --missing=print \
126 master..origin/master >observed &&
127 test_line_count = 0 observed
130 # create new commits in "src" repo to establish a history on file.3.txt
131 # and push to "srv.bare".
132 test_expect_success 'push new commits to server for file.3.txt' '
133 for x in a b c d e f
135 echo "Mod file.3.txt $x" >>src/file.3.txt
136 git -C src add file.3.txt
137 git -C src commit -m "mod $x"
138 done &&
139 git -C src push -u srv master
142 # Do a partial fetch and then try to manually fetch the missing objects.
143 # This can be used as the basis of a pre-command hook to bulk fetch objects
144 # perhaps combined with a command in dry-run mode.
145 test_expect_success 'manual prefetch of missing objects' '
146 git -C pc1 fetch --filter=blob:none origin &&
148 git -C pc1 rev-list --quiet --objects --missing=print \
149 master..origin/master >revs &&
150 awk -f print_1.awk revs |
151 sed "s/?//" |
152 sort >observed.oids &&
154 test_line_count = 6 observed.oids &&
155 git -C pc1 fetch-pack --stdin "file://$(pwd)/srv.bare" <observed.oids &&
157 git -C pc1 rev-list --quiet --objects --missing=print \
158 master..origin/master >revs &&
159 awk -f print_1.awk revs |
160 sed "s/?//" |
161 sort >observed.oids &&
163 test_line_count = 0 observed.oids
166 test_expect_success 'partial clone with transfer.fsckobjects=1 works with submodules' '
167 test_create_repo submodule &&
168 test_commit -C submodule mycommit &&
170 test_create_repo src_with_sub &&
171 test_config -C src_with_sub uploadpack.allowfilter 1 &&
172 test_config -C src_with_sub uploadpack.allowanysha1inwant 1 &&
174 test_config_global protocol.file.allow always &&
176 git -C src_with_sub submodule add "file://$(pwd)/submodule" mysub &&
177 git -C src_with_sub commit -m "commit with submodule" &&
179 git -c transfer.fsckobjects=1 \
180 clone --filter="blob:none" "file://$(pwd)/src_with_sub" dst &&
181 test_when_finished rm -rf dst
184 test_expect_success 'partial clone with transfer.fsckobjects=1 uses index-pack --fsck-objects' '
185 git init src &&
186 test_commit -C src x &&
187 test_config -C src uploadpack.allowfilter 1 &&
188 test_config -C src uploadpack.allowanysha1inwant 1 &&
190 GIT_TRACE="$(pwd)/trace" git -c transfer.fsckobjects=1 \
191 clone --filter="blob:none" "file://$(pwd)/src" dst &&
192 grep "git index-pack.*--fsck-objects" trace
195 test_expect_success 'use fsck before and after manually fetching a missing subtree' '
196 # push new commit so server has a subtree
197 mkdir src/dir &&
198 echo "in dir" >src/dir/file.txt &&
199 git -C src add dir/file.txt &&
200 git -C src commit -m "file in dir" &&
201 git -C src push -u srv master &&
202 SUBTREE=$(git -C src rev-parse HEAD:dir) &&
204 rm -rf dst &&
205 git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" dst &&
206 git -C dst fsck &&
208 # Make sure we only have commits, and all trees and blobs are missing.
209 git -C dst rev-list --missing=allow-any --objects master \
210 >fetched_objects &&
211 awk -f print_1.awk fetched_objects |
212 xargs -n1 git -C dst cat-file -t >fetched_types &&
214 sort -u fetched_types >unique_types.observed &&
215 echo commit >unique_types.expected &&
216 test_cmp unique_types.expected unique_types.observed &&
218 # Auto-fetch a tree with cat-file.
219 git -C dst cat-file -p $SUBTREE >tree_contents &&
220 grep file.txt tree_contents &&
222 # fsck still works after an auto-fetch of a tree.
223 git -C dst fsck &&
225 # Auto-fetch all remaining trees and blobs with --missing=error
226 git -C dst rev-list --missing=error --objects master >fetched_objects &&
227 test_line_count = 70 fetched_objects &&
229 awk -f print_1.awk fetched_objects |
230 xargs -n1 git -C dst cat-file -t >fetched_types &&
232 sort -u fetched_types >unique_types.observed &&
233 test_write_lines blob commit tree >unique_types.expected &&
234 test_cmp unique_types.expected unique_types.observed
237 test_expect_success 'implicitly construct combine: filter with repeated flags' '
238 GIT_TRACE=$(pwd)/trace git clone --bare \
239 --filter=blob:none --filter=tree:1 \
240 "file://$(pwd)/srv.bare" pc2 &&
241 grep "trace:.* git pack-objects .*--filter=combine:blob:none+tree:1" \
242 trace &&
243 git -C pc2 rev-list --objects --missing=allow-any HEAD >objects &&
245 # We should have gotten some root trees.
246 grep " $" objects &&
247 # Should not have gotten any non-root trees or blobs.
248 ! grep " ." objects &&
250 xargs -n 1 git -C pc2 cat-file -t <objects >types &&
251 sort -u types >unique_types.actual &&
252 test_write_lines commit tree >unique_types.expected &&
253 test_cmp unique_types.expected unique_types.actual
256 test_expect_success 'upload-pack complains of bogus filter config' '
257 printf 0000 |
258 test_must_fail git \
259 -c uploadpackfilter.tree.maxdepth \
260 upload-pack . >/dev/null 2>err &&
261 test_i18ngrep "unable to parse.*tree.maxdepth" err
264 test_expect_success 'upload-pack fails banned object filters' '
265 test_config -C srv.bare uploadpackfilter.blob:none.allow false &&
266 test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \
267 "file://$(pwd)/srv.bare" pc3 2>err &&
268 test_i18ngrep "filter '\''blob:none'\'' not supported" err
271 test_expect_success 'upload-pack fails banned combine object filters' '
272 test_config -C srv.bare uploadpackfilter.allow false &&
273 test_config -C srv.bare uploadpackfilter.combine.allow true &&
274 test_config -C srv.bare uploadpackfilter.tree.allow true &&
275 test_config -C srv.bare uploadpackfilter.blob:none.allow false &&
276 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \
277 --filter=blob:none "file://$(pwd)/srv.bare" pc3 2>err &&
278 test_i18ngrep "filter '\''blob:none'\'' not supported" err
281 test_expect_success 'upload-pack fails banned object filters with fallback' '
282 test_config -C srv.bare uploadpackfilter.allow false &&
283 test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \
284 "file://$(pwd)/srv.bare" pc3 2>err &&
285 test_i18ngrep "filter '\''blob:none'\'' not supported" err
288 test_expect_success 'upload-pack limits tree depth filters' '
289 test_config -C srv.bare uploadpackfilter.allow false &&
290 test_config -C srv.bare uploadpackfilter.tree.allow true &&
291 test_config -C srv.bare uploadpackfilter.tree.maxDepth 0 &&
292 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \
293 "file://$(pwd)/srv.bare" pc3 2>err &&
294 test_i18ngrep "tree filter allows max depth 0, but got 1" err &&
296 git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" pc4 &&
298 test_config -C srv.bare uploadpackfilter.tree.maxDepth 5 &&
299 git clone --no-checkout --filter=tree:5 "file://$(pwd)/srv.bare" pc5 &&
300 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:6 \
301 "file://$(pwd)/srv.bare" pc6 2>err &&
302 test_i18ngrep "tree filter allows max depth 5, but got 6" err
305 test_expect_success 'partial clone fetches blobs pointed to by refs even if normally filtered out' '
306 rm -rf src dst &&
307 git init src &&
308 test_commit -C src x &&
309 test_config -C src uploadpack.allowfilter 1 &&
310 test_config -C src uploadpack.allowanysha1inwant 1 &&
312 # Create a tag pointing to a blob.
313 BLOB=$(echo blob-contents | git -C src hash-object --stdin -w) &&
314 git -C src tag myblob "$BLOB" &&
316 git clone --filter="blob:none" "file://$(pwd)/src" dst 2>err &&
317 ! grep "does not point to a valid object" err &&
318 git -C dst fsck
321 test_expect_success 'fetch what is specified on CLI even if already promised' '
322 rm -rf src dst.git &&
323 git init src &&
324 test_commit -C src foo &&
325 test_config -C src uploadpack.allowfilter 1 &&
326 test_config -C src uploadpack.allowanysha1inwant 1 &&
328 git hash-object --stdin <src/foo.t >blob &&
330 git clone --bare --filter=blob:none "file://$(pwd)/src" dst.git &&
331 git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_before &&
332 grep "?$(cat blob)" missing_before &&
333 git -C dst.git fetch origin $(cat blob) &&
334 git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_after &&
335 ! grep "?$(cat blob)" missing_after
338 test_expect_success 'setup src repo for sparse filter' '
339 git init sparse-src &&
340 git -C sparse-src config --local uploadpack.allowfilter 1 &&
341 git -C sparse-src config --local uploadpack.allowanysha1inwant 1 &&
342 test_commit -C sparse-src one &&
343 test_commit -C sparse-src two &&
344 echo /one.t >sparse-src/only-one &&
345 git -C sparse-src add . &&
346 git -C sparse-src commit -m "add sparse checkout files"
349 test_expect_success 'partial clone with sparse filter succeeds' '
350 rm -rf dst.git &&
351 git clone --no-local --bare \
352 --filter=sparse:oid=master:only-one \
353 sparse-src dst.git &&
355 cd dst.git &&
356 git rev-list --objects --missing=print HEAD >out &&
357 grep "^$(git rev-parse HEAD:one.t)" out &&
358 grep "^?$(git rev-parse HEAD:two.t)" out
362 test_expect_success 'partial clone with unresolvable sparse filter fails cleanly' '
363 rm -rf dst.git &&
364 test_must_fail git clone --no-local --bare \
365 --filter=sparse:oid=master:no-such-name \
366 sparse-src dst.git 2>err &&
367 test_i18ngrep "unable to access sparse blob in .master:no-such-name" err &&
368 test_must_fail git clone --no-local --bare \
369 --filter=sparse:oid=master \
370 sparse-src dst.git 2>err &&
371 test_i18ngrep "unable to parse sparse filter data in" err
374 setup_triangle () {
375 rm -rf big-blob.txt server client promisor-remote &&
377 printf "line %d\n" $(test_seq 1 100) >big-blob.txt &&
379 # Create a server with 2 commits: a commit with a big tree and a child
380 # commit with an incremental change. Also, create a partial clone
381 # client that only contains the first commit.
382 git init server &&
383 git -C server config --local uploadpack.allowfilter 1 &&
384 for i in $(test_seq 1 100)
386 echo "make the tree big" >server/file$i &&
387 git -C server add file$i
388 done &&
389 git -C server commit -m "initial" &&
390 git clone --bare --filter=tree:0 "file://$(pwd)/server" client &&
391 echo another line >>server/file1 &&
392 git -C server commit -am "incremental change" &&
394 # Create a promisor remote that only contains the tree and blob from
395 # the first commit.
396 git init promisor-remote &&
397 git -C server config --local uploadpack.allowanysha1inwant 1 &&
398 TREE_HASH=$(git -C server rev-parse HEAD~1^{tree}) &&
399 git -C promisor-remote fetch --keep "file://$(pwd)/server" "$TREE_HASH" &&
400 git -C promisor-remote count-objects -v >object-count &&
401 test_i18ngrep "count: 0" object-count &&
402 test_i18ngrep "in-pack: 2" object-count &&
404 # Set it as the promisor remote of client. Thus, whenever
405 # the client lazy fetches, the lazy fetch will succeed only if it is
406 # for this tree or blob.
407 test_commit -C promisor-remote one && # so that ref advertisement is not empty
408 git -C promisor-remote config --local uploadpack.allowanysha1inwant 1 &&
409 git -C client remote set-url origin "file://$(pwd)/promisor-remote"
412 # NEEDSWORK: The tests beginning with "fetch lazy-fetches" below only
413 # test that "fetch" avoid fetching trees and blobs, but not commits or
414 # tags. Revisit this if Git is ever taught to support partial clones
415 # with commits and/or tags filtered out.
417 test_expect_success 'fetch lazy-fetches only to resolve deltas' '
418 setup_triangle &&
420 # Exercise to make sure it works. Git will not fetch anything from the
421 # promisor remote other than for the big tree (because it needs to
422 # resolve the delta).
423 GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
424 fetch "file://$(pwd)/server" master &&
426 # Verify the assumption that the client needed to fetch the delta base
427 # to resolve the delta.
428 git -C server rev-parse HEAD~1^{tree} >hash &&
429 grep "want $(cat hash)" trace
432 test_expect_success 'fetch lazy-fetches only to resolve deltas, protocol v2' '
433 setup_triangle &&
435 git -C server config --local protocol.version 2 &&
436 git -C client config --local protocol.version 2 &&
437 git -C promisor-remote config --local protocol.version 2 &&
439 # Exercise to make sure it works. Git will not fetch anything from the
440 # promisor remote other than for the big blob (because it needs to
441 # resolve the delta).
442 GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
443 fetch "file://$(pwd)/server" master &&
445 # Verify that protocol version 2 was used.
446 grep "fetch< version 2" trace &&
448 # Verify the assumption that the client needed to fetch the delta base
449 # to resolve the delta.
450 git -C server rev-parse HEAD~1^{tree} >hash &&
451 grep "want $(cat hash)" trace
454 test_expect_success 'fetch does not lazy-fetch missing targets of its refs' '
455 rm -rf server client trace &&
457 test_create_repo server &&
458 test_config -C server uploadpack.allowfilter 1 &&
459 test_config -C server uploadpack.allowanysha1inwant 1 &&
460 test_commit -C server foo &&
462 git clone --filter=blob:none "file://$(pwd)/server" client &&
463 # Make all refs point to nothing by deleting all objects.
464 rm client/.git/objects/pack/* &&
466 test_commit -C server bar &&
467 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
468 --no-tags --recurse-submodules=no \
469 origin refs/tags/bar &&
470 FOO_HASH=$(git -C server rev-parse foo) &&
471 ! grep "want $FOO_HASH" trace
474 # The following two tests must be in this order. It is important that
475 # the srv.bare repository did not have tags during clone, but has tags
476 # in the fetch.
478 test_expect_success 'verify fetch succeeds when asking for new tags' '
479 git clone --filter=blob:none "file://$(pwd)/srv.bare" tag-test &&
480 for i in I J K
482 test_commit -C src $i &&
483 git -C src branch $i || return 1
484 done &&
485 git -C srv.bare fetch --tags origin +refs/heads/*:refs/heads/* &&
486 git -C tag-test -c protocol.version=2 fetch --tags origin
489 test_expect_success 'verify fetch downloads only one pack when updating refs' '
490 git clone --filter=blob:none "file://$(pwd)/srv.bare" pack-test &&
491 ls pack-test/.git/objects/pack/*pack >pack-list &&
492 test_line_count = 2 pack-list &&
493 for i in A B C
495 test_commit -C src $i &&
496 git -C src branch $i || return 1
497 done &&
498 git -C srv.bare fetch origin +refs/heads/*:refs/heads/* &&
499 git -C pack-test fetch origin &&
500 ls pack-test/.git/objects/pack/*pack >pack-list &&
501 test_line_count = 3 pack-list
504 test_expect_success 'single-branch tag following respects partial clone' '
505 git clone --single-branch -b B --filter=blob:none \
506 "file://$(pwd)/srv.bare" single &&
507 git -C single rev-parse --verify refs/tags/B &&
508 git -C single rev-parse --verify refs/tags/A &&
509 test_must_fail git -C single rev-parse --verify refs/tags/C
512 test_expect_success 'fetch from a partial clone, protocol v0' '
513 rm -rf server client trace &&
515 # Pretend that the server is a partial clone
516 git init server &&
517 git -C server remote add a_remote "file://$(pwd)/" &&
518 test_config -C server core.repositoryformatversion 1 &&
519 test_config -C server extensions.partialclone a_remote &&
520 test_config -C server protocol.version 0 &&
521 test_commit -C server foo &&
523 # Fetch from the server
524 git init client &&
525 test_config -C client protocol.version 0 &&
526 test_commit -C client bar &&
527 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" &&
528 ! grep "version 2" trace
531 test_expect_success 'fetch from a partial clone, protocol v2' '
532 rm -rf server client trace &&
534 # Pretend that the server is a partial clone
535 git init server &&
536 git -C server remote add a_remote "file://$(pwd)/" &&
537 test_config -C server core.repositoryformatversion 1 &&
538 test_config -C server extensions.partialclone a_remote &&
539 test_config -C server protocol.version 2 &&
540 test_commit -C server foo &&
542 # Fetch from the server
543 git init client &&
544 test_config -C client protocol.version 2 &&
545 test_commit -C client bar &&
546 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" &&
547 grep "version 2" trace
550 . "$TEST_DIRECTORY"/lib-httpd.sh
551 start_httpd
553 # Converts bytes into their hexadecimal representation. For example,
554 # "printf 'ab\r\n' | hex_unpack" results in '61620d0a'.
555 hex_unpack () {
556 perl -e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)'
559 # Inserts $1 at the start of the string and every 2 characters thereafter.
560 intersperse () {
561 sed 's/\(..\)/'$1'\1/g'
564 # Create a one-time-perl command to replace the existing packfile with $1.
565 replace_packfile () {
566 # The protocol requires that the packfile be sent in sideband 1, hence
567 # the extra \x01 byte at the beginning.
568 cp $1 "$HTTPD_ROOT_PATH/one-time-pack" &&
569 echo 'if (/packfile/) {
570 print;
571 my $length = -s "one-time-pack";
572 printf "%04x\x01", $length + 5;
573 print `cat one-time-pack` . "0000";
574 last
575 }' >"$HTTPD_ROOT_PATH/one-time-perl"
578 test_expect_success 'upon cloning, check that all refs point to objects' '
579 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
580 rm -rf "$SERVER" repo &&
581 test_create_repo "$SERVER" &&
582 test_commit -C "$SERVER" foo &&
583 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
584 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
586 # Create a tag pointing to a blob.
587 BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
588 git -C "$SERVER" tag myblob "$BLOB" &&
590 # Craft a packfile not including that blob.
591 git -C "$SERVER" rev-parse HEAD |
592 git -C "$SERVER" pack-objects --stdout >incomplete.pack &&
594 # Replace the existing packfile with the crafted one. The protocol
595 # requires that the packfile be sent in sideband 1, hence the extra
596 # \x01 byte at the beginning.
597 replace_packfile incomplete.pack &&
599 # Use protocol v2 because the perl command looks for the "packfile"
600 # section header.
601 test_config -C "$SERVER" protocol.version 2 &&
602 test_must_fail git -c protocol.version=2 clone \
603 --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2>err &&
605 test_i18ngrep "did not send all necessary objects" err &&
607 # Ensure that the one-time-perl script was used.
608 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
611 test_expect_success 'when partial cloning, tolerate server not sending target of tag' '
612 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
613 rm -rf "$SERVER" repo &&
614 test_create_repo "$SERVER" &&
615 test_commit -C "$SERVER" foo &&
616 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
617 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
619 # Create an annotated tag pointing to a blob.
620 BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
621 git -C "$SERVER" tag -m message -a myblob "$BLOB" &&
623 # Craft a packfile including the tag, but not the blob it points to.
624 # Also, omit objects referenced from HEAD in order to force a second
625 # fetch (to fetch missing objects) upon the automatic checkout that
626 # happens after a clone.
627 printf "%s\n%s\n--not\n%s\n%s\n" \
628 $(git -C "$SERVER" rev-parse HEAD) \
629 $(git -C "$SERVER" rev-parse myblob) \
630 $(git -C "$SERVER" rev-parse HEAD^{tree}) \
631 $(git -C "$SERVER" rev-parse myblob^{blob}) |
632 git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack &&
634 # Replace the existing packfile with the crafted one. The protocol
635 # requires that the packfile be sent in sideband 1, hence the extra
636 # \x01 byte at the beginning.
637 replace_packfile incomplete.pack &&
639 # Use protocol v2 because the perl command looks for the "packfile"
640 # section header.
641 test_config -C "$SERVER" protocol.version 2 &&
643 # Exercise to make sure it works.
644 git -c protocol.version=2 clone \
645 --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2> err &&
646 ! grep "missing object referenced by" err &&
648 # Ensure that the one-time-perl script was used.
649 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
652 test_expect_success 'tolerate server sending REF_DELTA against missing promisor objects' '
653 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
654 rm -rf "$SERVER" repo &&
655 test_create_repo "$SERVER" &&
656 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
657 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
659 # Create a commit with 2 blobs to be used as delta bases.
660 for i in $(test_seq 10)
662 echo "this is a line" >>"$SERVER/foo.txt" &&
663 echo "this is another line" >>"$SERVER/have.txt"
664 done &&
665 git -C "$SERVER" add foo.txt have.txt &&
666 git -C "$SERVER" commit -m bar &&
667 git -C "$SERVER" rev-parse HEAD:foo.txt >deltabase_missing &&
668 git -C "$SERVER" rev-parse HEAD:have.txt >deltabase_have &&
670 # Clone. The client has deltabase_have but not deltabase_missing.
671 git -c protocol.version=2 clone --no-checkout \
672 --filter=blob:none $HTTPD_URL/one_time_perl/server repo &&
673 git -C repo hash-object -w -- "$SERVER/have.txt" &&
675 # Sanity check to ensure that the client does not have
676 # deltabase_missing.
677 git -C repo rev-list --objects --ignore-missing \
678 -- $(cat deltabase_missing) >objlist &&
679 test_line_count = 0 objlist &&
681 # Another commit. This commit will be fetched by the client.
682 echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/foo.txt" &&
683 echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/have.txt" &&
684 git -C "$SERVER" add foo.txt have.txt &&
685 git -C "$SERVER" commit -m baz &&
687 # Pack a thin pack containing, among other things, HEAD:foo.txt
688 # delta-ed against HEAD^:foo.txt and HEAD:have.txt delta-ed against
689 # HEAD^:have.txt.
690 printf "%s\n--not\n%s\n" \
691 $(git -C "$SERVER" rev-parse HEAD) \
692 $(git -C "$SERVER" rev-parse HEAD^) |
693 git -C "$SERVER" pack-objects --thin --stdout >thin.pack &&
695 # Ensure that the pack contains one delta against HEAD^:foo.txt. Since
696 # the delta contains at least 26 novel characters, the size cannot be
697 # contained in 4 bits, so the object header will take up 2 bytes. The
698 # most significant nybble of the first byte is 0b1111 (0b1 to indicate
699 # that the header continues, and 0b111 to indicate REF_DELTA), followed
700 # by any 3 nybbles, then the OID of the delta base.
701 printf "f.,..%s" $(intersperse "," <deltabase_missing) >want &&
702 hex_unpack <thin.pack | intersperse "," >have &&
703 grep $(cat want) have &&
705 # Ensure that the pack contains one delta against HEAD^:have.txt,
706 # similar to the above.
707 printf "f.,..%s" $(intersperse "," <deltabase_have) >want &&
708 hex_unpack <thin.pack | intersperse "," >have &&
709 grep $(cat want) have &&
711 replace_packfile thin.pack &&
713 # Use protocol v2 because the perl command looks for the "packfile"
714 # section header.
715 test_config -C "$SERVER" protocol.version 2 &&
717 # Fetch the thin pack and ensure that index-pack is able to handle the
718 # REF_DELTA object with a missing promisor delta base.
719 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo -c protocol.version=2 fetch &&
721 # Ensure that the missing delta base was directly fetched, but not the
722 # one that the client has.
723 grep "want $(cat deltabase_missing)" trace &&
724 ! grep "want $(cat deltabase_have)" trace &&
726 # Ensure that the one-time-perl script was used.
727 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
730 # DO NOT add non-httpd-specific tests here, because the last part of this
731 # test script is only executed when httpd is available and enabled.
733 test_done