Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/git/blob/master/t/t5500-fetch-pack.sh
# git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
branch `master` Branches Tags History
`git / t / t5500-fetch-pack.sh`
1121 lines ยท 29827 bytes Raw Blame History
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Johannes Schindelin
4 #
5
6 test_description='Testing multi_ack pack fetching'
7
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 . ./test-lib.sh
12
13 # Test fetch-pack/upload-pack pair.
14
15 # Some convenience functions
16
17 add () {
18 name=$1 &&
19 text="$@" &&
20 branch=$(echo $name | sed -e 's/^\(.\).*$/\1/') &&
21 parents="" &&
22
23 shift &&
24 while test $1; do
25 parents="$parents -p $1" &&
26 shift
27 done &&
28
29 echo "$text" > test.txt &&
30 git update-index --add test.txt &&
31 tree=$(git write-tree) &&
32 # make sure timestamps are in correct order
33 test_tick &&
34 commit=$(echo "$text" | git commit-tree $tree $parents) &&
35 eval "$name=$commit; export $name" &&
36 git update-ref "refs/heads/$branch" "$commit" &&
37 eval ${branch}TIP=$commit
38 }
39
40 pull_to_client () {
41 number=$1 &&
42 heads=$2 &&
43 count=$3 &&
44 test_expect_success "$number pull" '
45 (
46 cd client &&
47 git fetch-pack -k -v .. $heads &&
48
49 case "$heads" in
50 *A*)
51 git update-ref refs/heads/A "$ATIP";;
52 esac &&
53 case "$heads" in *B*)
54 git update-ref refs/heads/B "$BTIP";;
55 esac &&
56
57 git symbolic-ref HEAD refs/heads/$(
58 echo $heads |
59 sed -e "s/^\(.\).*$/\1/"
60 ) &&
61
62 git fsck --full &&
63
64 mv .git/objects/pack/pack-* . &&
65 p=$(ls -1 pack-*.pack) &&
66 git unpack-objects <$p &&
67 git fsck --full &&
68
69 idx=$(echo pack-*.idx) &&
70 pack_count=$(git show-index <$idx | wc -l) &&
71 test $pack_count = $count &&
72 rm -f pack-*
73 )
74 '
75 }
76
77 # Here begins the actual testing
78
79 # A1 - ... - A20 - A21
80 # \
81 # B1 - B2 - .. - B70
82
83 # client pulls A20, B1. Then tracks only B. Then pulls A.
84
85 test_expect_success 'setup' '
86 mkdir client &&
87 (
88 cd client &&
89 git init &&
90 git config transfer.unpacklimit 0
91 ) &&
92 add A1 &&
93 prev=1 &&
94 cur=2 &&
95 while [ $cur -le 10 ]; do
96 add A$cur $(eval echo \$A$prev) &&
97 prev=$cur &&
98 cur=$(($cur+1)) || return 1
99 done &&
100 add B1 $A1 &&
101 git update-ref refs/heads/A "$ATIP" &&
102 git update-ref refs/heads/B "$BTIP" &&
103 git symbolic-ref HEAD refs/heads/B
104 '
105
106 pull_to_client 1st "refs/heads/B refs/heads/A" $((11*3))
107
108 test_expect_success 'post 1st pull setup' '
109 add A11 $A10 &&
110 prev=1 &&
111 cur=2 &&
112 while [ $cur -le 65 ]; do
113 add B$cur $(eval echo \$B$prev) &&
114 prev=$cur &&
115 cur=$(($cur+1)) || return 1
116 done
117 '
118
119 pull_to_client 2nd "refs/heads/B" $((64*3))
120
121 pull_to_client 3rd "refs/heads/A" $((1*3))
122
123 test_expect_success 'single branch clone' '
124 git clone --single-branch "file://$(pwd)/." singlebranch
125 '
126
127 test_expect_success 'single branch object count' '
128 GIT_DIR=singlebranch/.git git count-objects -v |
129 grep "^in-pack:" > count.singlebranch &&
130 echo "in-pack: 198" >expected &&
131 test_cmp expected count.singlebranch
132 '
133
134 test_expect_success 'single given branch clone' '
135 GIT_TRACE2_EVENT="$(pwd)/branch-a/trace2_event" \
136 git clone --single-branch --branch A "file://$(pwd)/." branch-a &&
137 test_must_fail git --git-dir=branch-a/.git rev-parse origin/B &&
138 test_grep \"fetch-info\".*\"haves\":0 branch-a/trace2_event &&
139 test_grep \"fetch-info\".*\"wants\":1 branch-a/trace2_event
140 '
141
142 test_expect_success 'clone shallow depth 1' '
143 GIT_TRACE2_EVENT="$(pwd)/shallow0/trace2_event" \
144 git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0 &&
145 test "$(git --git-dir=shallow0/.git rev-list --count HEAD)" = 1 &&
146 test_grep \"fetch-info\".*\"depth\":1 shallow0/trace2_event
147 '
148
149 test_expect_success 'clone shallow depth 1 with fsck' '
150 git config --global fetch.fsckobjects true &&
151 git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0fsck &&
152 test "$(git --git-dir=shallow0fsck/.git rev-list --count HEAD)" = 1 &&
153 git config --global --unset fetch.fsckobjects
154 '
155
156 test_expect_success 'clone shallow' '
157 git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow &&
158 git -C shallow config set maintenance.auto false
159 '
160
161 test_expect_success 'clone shallow depth count' '
162 test "$(git --git-dir=shallow/.git rev-list --count HEAD)" = 2
163 '
164
165 test_expect_success 'clone shallow object count' '
166 (
167 cd shallow &&
168 git count-objects -v
169 ) > count.shallow &&
170 test_grep "^in-pack: 12" count.shallow
171 '
172
173 test_expect_success 'clone shallow object count (part 2)' '
174 sed -e "/^in-pack:/d" -e "/^packs:/d" -e "/^size-pack:/d" \
175 -e "/: 0$/d" count.shallow > count_output &&
176 test_must_be_empty count_output
177 '
178
179 test_expect_success 'fsck in shallow repo' '
180 (
181 cd shallow &&
182 git fsck --full
183 )
184 '
185
186 test_expect_success 'simple fetch in shallow repo' '
187 (
188 cd shallow &&
189 git fetch
190 )
191 '
192
193 test_expect_success 'no changes expected' '
194 (
195 cd shallow &&
196 git count-objects -v
197 ) > count.shallow.2 &&
198 cmp count.shallow count.shallow.2
199 '
200
201 test_expect_success 'fetch same depth in shallow repo' '
202 (
203 cd shallow &&
204 git fetch --depth=2
205 )
206 '
207
208 test_expect_success 'no changes expected' '
209 (
210 cd shallow &&
211 git count-objects -v
212 ) > count.shallow.3 &&
213 cmp count.shallow count.shallow.3
214 '
215
216 test_expect_success 'add two more' '
217 add B66 $B65 &&
218 add B67 $B66
219 '
220
221 test_expect_success 'pull in shallow repo' '
222 (
223 cd shallow &&
224 git pull .. B
225 )
226 '
227
228 test_expect_success 'clone shallow object count' '
229 (
230 cd shallow &&
231 git count-objects -v
232 ) > count.shallow &&
233 test_grep "^count: 6" count.shallow
234 '
235
236 test_expect_success 'add two more (part 2)' '
237 add B68 $B67 &&
238 add B69 $B68
239 '
240
241 test_expect_success 'deepening pull in shallow repo' '
242 (
243 cd shallow &&
244 GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
245 git pull --depth 4 .. B &&
246 test_grep \"fetch-info\".*\"depth\":4 trace2_event &&
247 test_grep \"fetch-info\".*\"shallows\":2 trace2_event
248 )
249 '
250
251 test_expect_success 'clone shallow object count' '
252 (
253 cd shallow &&
254 git count-objects -v
255 ) > count.shallow &&
256 test_grep "^count: 12" count.shallow
257 '
258
259 test_expect_success 'deepening fetch in shallow repo' '
260 (
261 cd shallow &&
262 git fetch --depth 4 .. A:A
263 )
264 '
265
266 test_expect_success 'clone shallow object count' '
267 (
268 cd shallow &&
269 git count-objects -v
270 ) > count.shallow &&
271 test_grep "^count: 18" count.shallow
272 '
273
274 test_expect_success 'pull in shallow repo with missing merge base' '
275 (
276 cd shallow &&
277 git fetch --depth 4 .. A &&
278 test_must_fail git merge --allow-unrelated-histories FETCH_HEAD
279 )
280 '
281
282 test_expect_success 'additional simple shallow deepenings' '
283 (
284 cd shallow &&
285 git fetch --depth=8 &&
286 git fetch --depth=10 &&
287 git fetch --depth=11
288 )
289 '
290
291 test_expect_success 'clone shallow depth count' '
292 test "$(git --git-dir=shallow/.git rev-list --count HEAD)" = 11
293 '
294
295 test_expect_success 'clone shallow object count' '
296 (
297 cd shallow &&
298 git prune &&
299 git count-objects -v
300 ) > count.shallow &&
301 test_grep "^count: 54" count.shallow
302 '
303
304 test_expect_success 'fetch --no-shallow on full repo' '
305 test_must_fail git fetch --noshallow
306 '
307
308 test_expect_success 'fetch --depth --no-shallow' '
309 (
310 cd shallow &&
311 test_must_fail git fetch --depth=1 --noshallow
312 )
313 '
314
315 test_expect_success 'turn shallow to complete repository' '
316 (
317 cd shallow &&
318 GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
319 git fetch --unshallow &&
320 ! test -f .git/shallow &&
321 git fsck --full &&
322 test_grep \"fetch-info\".*\"shallows\":2 trace2_event &&
323 test_grep \"fetch-info\".*\"depth\":`2147483647` trace2_event
324 )
325 '
326
327 test_expect_success 'clone shallow without --no-single-branch' '
328 git clone --depth 1 "file://$(pwd)/." shallow2
329 '
330
331 test_expect_success 'clone shallow object count' '
332 (
333 cd shallow2 &&
334 git count-objects -v
335 ) > count.shallow2 &&
336 test_grep "^in-pack: 3" count.shallow2
337 '
338
339 test_expect_success 'clone shallow with --branch' '
340 git clone --depth 1 --branch A "file://$(pwd)/." shallow3
341 '
342
343 test_expect_success 'clone shallow object count' '
344 echo "in-pack: 3" > count3.expected &&
345 GIT_DIR=shallow3/.git git count-objects -v |
346 grep "^in-pack" > count3.actual &&
347 test_cmp count3.expected count3.actual
348 '
349
350 test_expect_success 'clone shallow with detached HEAD' '
351 git checkout HEAD^ &&
352 git clone --depth 1 "file://$(pwd)/." shallow5 &&
353 git checkout - &&
354 GIT_DIR=shallow5/.git git rev-parse HEAD >actual &&
355 git rev-parse HEAD^ >expected &&
356 test_cmp expected actual
357 '
358
359 test_expect_success 'shallow clone pulling tags' '
360 git tag -a -m A TAGA1 A &&
361 git tag -a -m B TAGB1 B &&
362 git tag TAGA2 A &&
363 git tag TAGB2 B &&
364 git clone --depth 1 "file://$(pwd)/." shallow6 &&
365
366 cat >taglist.expected <<\EOF &&
367 TAGB1
368 TAGB2
369 EOF
370 GIT_DIR=shallow6/.git git tag -l >taglist.actual &&
371 test_cmp taglist.expected taglist.actual &&
372
373 echo "in-pack: 4" > count6.expected &&
374 GIT_DIR=shallow6/.git git count-objects -v |
375 grep "^in-pack" > count6.actual &&
376 test_cmp count6.expected count6.actual
377 '
378
379 test_expect_success 'shallow cloning single tag' '
380 git clone --depth 1 --branch=TAGB1 "file://$(pwd)/." shallow7 &&
381 cat >taglist.expected <<\EOF &&
382 TAGB1
383 TAGB2
384 EOF
385 GIT_DIR=shallow7/.git git tag -l >taglist.actual &&
386 test_cmp taglist.expected taglist.actual &&
387
388 echo "in-pack: 4" > count7.expected &&
389 GIT_DIR=shallow7/.git git count-objects -v |
390 grep "^in-pack" > count7.actual &&
391 test_cmp count7.expected count7.actual
392 '
393
394 test_expect_success 'clone shallow with packed refs' '
395 git pack-refs --all &&
396 git clone --depth 1 --branch A "file://$(pwd)/." shallow8 &&
397 echo "in-pack: 4" > count8.expected &&
398 GIT_DIR=shallow8/.git git count-objects -v |
399 grep "^in-pack" > count8.actual &&
400 test_cmp count8.expected count8.actual
401 '
402
403 test_expect_success 'in_vain not triggered before first ACK' '
404 rm -rf myserver myclient &&
405 git init myserver &&
406 test_commit -C myserver foo &&
407 git clone "file://$(pwd)/myserver" myclient &&
408
409 # MAX_IN_VAIN is 256. Because of batching, the client will send 496
410 # (16+32+64+128+256) commits, not 256, before giving up. So create 496
411 # irrelevant commits.
412 test_commit_bulk -C myclient 496 &&
413
414 # The new commit that the client wants to fetch.
415 test_commit -C myserver bar &&
416
417 git -C myclient fetch --progress origin 2>log &&
418 test_grep "remote: Total 3 " log
419 '
420
421 test_expect_success 'in_vain reset upon ACK' '
422 test_when_finished rm -f log trace2 &&
423 rm -rf myserver myclient &&
424 git init myserver &&
425
426 # Linked list of commits on main. The first is common; the rest are
427 # not.
428 test_commit -C myserver first_main_commit &&
429 git clone "file://$(pwd)/myserver" myclient &&
430 test_commit_bulk -C myclient 255 &&
431
432 # Another linked list of commits on anotherbranch with no connection to
433 # main. The first is common; the rest are not.
434 git -C myserver checkout --orphan anotherbranch &&
435 test_commit -C myserver first_anotherbranch_commit &&
436 git -C myclient fetch origin anotherbranch:refs/heads/anotherbranch &&
437 git -C myclient checkout anotherbranch &&
438 test_commit_bulk -C myclient 255 &&
439
440 # The new commit that the client wants to fetch.
441 git -C myserver checkout main &&
442 test_commit -C myserver to_fetch &&
443
444 # The client will send (as "have"s) all 256 commits in anotherbranch
445 # first. The 256th commit is common between the client and the server,
446 # and should reset in_vain. This allows negotiation to continue until
447 # the client reports that first_anotherbranch_commit is common.
448 GIT_TRACE2_EVENT="$(pwd)/trace2" git -C myclient fetch --progress origin main 2>log &&
449 test_grep \"key\":\"total_rounds\",\"value\":\"6\" trace2 &&
450 test_grep "Total 3 " log
451 '
452
453 test_expect_success 'fetch in shallow repo unreachable shallow objects' '
454 (
455 git clone --bare --branch B --single-branch "file://$(pwd)/." no-reflog &&
456 git clone --depth 1 "file://$(pwd)/no-reflog" shallow9 &&
457 cd no-reflog &&
458 git tag -d TAGB1 TAGB2 &&
459 git update-ref refs/heads/B B~~ &&
460 git gc --prune=now &&
461 cd ../shallow9 &&
462 git fetch origin &&
463 git fsck --no-dangling
464 )
465 '
466 test_expect_success 'fetch creating new shallow root' '
467 (
468 git clone "file://$(pwd)/." shallow10 &&
469 git commit --allow-empty -m empty &&
470 cd shallow10 &&
471 git fetch --depth=1 --progress 2>actual &&
472 # This should fetch only the empty commit, no tree or
473 # blob objects
474 test_grep "remote: Total 1" actual
475 )
476 '
477
478 test_expect_success 'setup tests for the --stdin parameter' '
479 for head in C D E F
480 do
481 add $head || return 1
482 done &&
483 for head in A B C D E F
484 do
485 git tag $head $head || return 1
486 done &&
487 cat >input <<-\EOF &&
488 refs/heads/C
489 refs/heads/A
490 refs/heads/D
491 refs/tags/C
492 refs/heads/B
493 refs/tags/A
494 refs/heads/E
495 refs/tags/B
496 refs/tags/E
497 refs/tags/D
498 EOF
499 sort expect &&
500 (
501 echo refs/heads/E &&
502 echo refs/tags/E &&
503 cat input
504 ) >input.dup
505 '
506
507 test_expect_success 'setup fetch refs from cmdline v[12]' '
508 cp -r client client0 &&
509 cp -r client client1 &&
510 cp -r client client2
511 '
512
513 for version in '' 0 1 2
514 do
515 test_expect_success "protocol.version=$version fetch refs from cmdline" "
516 (
517 cd client$version &&
518 GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. \$(cat ../input)
519 ) >output &&
520 cut -d ' ' -f 2