Git 2.30.9
[git.git] / t / t5526-fetch-submodules.sh
blobaa04eacb652d909fe5b52014a4903bc6b085c4ea
1 #!/bin/sh
2 # Copyright (c) 2010, Jens Lehmann
4 test_description='Recursive "git fetch" for submodules'
6 . ./test-lib.sh
8 pwd=$(pwd)
10 add_upstream_commit() {
12 cd submodule &&
13 head1=$(git rev-parse --short HEAD) &&
14 echo new >> subfile &&
15 test_tick &&
16 git add subfile &&
17 git commit -m new subfile &&
18 head2=$(git rev-parse --short HEAD) &&
19 echo "Fetching submodule submodule" > ../expect.err &&
20 echo "From $pwd/submodule" >> ../expect.err &&
21 echo " $head1..$head2 sub -> origin/sub" >> ../expect.err
22 ) &&
24 cd deepsubmodule &&
25 head1=$(git rev-parse --short HEAD) &&
26 echo new >> deepsubfile &&
27 test_tick &&
28 git add deepsubfile &&
29 git commit -m new deepsubfile &&
30 head2=$(git rev-parse --short HEAD) &&
31 echo "Fetching submodule submodule/subdir/deepsubmodule" >> ../expect.err
32 echo "From $pwd/deepsubmodule" >> ../expect.err &&
33 echo " $head1..$head2 deep -> origin/deep" >> ../expect.err
37 test_expect_success setup '
38 git config --global protocol.file.allow always &&
39 mkdir deepsubmodule &&
41 cd deepsubmodule &&
42 git init &&
43 echo deepsubcontent > deepsubfile &&
44 git add deepsubfile &&
45 git commit -m new deepsubfile &&
46 git branch -M deep
47 ) &&
48 mkdir submodule &&
50 cd submodule &&
51 git init &&
52 echo subcontent > subfile &&
53 git add subfile &&
54 git submodule add "$pwd/deepsubmodule" subdir/deepsubmodule &&
55 git commit -a -m new &&
56 git branch -M sub
57 ) &&
58 git submodule add "$pwd/submodule" submodule &&
59 git commit -am initial &&
60 git branch -M super &&
61 git clone . downstream &&
63 cd downstream &&
64 git submodule update --init --recursive
68 test_expect_success "fetch --recurse-submodules recurses into submodules" '
69 add_upstream_commit &&
71 cd downstream &&
72 git fetch --recurse-submodules >../actual.out 2>../actual.err
73 ) &&
74 test_must_be_empty actual.out &&
75 test_i18ncmp expect.err actual.err
78 test_expect_success "submodule.recurse option triggers recursive fetch" '
79 add_upstream_commit &&
81 cd downstream &&
82 git -c submodule.recurse fetch >../actual.out 2>../actual.err
83 ) &&
84 test_must_be_empty actual.out &&
85 test_i18ncmp expect.err actual.err
88 test_expect_success "fetch --recurse-submodules -j2 has the same output behaviour" '
89 add_upstream_commit &&
91 cd downstream &&
92 GIT_TRACE="$TRASH_DIRECTORY/trace.out" git fetch --recurse-submodules -j2 2>../actual.err
93 ) &&
94 test_must_be_empty actual.out &&
95 test_i18ncmp expect.err actual.err &&
96 grep "2 tasks" trace.out
99 test_expect_success "fetch alone only fetches superproject" '
100 add_upstream_commit &&
102 cd downstream &&
103 git fetch >../actual.out 2>../actual.err
104 ) &&
105 test_must_be_empty actual.out &&
106 test_must_be_empty actual.err
109 test_expect_success "fetch --no-recurse-submodules only fetches superproject" '
111 cd downstream &&
112 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
113 ) &&
114 test_must_be_empty actual.out &&
115 test_must_be_empty actual.err
118 test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
120 cd downstream &&
121 git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
122 git fetch >../actual.out 2>../actual.err
123 ) &&
124 test_must_be_empty actual.out &&
125 test_i18ncmp expect.err actual.err
128 test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
129 add_upstream_commit &&
131 cd downstream &&
132 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
133 ) &&
134 test_must_be_empty actual.out &&
135 test_must_be_empty actual.err
138 test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
140 cd downstream &&
141 git config submodule.submodule.fetchRecurseSubmodules false &&
142 git fetch >../actual.out 2>../actual.err
143 ) &&
144 test_must_be_empty actual.out &&
145 test_must_be_empty actual.err
148 test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
150 cd downstream &&
151 git fetch --recurse-submodules >../actual.out 2>../actual.err &&
152 git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
153 git config --unset submodule.submodule.fetchRecurseSubmodules
154 ) &&
155 test_must_be_empty actual.out &&
156 test_i18ncmp expect.err actual.err
159 test_expect_success "--quiet propagates to submodules" '
161 cd downstream &&
162 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
163 ) &&
164 test_must_be_empty actual.out &&
165 test_must_be_empty actual.err
168 test_expect_success "--quiet propagates to parallel submodules" '
170 cd downstream &&
171 git fetch --recurse-submodules -j 2 --quiet >../actual.out 2>../actual.err
172 ) &&
173 test_must_be_empty actual.out &&
174 test_must_be_empty actual.err
177 test_expect_success "--dry-run propagates to submodules" '
178 add_upstream_commit &&
180 cd downstream &&
181 git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
182 ) &&
183 test_must_be_empty actual.out &&
184 test_i18ncmp expect.err actual.err
187 test_expect_success "Without --dry-run propagates to submodules" '
189 cd downstream &&
190 git fetch --recurse-submodules >../actual.out 2>../actual.err
191 ) &&
192 test_must_be_empty actual.out &&
193 test_i18ncmp expect.err actual.err
196 test_expect_success "recurseSubmodules=true propagates into submodules" '
197 add_upstream_commit &&
199 cd downstream &&
200 git config fetch.recurseSubmodules true &&
201 git fetch >../actual.out 2>../actual.err
202 ) &&
203 test_must_be_empty actual.out &&
204 test_i18ncmp expect.err actual.err
207 test_expect_success "--recurse-submodules overrides config in submodule" '
208 add_upstream_commit &&
210 cd downstream &&
212 cd submodule &&
213 git config fetch.recurseSubmodules false
214 ) &&
215 git fetch --recurse-submodules >../actual.out 2>../actual.err
216 ) &&
217 test_must_be_empty actual.out &&
218 test_i18ncmp expect.err actual.err
221 test_expect_success "--no-recurse-submodules overrides config setting" '
222 add_upstream_commit &&
224 cd downstream &&
225 git config fetch.recurseSubmodules true &&
226 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
227 ) &&
228 test_must_be_empty actual.out &&
229 test_must_be_empty actual.err
232 test_expect_success "Recursion doesn't happen when no new commits are fetched in the superproject" '
234 cd downstream &&
236 cd submodule &&
237 git config --unset fetch.recurseSubmodules
238 ) &&
239 git config --unset fetch.recurseSubmodules &&
240 git fetch >../actual.out 2>../actual.err
241 ) &&
242 test_must_be_empty actual.out &&
243 test_must_be_empty actual.err
246 test_expect_success "Recursion stops when no new submodule commits are fetched" '
247 head1=$(git rev-parse --short HEAD) &&
248 git add submodule &&
249 git commit -m "new submodule" &&
250 head2=$(git rev-parse --short HEAD) &&
251 echo "From $pwd/." > expect.err.sub &&
252 echo " $head1..$head2 super -> origin/super" >>expect.err.sub &&
253 head -3 expect.err >> expect.err.sub &&
255 cd downstream &&
256 git fetch >../actual.out 2>../actual.err
257 ) &&
258 test_i18ncmp expect.err.sub actual.err &&
259 test_must_be_empty actual.out
262 test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
263 add_upstream_commit &&
264 head1=$(git rev-parse --short HEAD) &&
265 echo a > file &&
266 git add file &&
267 git commit -m "new file" &&
268 head2=$(git rev-parse --short HEAD) &&
269 echo "From $pwd/." > expect.err.file &&
270 echo " $head1..$head2 super -> origin/super" >> expect.err.file &&
272 cd downstream &&
273 git fetch >../actual.out 2>../actual.err
274 ) &&
275 test_must_be_empty actual.out &&
276 test_i18ncmp expect.err.file actual.err
279 test_expect_success "Recursion picks up config in submodule" '
281 cd downstream &&
282 git fetch --recurse-submodules &&
284 cd submodule &&
285 git config fetch.recurseSubmodules true
287 ) &&
288 add_upstream_commit &&
289 head1=$(git rev-parse --short HEAD) &&
290 git add submodule &&
291 git commit -m "new submodule" &&
292 head2=$(git rev-parse --short HEAD) &&
293 echo "From $pwd/." > expect.err.sub &&
294 echo " $head1..$head2 super -> origin/super" >> expect.err.sub &&
295 cat expect.err >> expect.err.sub &&
297 cd downstream &&
298 git fetch >../actual.out 2>../actual.err &&
300 cd submodule &&
301 git config --unset fetch.recurseSubmodules
303 ) &&
304 test_i18ncmp expect.err.sub actual.err &&
305 test_must_be_empty actual.out
308 test_expect_success "Recursion picks up all submodules when necessary" '
309 add_upstream_commit &&
311 cd submodule &&
313 cd subdir/deepsubmodule &&
314 git fetch &&
315 git checkout -q FETCH_HEAD
316 ) &&
317 head1=$(git rev-parse --short HEAD^) &&
318 git add subdir/deepsubmodule &&
319 git commit -m "new deepsubmodule" &&
320 head2=$(git rev-parse --short HEAD) &&
321 echo "Fetching submodule submodule" > ../expect.err.sub &&
322 echo "From $pwd/submodule" >> ../expect.err.sub &&
323 echo " $head1..$head2 sub -> origin/sub" >> ../expect.err.sub
324 ) &&
325 head1=$(git rev-parse --short HEAD) &&
326 git add submodule &&
327 git commit -m "new submodule" &&
328 head2=$(git rev-parse --short HEAD) &&
329 echo "From $pwd/." > expect.err.2 &&
330 echo " $head1..$head2 super -> origin/super" >> expect.err.2 &&
331 cat expect.err.sub >> expect.err.2 &&
332 tail -3 expect.err >> expect.err.2 &&
334 cd downstream &&
335 git fetch >../actual.out 2>../actual.err
336 ) &&
337 test_i18ncmp expect.err.2 actual.err &&
338 test_must_be_empty actual.out
341 test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
342 add_upstream_commit &&
344 cd submodule &&
346 cd subdir/deepsubmodule &&
347 git fetch &&
348 git checkout -q FETCH_HEAD
349 ) &&
350 head1=$(git rev-parse --short HEAD^) &&
351 git add subdir/deepsubmodule &&
352 git commit -m "new deepsubmodule" &&
353 head2=$(git rev-parse --short HEAD) &&
354 echo Fetching submodule submodule > ../expect.err.sub &&
355 echo "From $pwd/submodule" >> ../expect.err.sub &&
356 echo " $head1..$head2 sub -> origin/sub" >> ../expect.err.sub
357 ) &&
359 cd downstream &&
360 git config fetch.recurseSubmodules true &&
361 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
362 git config --unset fetch.recurseSubmodules
363 ) &&
364 test_must_be_empty actual.out &&
365 test_must_be_empty actual.err
368 test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
369 head1=$(git rev-parse --short HEAD) &&
370 git add submodule &&
371 git commit -m "new submodule" &&
372 head2=$(git rev-parse --short HEAD) &&
373 tail -3 expect.err > expect.err.deepsub &&
374 echo "From $pwd/." > expect.err &&
375 echo " $head1..$head2 super -> origin/super" >>expect.err &&
376 cat expect.err.sub >> expect.err &&
377 cat expect.err.deepsub >> expect.err &&
379 cd downstream &&
380 git config fetch.recurseSubmodules false &&
382 cd submodule &&
383 git config -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive false
384 ) &&
385 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
386 git config --unset fetch.recurseSubmodules &&
388 cd submodule &&
389 git config --unset -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive
391 ) &&
392 test_must_be_empty actual.out &&
393 test_i18ncmp expect.err actual.err
396 test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
397 add_upstream_commit &&
398 head1=$(git rev-parse --short HEAD) &&
399 echo a >> file &&
400 git add file &&
401 git commit -m "new file" &&
402 head2=$(git rev-parse --short HEAD) &&
403 echo "From $pwd/." > expect.err.file &&
404 echo " $head1..$head2 super -> origin/super" >> expect.err.file &&
406 cd downstream &&
407 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
408 ) &&
409 test_must_be_empty actual.out &&
410 test_i18ncmp expect.err.file actual.err
413 test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" '
415 cd downstream &&
416 git fetch --recurse-submodules
417 ) &&
418 add_upstream_commit &&
419 git config --global fetch.recurseSubmodules false &&
420 head1=$(git rev-parse --short HEAD) &&
421 git add submodule &&
422 git commit -m "new submodule" &&
423 head2=$(git rev-parse --short HEAD) &&
424 echo "From $pwd/." > expect.err.2 &&
425 echo " $head1..$head2 super -> origin/super" >>expect.err.2 &&
426 head -3 expect.err >> expect.err.2 &&
428 cd downstream &&
429 git config fetch.recurseSubmodules on-demand &&
430 git fetch >../actual.out 2>../actual.err
431 ) &&
432 git config --global --unset fetch.recurseSubmodules &&
434 cd downstream &&
435 git config --unset fetch.recurseSubmodules
436 ) &&
437 test_must_be_empty actual.out &&
438 test_i18ncmp expect.err.2 actual.err
441 test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
443 cd downstream &&
444 git fetch --recurse-submodules
445 ) &&
446 add_upstream_commit &&
447 git config fetch.recurseSubmodules false &&
448 head1=$(git rev-parse --short HEAD) &&
449 git add submodule &&
450 git commit -m "new submodule" &&
451 head2=$(git rev-parse --short HEAD) &&
452 echo "From $pwd/." > expect.err.2 &&
453 echo " $head1..$head2 super -> origin/super" >>expect.err.2 &&
454 head -3 expect.err >> expect.err.2 &&
456 cd downstream &&
457 git config submodule.submodule.fetchRecurseSubmodules on-demand &&
458 git fetch >../actual.out 2>../actual.err
459 ) &&
460 git config --unset fetch.recurseSubmodules &&
462 cd downstream &&
463 git config --unset submodule.submodule.fetchRecurseSubmodules
464 ) &&
465 test_must_be_empty actual.out &&
466 test_i18ncmp expect.err.2 actual.err
469 test_expect_success "don't fetch submodule when newly recorded commits are already present" '
471 cd submodule &&
472 git checkout -q HEAD^^
473 ) &&
474 head1=$(git rev-parse --short HEAD) &&
475 git add submodule &&
476 git commit -m "submodule rewound" &&
477 head2=$(git rev-parse --short HEAD) &&
478 echo "From $pwd/." > expect.err &&
479 echo " $head1..$head2 super -> origin/super" >> expect.err &&
481 cd downstream &&
482 git fetch >../actual.out 2>../actual.err
483 ) &&
484 test_must_be_empty actual.out &&
485 test_i18ncmp expect.err actual.err &&
487 cd submodule &&
488 git checkout -q sub
492 test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .gitmodules entry" '
494 cd downstream &&
495 git fetch --recurse-submodules
496 ) &&
497 add_upstream_commit &&
498 head1=$(git rev-parse --short HEAD) &&
499 git add submodule &&
500 git rm .gitmodules &&
501 git commit -m "new submodule without .gitmodules" &&
502 head2=$(git rev-parse --short HEAD) &&
503 echo "From $pwd/." >expect.err.2 &&
504 echo " $head1..$head2 super -> origin/super" >>expect.err.2 &&
505 head -3 expect.err >>expect.err.2 &&
507 cd downstream &&
508 rm .gitmodules &&
509 git config fetch.recurseSubmodules on-demand &&
510 # fake submodule configuration to avoid skipping submodule handling
511 git config -f .gitmodules submodule.fake.path fake &&
512 git config -f .gitmodules submodule.fake.url fakeurl &&
513 git add .gitmodules &&
514 git config --unset submodule.submodule.url &&
515 git fetch >../actual.out 2>../actual.err &&
516 # cleanup
517 git config --unset fetch.recurseSubmodules &&
518 git reset --hard
519 ) &&
520 test_must_be_empty actual.out &&
521 test_i18ncmp expect.err.2 actual.err &&
522 git checkout HEAD^ -- .gitmodules &&
523 git add .gitmodules &&
524 git commit -m "new submodule restored .gitmodules"
527 test_expect_success 'fetching submodules respects parallel settings' '
528 git config fetch.recurseSubmodules true &&
530 cd downstream &&
531 GIT_TRACE=$(pwd)/trace.out git fetch &&
532 grep "1 tasks" trace.out &&
533 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
534 grep "7 tasks" trace.out &&
535 git config submodule.fetchJobs 8 &&
536 GIT_TRACE=$(pwd)/trace.out git fetch &&
537 grep "8 tasks" trace.out &&
538 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
539 grep "9 tasks" trace.out
543 test_expect_success 'fetching submodule into a broken repository' '
544 # Prepare src and src/sub nested in it
545 git init src &&
547 cd src &&
548 git init sub &&
549 git -C sub commit --allow-empty -m "initial in sub" &&
550 git submodule add -- ./sub sub &&
551 git commit -m "initial in top"
552 ) &&
554 # Clone the old-fashoned way
555 git clone src dst &&
556 git -C dst clone ../src/sub sub &&
558 # Make sure that old-fashoned layout is still supported
559 git -C dst status &&
561 # "diff" would find no change
562 git -C dst diff --exit-code &&
564 # Recursive-fetch works fine
565 git -C dst fetch --recurse-submodules &&
567 # Break the receiving submodule
568 rm -f dst/sub/.git/HEAD &&
570 # NOTE: without the fix the following tests will recurse forever!
571 # They should terminate with an error.
573 test_must_fail git -C dst status &&
574 test_must_fail git -C dst diff &&
575 test_must_fail git -C dst fetch --recurse-submodules
578 test_expect_success "fetch new commits when submodule got renamed" '
579 git clone . downstream_rename &&
581 cd downstream_rename &&
582 git submodule update --init --recursive &&
583 git checkout -b rename &&
584 git mv submodule submodule_renamed &&
586 cd submodule_renamed &&
587 git checkout -b rename_sub &&
588 echo a >a &&
589 git add a &&
590 git commit -ma &&
591 git push origin rename_sub &&
592 git rev-parse HEAD >../../expect
593 ) &&
594 git add submodule_renamed &&
595 git commit -m "update renamed submodule" &&
596 git push origin rename
597 ) &&
599 cd downstream &&
600 git fetch --recurse-submodules=on-demand &&
602 cd submodule &&
603 git rev-parse origin/rename_sub >../../actual
605 ) &&
606 test_cmp expect actual
609 test_expect_success "fetch new submodule commits on-demand outside standard refspec" '
610 # add a second submodule and ensure it is around in downstream first
611 git clone submodule sub1 &&
612 git submodule add ./sub1 &&
613 git commit -m "adding a second submodule" &&
614 git -C downstream pull &&
615 git -C downstream submodule update --init --recursive &&
617 git checkout --detach &&
619 C=$(git -C submodule commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
620 git -C submodule update-ref refs/changes/1 $C &&
621 git update-index --cacheinfo 160000 $C submodule &&
622 test_tick &&
624 D=$(git -C sub1 commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
625 git -C sub1 update-ref refs/changes/2 $D &&
626 git update-index --cacheinfo 160000 $D sub1 &&
628 git commit -m "updated submodules outside of refs/heads" &&
629 E=$(git rev-parse HEAD) &&
630 git update-ref refs/changes/3 $E &&
632 cd downstream &&
633 git fetch --recurse-submodules origin refs/changes/3:refs/heads/my_branch &&
634 git -C submodule cat-file -t $C &&
635 git -C sub1 cat-file -t $D &&
636 git checkout --recurse-submodules FETCH_HEAD
640 test_expect_success 'fetch new submodule commit on-demand in FETCH_HEAD' '
641 # depends on the previous test for setup
643 C=$(git -C submodule commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
644 git -C submodule update-ref refs/changes/4 $C &&
645 git update-index --cacheinfo 160000 $C submodule &&
646 test_tick &&
648 D=$(git -C sub1 commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
649 git -C sub1 update-ref refs/changes/5 $D &&
650 git update-index --cacheinfo 160000 $D sub1 &&
652 git commit -m "updated submodules outside of refs/heads" &&
653 E=$(git rev-parse HEAD) &&
654 git update-ref refs/changes/6 $E &&
656 cd downstream &&
657 git fetch --recurse-submodules origin refs/changes/6 &&
658 git -C submodule cat-file -t $C &&
659 git -C sub1 cat-file -t $D &&
660 git checkout --recurse-submodules FETCH_HEAD
664 test_expect_success 'fetch new submodule commits on-demand without .gitmodules entry' '
665 # depends on the previous test for setup
667 git config -f .gitmodules --remove-section submodule.sub1 &&
668 git add .gitmodules &&
669 git commit -m "delete gitmodules file" &&
670 git checkout -B super &&
671 git -C downstream fetch &&
672 git -C downstream checkout origin/super &&
674 C=$(git -C submodule commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
675 git -C submodule update-ref refs/changes/7 $C &&
676 git update-index --cacheinfo 160000 $C submodule &&
677 test_tick &&
679 D=$(git -C sub1 commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
680 git -C sub1 update-ref refs/changes/8 $D &&
681 git update-index --cacheinfo 160000 $D sub1 &&
683 git commit -m "updated submodules outside of refs/heads" &&
684 E=$(git rev-parse HEAD) &&
685 git update-ref refs/changes/9 $E &&
687 cd downstream &&
688 git fetch --recurse-submodules origin refs/changes/9 &&
689 git -C submodule cat-file -t $C &&
690 git -C sub1 cat-file -t $D &&
691 git checkout --recurse-submodules FETCH_HEAD
695 test_expect_success 'fetch new submodule commit intermittently referenced by superproject' '
696 # depends on the previous test for setup
698 D=$(git -C sub1 commit-tree -m "change 10 outside refs/heads" HEAD^{tree}) &&
699 E=$(git -C sub1 commit-tree -m "change 11 outside refs/heads" HEAD^{tree}) &&
700 F=$(git -C sub1 commit-tree -m "change 12 outside refs/heads" HEAD^{tree}) &&
702 git -C sub1 update-ref refs/changes/10 $D &&
703 git update-index --cacheinfo 160000 $D sub1 &&
704 git commit -m "updated submodules outside of refs/heads" &&
706 git -C sub1 update-ref refs/changes/11 $E &&
707 git update-index --cacheinfo 160000 $E sub1 &&
708 git commit -m "updated submodules outside of refs/heads" &&
710 git -C sub1 update-ref refs/changes/12 $F &&
711 git update-index --cacheinfo 160000 $F sub1 &&
712 git commit -m "updated submodules outside of refs/heads" &&
714 G=$(git rev-parse HEAD) &&
715 git update-ref refs/changes/13 $G &&
717 cd downstream &&
718 git fetch --recurse-submodules origin refs/changes/13 &&
720 git -C sub1 cat-file -t $D &&
721 git -C sub1 cat-file -t $E &&
722 git -C sub1 cat-file -t $F
726 add_commit_push () {
727 dir="$1" &&
728 msg="$2" &&
729 shift 2 &&
730 git -C "$dir" add "$@" &&
731 git -C "$dir" commit -a -m "$msg" &&
732 git -C "$dir" push
735 compare_refs_in_dir () {
736 fail= &&
737 if test "x$1" = 'x!'
738 then
739 fail='!' &&
740 shift
741 fi &&
742 git -C "$1" rev-parse --verify "$2" >expect &&
743 git -C "$3" rev-parse --verify "$4" >actual &&
744 eval $fail test_cmp expect actual
748 test_expect_success 'setup nested submodule fetch test' '
749 # does not depend on any previous test setups
751 for repo in outer middle inner
753 git init --bare $repo &&
754 git clone $repo ${repo}_content &&
755 echo "$repo" >"${repo}_content/file" &&
756 add_commit_push ${repo}_content "initial" file ||
757 return 1
758 done &&
760 git clone outer A &&
761 git -C A submodule add "$pwd/middle" &&
762 git -C A/middle/ submodule add "$pwd/inner" &&
763 add_commit_push A/middle/ "adding inner sub" .gitmodules inner &&
764 add_commit_push A/ "adding middle sub" .gitmodules middle &&
766 git clone outer B &&
767 git -C B/ submodule update --init middle &&
769 compare_refs_in_dir A HEAD B HEAD &&
770 compare_refs_in_dir A/middle HEAD B/middle HEAD &&
771 test_path_is_file B/file &&
772 test_path_is_file B/middle/file &&
773 test_path_is_missing B/middle/inner/file &&
775 echo "change on inner repo of A" >"A/middle/inner/file" &&
776 add_commit_push A/middle/inner "change on inner" file &&
777 add_commit_push A/middle "change on inner" inner &&
778 add_commit_push A "change on inner" middle
781 test_expect_success 'fetching a superproject containing an uninitialized sub/sub project' '
782 # depends on previous test for setup
784 git -C B/ fetch &&
785 compare_refs_in_dir A origin/HEAD B origin/HEAD
788 fetch_with_recursion_abort () {
789 # In a regression the following git call will run into infinite recursion.
790 # To handle that, we connect the sed command to the git call by a pipe
791 # so that sed can kill the infinite recursion when detected.
792 # The recursion creates git output like:
793 # Fetching submodule sub
794 # Fetching submodule sub/sub <-- [1]
795 # Fetching submodule sub/sub/sub
796 # ...
797 # [1] sed will stop reading and cause git to eventually stop and die
799 git -C "$1" fetch --recurse-submodules 2>&1 |
800 sed "/Fetching submodule $2[^$]/q" >out &&
801 ! grep "Fetching submodule $2[^$]" out
804 test_expect_success 'setup recursive fetch with uninit submodule' '
805 # does not depend on any previous test setups
807 test_create_repo super &&
808 test_commit -C super initial &&
809 test_create_repo sub &&
810 test_commit -C sub initial &&
811 git -C sub rev-parse HEAD >expect &&
813 git -C super submodule add ../sub &&
814 git -C super commit -m "add sub" &&
816 git clone super superclone &&
817 git -C superclone submodule status >out &&
818 sed -e "s/^-//" -e "s/ sub.*$//" out >actual &&
819 test_cmp expect actual
822 test_expect_success 'recursive fetch with uninit submodule' '
823 # depends on previous test for setup
825 fetch_with_recursion_abort superclone sub &&
826 git -C superclone submodule status >out &&
827 sed -e "s/^-//" -e "s/ sub$//" out >actual &&
828 test_cmp expect actual
831 test_expect_success 'recursive fetch after deinit a submodule' '
832 # depends on previous test for setup
834 git -C superclone submodule update --init sub &&
835 git -C superclone submodule deinit -f sub &&
837 fetch_with_recursion_abort superclone sub &&
838 git -C superclone submodule status >out &&
839 sed -e "s/^-//" -e "s/ sub$//" out >actual &&
840 test_cmp expect actual
843 test_done