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