]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5616-partial-clone.sh
Sync with 2.31.5
[thirdparty/git.git] / t / t5616-partial-clone.sh
1 #!/bin/sh
2
3 test_description='git partial clone'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
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 &&
15
16 git init src &&
17 for n in 1 2 3 4
18 do
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
23 done &&
24 awk -f print_2.awk <temp | sort >expect_1.oids &&
25 test_line_count = 4 expect_1.oids
26 '
27
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
33 '
34
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 &&
40
41 git -C pc1 rev-list --quiet --objects --missing=print HEAD >revs &&
42 awk -f print_1.awk revs |
43 sed "s/?//" |
44 sort >observed.oids &&
45
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"
50 '
51
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)
58 '
59
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
67 '
68
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" &&
73 for x in a b c d e
74 do
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"
78 done &&
79 git -C src blame main -- file.1.txt >expect.blame &&
80 git -C src push -u srv main
81 '
82
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
85 # have the new blobs.
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
91 '
92
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
100 '
101
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
110 '
111
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' '
115 for x in a b c d e f
116 do
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"
120 done &&
121 git -C src push -u srv main
122 '
123
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
131 '
132
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' '
136 for x in a b c d e f
137 do
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"
141 done &&
142 git -C src push -u srv main
143 '
144
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 &&
150
151 git -C pc1 rev-list --quiet --objects --missing=print \
152 main..origin/main >revs &&
153 awk -f print_1.awk revs |
154 sed "s/?//" |
155 sort >observed.oids &&
156
157 test_line_count = 6 observed.oids &&
158 git -C pc1 fetch-pack --stdin "file://$(pwd)/srv.bare" <observed.oids &&
159
160 git -C pc1 rev-list --quiet --objects --missing=print \
161 main..origin/main >revs &&
162 awk -f print_1.awk revs |
163 sed "s/?//" |
164 sort >observed.oids &&
165
166 test_line_count = 0 observed.oids
167 '
168
169 test_expect_success 'partial clone with transfer.fsckobjects=1 works with submodules' '
170 test_create_repo submodule &&
171 test_commit -C submodule mycommit &&
172
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 &&
176
177 test_config_global protocol.file.allow always &&
178
179 git -C src_with_sub submodule add "file://$(pwd)/submodule" mysub &&
180 git -C src_with_sub commit -m "commit with submodule" &&
181
182 git -c transfer.fsckobjects=1 \
183 clone --filter="blob:none" "file://$(pwd)/src_with_sub" dst &&
184 test_when_finished rm -rf dst
185 '
186
187 test_expect_success 'partial clone with transfer.fsckobjects=1 uses index-pack --fsck-objects' '
188 git init src &&
189 test_commit -C src x &&
190 test_config -C src uploadpack.allowfilter 1 &&
191 test_config -C src uploadpack.allowanysha1inwant 1 &&
192
193 GIT_TRACE="$(pwd)/trace" git -c transfer.fsckobjects=1 \
194 clone --filter="blob:none" "file://$(pwd)/src" dst &&
195 grep "git index-pack.*--fsck-objects" trace
196 '
197
198 test_expect_success 'use fsck before and after manually fetching a missing subtree' '
199 # push new commit so server has a subtree
200 mkdir src/dir &&
201 echo "in dir" >src/dir/file.txt &&
202 git -C src add dir/file.txt &&
203 git -C src commit -m "file in dir" &&
204 git -C src push -u srv main &&
205 SUBTREE=$(git -C src rev-parse HEAD:dir) &&
206
207 rm -rf dst &&
208 git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" dst &&
209 git -C dst fsck &&
210
211 # Make sure we only have commits, and all trees and blobs are missing.
212 git -C dst rev-list --missing=allow-any --objects main \
213 >fetched_objects &&
214 awk -f print_1.awk fetched_objects |
215 xargs -n1 git -C dst cat-file -t >fetched_types &&
216
217 sort -u fetched_types >unique_types.observed &&
218 echo commit >unique_types.expected &&
219 test_cmp unique_types.expected unique_types.observed &&
220
221 # Auto-fetch a tree with cat-file.
222 git -C dst cat-file -p $SUBTREE >tree_contents &&
223 grep file.txt tree_contents &&
224
225 # fsck still works after an auto-fetch of a tree.
226 git -C dst fsck &&
227
228 # Auto-fetch all remaining trees and blobs with --missing=error
229 git -C dst rev-list --missing=error --objects main >fetched_objects &&
230 test_line_count = 70 fetched_objects &&
231
232 awk -f print_1.awk fetched_objects |
233 xargs -n1 git -C dst cat-file -t >fetched_types &&
234
235 sort -u fetched_types >unique_types.observed &&
236 test_write_lines blob commit tree >unique_types.expected &&
237 test_cmp unique_types.expected unique_types.observed
238 '
239
240 test_expect_success 'implicitly construct combine: filter with repeated flags' '
241 GIT_TRACE=$(pwd)/trace git clone --bare \
242 --filter=blob:none --filter=tree:1 \
243 "file://$(pwd)/srv.bare" pc2 &&
244 grep "trace:.* git pack-objects .*--filter=combine:blob:none+tree:1" \
245 trace &&
246 git -C pc2 rev-list --objects --missing=allow-any HEAD >objects &&
247
248 # We should have gotten some root trees.
249 grep " $" objects &&
250 # Should not have gotten any non-root trees or blobs.
251 ! grep " ." objects &&
252
253 xargs -n 1 git -C pc2 cat-file -t <objects >types &&
254 sort -u types >unique_types.actual &&
255 test_write_lines commit tree >unique_types.expected &&
256 test_cmp unique_types.expected unique_types.actual
257 '
258
259 test_expect_success 'upload-pack complains of bogus filter config' '
260 printf 0000 |
261 test_must_fail git \
262 -c uploadpackfilter.tree.maxdepth \
263 upload-pack . >/dev/null 2>err &&
264 test_i18ngrep "unable to parse.*tree.maxdepth" err
265 '
266
267 test_expect_success 'upload-pack fails banned object filters' '
268 test_config -C srv.bare uploadpackfilter.blob:none.allow false &&
269 test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \
270 "file://$(pwd)/srv.bare" pc3 2>err &&
271 test_i18ngrep "filter '\''blob:none'\'' not supported" err
272 '
273
274 test_expect_success 'upload-pack fails banned combine object filters' '
275 test_config -C srv.bare uploadpackfilter.allow false &&
276 test_config -C srv.bare uploadpackfilter.combine.allow true &&
277 test_config -C srv.bare uploadpackfilter.tree.allow true &&
278 test_config -C srv.bare uploadpackfilter.blob:none.allow false &&
279 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \
280 --filter=blob:none "file://$(pwd)/srv.bare" pc3 2>err &&
281 test_i18ngrep "filter '\''blob:none'\'' not supported" err
282 '
283
284 test_expect_success 'upload-pack fails banned object filters with fallback' '
285 test_config -C srv.bare uploadpackfilter.allow false &&
286 test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \
287 "file://$(pwd)/srv.bare" pc3 2>err &&
288 test_i18ngrep "filter '\''blob:none'\'' not supported" err
289 '
290
291 test_expect_success 'upload-pack limits tree depth filters' '
292 test_config -C srv.bare uploadpackfilter.allow false &&
293 test_config -C srv.bare uploadpackfilter.tree.allow true &&
294 test_config -C srv.bare uploadpackfilter.tree.maxDepth 0 &&
295 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \
296 "file://$(pwd)/srv.bare" pc3 2>err &&
297 test_i18ngrep "tree filter allows max depth 0, but got 1" err &&
298
299 git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" pc4 &&
300
301 test_config -C srv.bare uploadpackfilter.tree.maxDepth 5 &&
302 git clone --no-checkout --filter=tree:5 "file://$(pwd)/srv.bare" pc5 &&
303 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:6 \
304 "file://$(pwd)/srv.bare" pc6 2>err &&
305 test_i18ngrep "tree filter allows max depth 5, but got 6" err
306 '
307
308 test_expect_success 'partial clone fetches blobs pointed to by refs even if normally filtered out' '
309 rm -rf src dst &&
310 git init src &&
311 test_commit -C src x &&
312 test_config -C src uploadpack.allowfilter 1 &&
313 test_config -C src uploadpack.allowanysha1inwant 1 &&
314
315 # Create a tag pointing to a blob.
316 BLOB=$(echo blob-contents | git -C src hash-object --stdin -w) &&
317 git -C src tag myblob "$BLOB" &&
318
319 git clone --filter="blob:none" "file://$(pwd)/src" dst 2>err &&
320 ! grep "does not point to a valid object" err &&
321 git -C dst fsck
322 '
323
324 test_expect_success 'fetch what is specified on CLI even if already promised' '
325 rm -rf src dst.git &&
326 git init src &&
327 test_commit -C src foo &&
328 test_config -C src uploadpack.allowfilter 1 &&
329 test_config -C src uploadpack.allowanysha1inwant 1 &&
330
331 git hash-object --stdin <src/foo.t >blob &&
332
333 git clone --bare --filter=blob:none "file://$(pwd)/src" dst.git &&
334 git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_before &&
335 grep "?$(cat blob)" missing_before &&
336 git -C dst.git fetch origin $(cat blob) &&
337 git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_after &&
338 ! grep "?$(cat blob)" missing_after
339 '
340
341 test_expect_success 'setup src repo for sparse filter' '
342 git init sparse-src &&
343 git -C sparse-src config --local uploadpack.allowfilter 1 &&
344 git -C sparse-src config --local uploadpack.allowanysha1inwant 1 &&
345 test_commit -C sparse-src one &&
346 test_commit -C sparse-src two &&
347 echo /one.t >sparse-src/only-one &&
348 git -C sparse-src add . &&
349 git -C sparse-src commit -m "add sparse checkout files"
350 '
351
352 test_expect_success 'partial clone with sparse filter succeeds' '
353 rm -rf dst.git &&
354 git clone --no-local --bare \
355 --filter=sparse:oid=main:only-one \
356 sparse-src dst.git &&
357 (
358 cd dst.git &&
359 git rev-list --objects --missing=print HEAD >out &&
360 grep "^$(git rev-parse HEAD:one.t)" out &&
361 grep "^?$(git rev-parse HEAD:two.t)" out
362 )
363 '
364
365 test_expect_success 'partial clone with unresolvable sparse filter fails cleanly' '
366 rm -rf dst.git &&
367 test_must_fail git clone --no-local --bare \
368 --filter=sparse:oid=main:no-such-name \
369 sparse-src dst.git 2>err &&
370 test_i18ngrep "unable to access sparse blob in .main:no-such-name" err &&
371 test_must_fail git clone --no-local --bare \
372 --filter=sparse:oid=main \
373 sparse-src dst.git 2>err &&
374 test_i18ngrep "unable to parse sparse filter data in" err
375 '
376
377 setup_triangle () {
378 rm -rf big-blob.txt server client promisor-remote &&
379
380 printf "line %d\n" $(test_seq 1 100) >big-blob.txt &&
381
382 # Create a server with 2 commits: a commit with a big tree and a child
383 # commit with an incremental change. Also, create a partial clone
384 # client that only contains the first commit.
385 git init server &&
386 git -C server config --local uploadpack.allowfilter 1 &&
387 for i in $(test_seq 1 100)
388 do
389 echo "make the tree big" >server/file$i &&
390 git -C server add file$i
391 done &&
392 git -C server commit -m "initial" &&
393 git clone --bare --filter=tree:0 "file://$(pwd)/server" client &&
394 echo another line >>server/file1 &&
395 git -C server commit -am "incremental change" &&
396
397 # Create a promisor remote that only contains the tree and blob from
398 # the first commit.
399 git init promisor-remote &&
400 git -C server config --local uploadpack.allowanysha1inwant 1 &&
401 TREE_HASH=$(git -C server rev-parse HEAD~1^{tree}) &&
402 git -C promisor-remote fetch --keep "file://$(pwd)/server" "$TREE_HASH" &&
403 git -C promisor-remote count-objects -v >object-count &&
404 test_i18ngrep "count: 0" object-count &&
405 test_i18ngrep "in-pack: 2" object-count &&
406
407 # Set it as the promisor remote of client. Thus, whenever
408 # the client lazy fetches, the lazy fetch will succeed only if it is
409 # for this tree or blob.
410 test_commit -C promisor-remote one && # so that ref advertisement is not empty
411 git -C promisor-remote config --local uploadpack.allowanysha1inwant 1 &&
412 git -C client remote set-url origin "file://$(pwd)/promisor-remote"
413 }
414
415 # NEEDSWORK: The tests beginning with "fetch lazy-fetches" below only
416 # test that "fetch" avoid fetching trees and blobs, but not commits or
417 # tags. Revisit this if Git is ever taught to support partial clones
418 # with commits and/or tags filtered out.
419
420 test_expect_success 'fetch lazy-fetches only to resolve deltas' '
421 setup_triangle &&
422
423 # Exercise to make sure it works. Git will not fetch anything from the
424 # promisor remote other than for the big tree (because it needs to
425 # resolve the delta).
426 GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
427 fetch "file://$(pwd)/server" main &&
428
429 # Verify the assumption that the client needed to fetch the delta base
430 # to resolve the delta.
431 git -C server rev-parse HEAD~1^{tree} >hash &&
432 grep "want $(cat hash)" trace
433 '
434
435 test_expect_success 'fetch lazy-fetches only to resolve deltas, protocol v2' '
436 setup_triangle &&
437
438 git -C server config --local protocol.version 2 &&
439 git -C client config --local protocol.version 2 &&
440 git -C promisor-remote config --local protocol.version 2 &&
441
442 # Exercise to make sure it works. Git will not fetch anything from the
443 # promisor remote other than for the big blob (because it needs to
444 # resolve the delta).
445 GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
446 fetch "file://$(pwd)/server" main &&
447
448 # Verify that protocol version 2 was used.
449 grep "fetch< version 2" trace &&
450
451 # Verify the assumption that the client needed to fetch the delta base
452 # to resolve the delta.
453 git -C server rev-parse HEAD~1^{tree} >hash &&
454 grep "want $(cat hash)" trace
455 '
456
457 test_expect_success 'fetch does not lazy-fetch missing targets of its refs' '
458 rm -rf server client trace &&
459
460 test_create_repo server &&
461 test_config -C server uploadpack.allowfilter 1 &&
462 test_config -C server uploadpack.allowanysha1inwant 1 &&
463 test_commit -C server foo &&
464
465 git clone --filter=blob:none "file://$(pwd)/server" client &&
466 # Make all refs point to nothing by deleting all objects.
467 rm client/.git/objects/pack/* &&
468
469 test_commit -C server bar &&
470 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
471 --no-tags --recurse-submodules=no \
472 origin refs/tags/bar &&
473 FOO_HASH=$(git -C server rev-parse foo) &&
474 ! grep "want $FOO_HASH" trace
475 '
476
477 # The following two tests must be in this order. It is important that
478 # the srv.bare repository did not have tags during clone, but has tags
479 # in the fetch.
480
481 test_expect_success 'verify fetch succeeds when asking for new tags' '
482 git clone --filter=blob:none "file://$(pwd)/srv.bare" tag-test &&
483 for i in I J K
484 do
485 test_commit -C src $i &&
486 git -C src branch $i || return 1
487 done &&
488 git -C srv.bare fetch --tags origin +refs/heads/*:refs/heads/* &&
489 git -C tag-test -c protocol.version=2 fetch --tags origin
490 '
491
492 test_expect_success 'verify fetch downloads only one pack when updating refs' '
493 git clone --filter=blob:none "file://$(pwd)/srv.bare" pack-test &&
494 ls pack-test/.git/objects/pack/*pack >pack-list &&
495 test_line_count = 2 pack-list &&
496 for i in A B C
497 do
498 test_commit -C src $i &&
499 git -C src branch $i || return 1
500 done &&
501 git -C srv.bare fetch origin +refs/heads/*:refs/heads/* &&
502 git -C pack-test fetch origin &&
503 ls pack-test/.git/objects/pack/*pack >pack-list &&
504 test_line_count = 3 pack-list
505 '
506
507 test_expect_success 'single-branch tag following respects partial clone' '
508 git clone --single-branch -b B --filter=blob:none \
509 "file://$(pwd)/srv.bare" single &&
510 git -C single rev-parse --verify refs/tags/B &&
511 git -C single rev-parse --verify refs/tags/A &&
512 test_must_fail git -C single rev-parse --verify refs/tags/C
513 '
514
515 test_expect_success 'fetch from a partial clone, protocol v0' '
516 rm -rf server client trace &&
517
518 # Pretend that the server is a partial clone
519 git init server &&
520 git -C server remote add a_remote "file://$(pwd)/" &&
521 test_config -C server core.repositoryformatversion 1 &&
522 test_config -C server extensions.partialclone a_remote &&
523 test_config -C server protocol.version 0 &&
524 test_commit -C server foo &&
525
526 # Fetch from the server
527 git init client &&
528 test_config -C client protocol.version 0 &&
529 test_commit -C client bar &&
530 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" &&
531 ! grep "version 2" trace
532 '
533
534 test_expect_success 'fetch from a partial clone, protocol v2' '
535 rm -rf server client trace &&
536
537 # Pretend that the server is a partial clone
538 git init server &&
539 git -C server remote add a_remote "file://$(pwd)/" &&
540 test_config -C server core.repositoryformatversion 1 &&
541 test_config -C server extensions.partialclone a_remote &&
542 test_config -C server protocol.version 2 &&
543 test_commit -C server foo &&
544
545 # Fetch from the server
546 git init client &&
547 test_config -C client protocol.version 2 &&
548 test_commit -C client bar &&
549 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" &&
550 grep "version 2" trace
551 '
552
553 test_expect_success 'repack does not loosen promisor objects' '
554 rm -rf client trace &&
555 git clone --bare --filter=blob:none "file://$(pwd)/srv.bare" client &&
556 test_when_finished "rm -rf client trace" &&
557 GIT_TRACE2_PERF="$(pwd)/trace" git -C client repack -A -d &&
558 grep "loosen_unused_packed_objects/loosened:0" trace
559 '
560
561 . "$TEST_DIRECTORY"/lib-httpd.sh
562 start_httpd
563
564 # Converts bytes into their hexadecimal representation. For example,
565 # "printf 'ab\r\n' | hex_unpack" results in '61620d0a'.
566 hex_unpack () {
567 perl -e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)'
568 }
569
570 # Inserts $1 at the start of the string and every 2 characters thereafter.
571 intersperse () {
572 sed 's/\(..\)/'$1'\1/g'
573 }
574
575 # Create a one-time-perl command to replace the existing packfile with $1.
576 replace_packfile () {
577 # The protocol requires that the packfile be sent in sideband 1, hence
578 # the extra \x01 byte at the beginning.
579 cp $1 "$HTTPD_ROOT_PATH/one-time-pack" &&
580 echo 'if (/packfile/) {
581 print;
582 my $length = -s "one-time-pack";
583 printf "%04x\x01", $length + 5;
584 print `cat one-time-pack` . "0000";
585 last
586 }' >"$HTTPD_ROOT_PATH/one-time-perl"
587 }
588
589 test_expect_success 'upon cloning, check that all refs point to objects' '
590 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
591 rm -rf "$SERVER" repo &&
592 test_create_repo "$SERVER" &&
593 test_commit -C "$SERVER" foo &&
594 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
595 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
596
597 # Create a tag pointing to a blob.
598 BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
599 git -C "$SERVER" tag myblob "$BLOB" &&
600
601 # Craft a packfile not including that blob.
602 git -C "$SERVER" rev-parse HEAD |
603 git -C "$SERVER" pack-objects --stdout >incomplete.pack &&
604
605 # Replace the existing packfile with the crafted one. The protocol
606 # requires that the packfile be sent in sideband 1, hence the extra
607 # \x01 byte at the beginning.
608 replace_packfile incomplete.pack &&
609
610 # Use protocol v2 because the perl command looks for the "packfile"
611 # section header.
612 test_config -C "$SERVER" protocol.version 2 &&
613 test_must_fail git -c protocol.version=2 clone \
614 --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2>err &&
615
616 test_i18ngrep "did not send all necessary objects" err &&
617
618 # Ensure that the one-time-perl script was used.
619 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
620 '
621
622 test_expect_success 'when partial cloning, tolerate server not sending target of tag' '
623 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
624 rm -rf "$SERVER" repo &&
625 test_create_repo "$SERVER" &&
626 test_commit -C "$SERVER" foo &&
627 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
628 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
629
630 # Create an annotated tag pointing to a blob.
631 BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
632 git -C "$SERVER" tag -m message -a myblob "$BLOB" &&
633
634 # Craft a packfile including the tag, but not the blob it points to.
635 # Also, omit objects referenced from HEAD in order to force a second
636 # fetch (to fetch missing objects) upon the automatic checkout that
637 # happens after a clone.
638 printf "%s\n%s\n--not\n%s\n%s\n" \
639 $(git -C "$SERVER" rev-parse HEAD) \
640 $(git -C "$SERVER" rev-parse myblob) \
641 $(git -C "$SERVER" rev-parse HEAD^{tree}) \
642 $(git -C "$SERVER" rev-parse myblob^{blob}) |
643 git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack &&
644
645 # Replace the existing packfile with the crafted one. The protocol
646 # requires that the packfile be sent in sideband 1, hence the extra
647 # \x01 byte at the beginning.
648 replace_packfile incomplete.pack &&
649
650 # Use protocol v2 because the perl command looks for the "packfile"
651 # section header.
652 test_config -C "$SERVER" protocol.version 2 &&
653
654 # Exercise to make sure it works.
655 git -c protocol.version=2 clone \
656 --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2> err &&
657 ! grep "missing object referenced by" err &&
658
659 # Ensure that the one-time-perl script was used.
660 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
661 '
662
663 test_expect_success 'tolerate server sending REF_DELTA against missing promisor objects' '
664 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
665 rm -rf "$SERVER" repo &&
666 test_create_repo "$SERVER" &&
667 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
668 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
669
670 # Create a commit with 2 blobs to be used as delta bases.
671 for i in $(test_seq 10)
672 do
673 echo "this is a line" >>"$SERVER/foo.txt" &&
674 echo "this is another line" >>"$SERVER/have.txt"
675 done &&
676 git -C "$SERVER" add foo.txt have.txt &&
677 git -C "$SERVER" commit -m bar &&
678 git -C "$SERVER" rev-parse HEAD:foo.txt >deltabase_missing &&
679 git -C "$SERVER" rev-parse HEAD:have.txt >deltabase_have &&
680
681 # Clone. The client has deltabase_have but not deltabase_missing.
682 git -c protocol.version=2 clone --no-checkout \
683 --filter=blob:none $HTTPD_URL/one_time_perl/server repo &&
684 git -C repo hash-object -w -- "$SERVER/have.txt" &&
685
686 # Sanity check to ensure that the client does not have
687 # deltabase_missing.
688 git -C repo rev-list --objects --ignore-missing \
689 -- $(cat deltabase_missing) >objlist &&
690 test_line_count = 0 objlist &&
691
692 # Another commit. This commit will be fetched by the client.
693 echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/foo.txt" &&
694 echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/have.txt" &&
695 git -C "$SERVER" add foo.txt have.txt &&
696 git -C "$SERVER" commit -m baz &&
697
698 # Pack a thin pack containing, among other things, HEAD:foo.txt
699 # delta-ed against HEAD^:foo.txt and HEAD:have.txt delta-ed against
700 # HEAD^:have.txt.
701 printf "%s\n--not\n%s\n" \
702 $(git -C "$SERVER" rev-parse HEAD) \
703 $(git -C "$SERVER" rev-parse HEAD^) |
704 git -C "$SERVER" pack-objects --thin --stdout >thin.pack &&
705
706 # Ensure that the pack contains one delta against HEAD^:foo.txt. Since
707 # the delta contains at least 26 novel characters, the size cannot be
708 # contained in 4 bits, so the object header will take up 2 bytes. The
709 # most significant nybble of the first byte is 0b1111 (0b1 to indicate
710 # that the header continues, and 0b111 to indicate REF_DELTA), followed
711 # by any 3 nybbles, then the OID of the delta base.
712 printf "f.,..%s" $(intersperse "," <deltabase_missing) >want &&
713 hex_unpack <thin.pack | intersperse "," >have &&
714 grep $(cat want) have &&
715
716 # Ensure that the pack contains one delta against HEAD^:have.txt,
717 # similar to the above.
718 printf "f.,..%s" $(intersperse "," <deltabase_have) >want &&
719 hex_unpack <thin.pack | intersperse "," >have &&
720 grep $(cat want) have &&
721
722 replace_packfile thin.pack &&
723
724 # Use protocol v2 because the perl command looks for the "packfile"
725 # section header.
726 test_config -C "$SERVER" protocol.version 2 &&
727
728 # Fetch the thin pack and ensure that index-pack is able to handle the
729 # REF_DELTA object with a missing promisor delta base.
730 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo -c protocol.version=2 fetch &&
731
732 # Ensure that the missing delta base was directly fetched, but not the
733 # one that the client has.
734 grep "want $(cat deltabase_missing)" trace &&
735 ! grep "want $(cat deltabase_have)" trace &&
736
737 # Ensure that the one-time-perl script was used.
738 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
739 '
740
741 # DO NOT add non-httpd-specific tests here, because the last part of this
742 # test script is only executed when httpd is available and enabled.
743
744 test_done