Git 2.33.8
[git.git] / t / t5526-fetch-submodules.sh
blobbca679590b3ec48e3c3bdb57af2900dcdd371f96
1 #!/bin/sh
2 # Copyright (c) 2010, Jens Lehmann
4 test_description='Recursive "git fetch" for submodules'
6 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
7 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 . ./test-lib.sh
11 pwd=$(pwd)
13 add_upstream_commit() {
15 cd submodule &&
16 head1=$(git rev-parse --short HEAD) &&
17 echo new >> subfile &&
18 test_tick &&
19 git add subfile &&
20 git commit -m new subfile &&
21 head2=$(git rev-parse --short HEAD) &&
22 echo "Fetching submodule submodule" > ../expect.err &&
23 echo "From $pwd/submodule" >> ../expect.err &&
24 echo " $head1..$head2 sub -> origin/sub" >> ../expect.err
25 ) &&
27 cd deepsubmodule &&
28 head1=$(git rev-parse --short HEAD) &&
29 echo new >> deepsubfile &&
30 test_tick &&
31 git add deepsubfile &&
32 git commit -m new deepsubfile &&
33 head2=$(git rev-parse --short HEAD) &&
34 echo "Fetching submodule submodule/subdir/deepsubmodule" >> ../expect.err
35 echo "From $pwd/deepsubmodule" >> ../expect.err &&
36 echo " $head1..$head2 deep -> origin/deep" >> ../expect.err
40 test_expect_success setup '
41 git config --global protocol.file.allow always &&
42 mkdir deepsubmodule &&
44 cd deepsubmodule &&
45 git init &&
46 echo deepsubcontent > deepsubfile &&
47 git add deepsubfile &&
48 git commit -m new deepsubfile &&
49 git branch -M deep
50 ) &&
51 mkdir submodule &&
53 cd submodule &&
54 git init &&
55 echo subcontent > subfile &&
56 git add subfile &&
57 git submodule add "$pwd/deepsubmodule" subdir/deepsubmodule &&
58 git commit -a -m new &&
59 git branch -M sub
60 ) &&
61 git submodule add "$pwd/submodule" submodule &&
62 git commit -am initial &&
63 git branch -M super &&
64 git clone . downstream &&
66 cd downstream &&
67 git submodule update --init --recursive
71 test_expect_success "fetch --recurse-submodules recurses into submodules" '
72 add_upstream_commit &&
74 cd downstream &&
75 git fetch --recurse-submodules >../actual.out 2>../actual.err
76 ) &&
77 test_must_be_empty actual.out &&
78 test_cmp expect.err actual.err
81 test_expect_success "submodule.recurse option triggers recursive fetch" '
82 add_upstream_commit &&
84 cd downstream &&
85 git -c submodule.recurse fetch >../actual.out 2>../actual.err
86 ) &&
87 test_must_be_empty actual.out &&
88 test_cmp expect.err actual.err
91 test_expect_success "fetch --recurse-submodules -j2 has the same output behaviour" '
92 add_upstream_commit &&
94 cd downstream &&
95 GIT_TRACE="$TRASH_DIRECTORY/trace.out" git fetch --recurse-submodules -j2 2>../actual.err
96 ) &&
97 test_must_be_empty actual.out &&
98 test_cmp expect.err actual.err &&
99 grep "2 tasks" trace.out
102 test_expect_success "fetch alone only fetches superproject" '
103 add_upstream_commit &&
105 cd downstream &&
106 git fetch >../actual.out 2>../actual.err
107 ) &&
108 test_must_be_empty actual.out &&
109 test_must_be_empty actual.err
112 test_expect_success "fetch --no-recurse-submodules only fetches superproject" '
114 cd downstream &&
115 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
116 ) &&
117 test_must_be_empty actual.out &&
118 test_must_be_empty actual.err
121 test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
123 cd downstream &&
124 git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
125 git fetch >../actual.out 2>../actual.err
126 ) &&
127 test_must_be_empty actual.out &&
128 test_cmp expect.err actual.err
131 test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
132 add_upstream_commit &&
134 cd downstream &&
135 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
136 ) &&
137 test_must_be_empty actual.out &&
138 test_must_be_empty actual.err
141 test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
143 cd downstream &&
144 git config submodule.submodule.fetchRecurseSubmodules false &&
145 git fetch >../actual.out 2>../actual.err
146 ) &&
147 test_must_be_empty actual.out &&
148 test_must_be_empty actual.err
151 test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
153 cd downstream &&
154 git fetch --recurse-submodules >../actual.out 2>../actual.err &&
155 git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
156 git config --unset submodule.submodule.fetchRecurseSubmodules
157 ) &&
158 test_must_be_empty actual.out &&
159 test_cmp expect.err actual.err
162 test_expect_success "--quiet propagates to submodules" '
164 cd downstream &&
165 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
166 ) &&
167 test_must_be_empty actual.out &&
168 test_must_be_empty actual.err
171 test_expect_success "--quiet propagates to parallel submodules" '
173 cd downstream &&
174 git fetch --recurse-submodules -j 2 --quiet >../actual.out 2>../actual.err
175 ) &&
176 test_must_be_empty actual.out &&
177 test_must_be_empty actual.err
180 test_expect_success "--dry-run propagates to submodules" '
181 add_upstream_commit &&
183 cd downstream &&
184 git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
185 ) &&
186 test_must_be_empty actual.out &&
187 test_cmp expect.err actual.err
190 test_expect_success "Without --dry-run propagates to submodules" '
192 cd downstream &&
193 git fetch --recurse-submodules >../actual.out 2>../actual.err
194 ) &&
195 test_must_be_empty actual.out &&
196 test_cmp expect.err actual.err
199 test_expect_success "recurseSubmodules=true propagates into submodules" '
200 add_upstream_commit &&
202 cd downstream &&
203 git config fetch.recurseSubmodules true &&
204 git fetch >../actual.out 2>../actual.err
205 ) &&
206 test_must_be_empty actual.out &&
207 test_cmp expect.err actual.err
210 test_expect_success "--recurse-submodules overrides config in submodule" '
211 add_upstream_commit &&
213 cd downstream &&
215 cd submodule &&
216 git config fetch.recurseSubmodules false
217 ) &&
218 git fetch --recurse-submodules >../actual.out 2>../actual.err
219 ) &&
220 test_must_be_empty actual.out &&
221 test_cmp expect.err actual.err
224 test_expect_success "--no-recurse-submodules overrides config setting" '
225 add_upstream_commit &&
227 cd downstream &&
228 git config fetch.recurseSubmodules true &&
229 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
230 ) &&
231 test_must_be_empty actual.out &&
232 test_must_be_empty actual.err
235 test_expect_success "Recursion doesn't happen when no new commits are fetched in the superproject" '
237 cd downstream &&
239 cd submodule &&
240 git config --unset fetch.recurseSubmodules
241 ) &&
242 git config --unset fetch.recurseSubmodules &&
243 git fetch >../actual.out 2>../actual.err
244 ) &&
245 test_must_be_empty actual.out &&
246 test_must_be_empty actual.err
249 test_expect_success "Recursion stops when no new submodule commits are fetched" '
250 head1=$(git rev-parse --short HEAD) &&
251 git add submodule &&
252 git commit -m "new submodule" &&
253 head2=$(git rev-parse --short HEAD) &&
254 echo "From $pwd/." > expect.err.sub &&
255 echo " $head1..$head2 super -> origin/super" >>expect.err.sub &&
256 head -3 expect.err >> expect.err.sub &&
258 cd downstream &&
259 git fetch >../actual.out 2>../actual.err
260 ) &&
261 test_cmp expect.err.sub actual.err &&
262 test_must_be_empty actual.out
265 test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
266 add_upstream_commit &&
267 head1=$(git rev-parse --short HEAD) &&
268 echo a > file &&
269 git add file &&
270 git commit -m "new file" &&
271 head2=$(git rev-parse --short HEAD) &&
272 echo "From $pwd/." > expect.err.file &&
273 echo " $head1..$head2 super -> origin/super" >> expect.err.file &&
275 cd downstream &&
276 git fetch >../actual.out 2>../actual.err
277 ) &&
278 test_must_be_empty actual.out &&
279 test_cmp expect.err.file actual.err
282 test_expect_success "Recursion picks up config in submodule" '
284 cd downstream &&
285 git fetch --recurse-submodules &&
287 cd submodule &&
288 git config fetch.recurseSubmodules true
290 ) &&
291 add_upstream_commit &&
292 head1=$(git rev-parse --short HEAD) &&
293 git add submodule &&
294 git commit -m "new submodule" &&
295 head2=$(git rev-parse --short HEAD) &&
296 echo "From $pwd/." > expect.err.sub &&
297 echo " $head1..$head2 super -> origin/super" >> expect.err.sub &&
298 cat expect.err >> expect.err.sub &&
300 cd downstream &&
301 git fetch >../actual.out 2>../actual.err &&
303 cd submodule &&
304 git config --unset fetch.recurseSubmodules
306 ) &&
307 test_cmp expect.err.sub actual.err &&
308 test_must_be_empty actual.out
311 test_expect_success "Recursion picks up all submodules when necessary" '
312 add_upstream_commit &&
314 cd submodule &&
316 cd subdir/deepsubmodule &&
317 git fetch &&
318 git checkout -q FETCH_HEAD
319 ) &&
320 head1=$(git rev-parse --short HEAD^) &&
321 git add subdir/deepsubmodule &&
322 git commit -m "new deepsubmodule" &&
323 head2=$(git rev-parse --short HEAD) &&
324 echo "Fetching submodule submodule" > ../expect.err.sub &&
325 echo "From $pwd/submodule" >> ../expect.err.sub &&
326 echo " $head1..$head2 sub -> origin/sub" >> ../expect.err.sub
327 ) &&
328 head1=$(git rev-parse --short HEAD) &&
329 git add submodule &&
330 git commit -m "new submodule" &&
331 head2=$(git rev-parse --short HEAD) &&
332 echo "From $pwd/." > expect.err.2 &&
333 echo " $head1..$head2 super -> origin/super" >> expect.err.2 &&
334 cat expect.err.sub >> expect.err.2 &&
335 tail -3 expect.err >> expect.err.2 &&
337 cd downstream &&
338 git fetch >../actual.out 2>../actual.err
339 ) &&
340 test_cmp expect.err.2 actual.err &&
341 test_must_be_empty actual.out
344 test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
345 add_upstream_commit &&
347 cd submodule &&
349 cd subdir/deepsubmodule &&
350 git fetch &&
351 git checkout -q FETCH_HEAD
352 ) &&
353 head1=$(git rev-parse --short HEAD^) &&
354 git add subdir/deepsubmodule &&
355 git commit -m "new deepsubmodule" &&
356 head2=$(git rev-parse --short HEAD) &&
357 echo Fetching submodule submodule > ../expect.err.sub &&
358 echo "From $pwd/submodule" >> ../expect.err.sub &&
359 echo " $head1..$head2 sub -> origin/sub" >> ../expect.err.sub
360 ) &&
362 cd downstream &&
363 git config fetch.recurseSubmodules true &&
364 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
365 git config --unset fetch.recurseSubmodules
366 ) &&
367 test_must_be_empty actual.out &&
368 test_must_be_empty actual.err
371 test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
372 head1=$(git rev-parse --short HEAD) &&
373 git add submodule &&
374 git commit -m "new submodule" &&
375 head2=$(git rev-parse --short HEAD) &&
376 tail -3 expect.err > expect.err.deepsub &&
377 echo "From $pwd/." > expect.err &&
378 echo " $head1..$head2 super -> origin/super" >>expect.err &&
379 cat expect.err.sub >> expect.err &&
380 cat expect.err.deepsub >> expect.err &&
382 cd downstream &&
383 git config fetch.recurseSubmodules false &&
385 cd submodule &&
386 git config -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive false
387 ) &&
388 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
389 git config --unset fetch.recurseSubmodules &&
391 cd submodule &&
392 git config --unset -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive
394 ) &&
395 test_must_be_empty actual.out &&
396 test_cmp expect.err actual.err
399 test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
400 add_upstream_commit &&
401 head1=$(git rev-parse --short HEAD) &&
402 echo a >> file &&
403 git add file &&
404 git commit -m "new file" &&
405 head2=$(git rev-parse --short HEAD) &&
406 echo "From $pwd/." > expect.err.file &&
407 echo " $head1..$head2 super -> origin/super" >> expect.err.file &&
409 cd downstream &&
410 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
411 ) &&
412 test_must_be_empty actual.out &&
413 test_cmp expect.err.file actual.err
416 test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" '
418 cd downstream &&
419 git fetch --recurse-submodules
420 ) &&
421 add_upstream_commit &&
422 git config --global fetch.recurseSubmodules false &&
423 head1=$(git rev-parse --short HEAD) &&
424 git add submodule &&
425 git commit -m "new submodule" &&
426 head2=$(git rev-parse --short HEAD) &&
427 echo "From $pwd/." > expect.err.2 &&
428 echo " $head1..$head2 super -> origin/super" >>expect.err.2 &&
429 head -3 expect.err >> expect.err.2 &&
431 cd downstream &&
432 git config fetch.recurseSubmodules on-demand &&
433 git fetch >../actual.out 2>../actual.err
434 ) &&
435 git config --global --unset fetch.recurseSubmodules &&
437 cd downstream &&
438 git config --unset fetch.recurseSubmodules
439 ) &&
440 test_must_be_empty actual.out &&
441 test_cmp expect.err.2 actual.err
444 test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
446 cd downstream &&
447 git fetch --recurse-submodules
448 ) &&
449 add_upstream_commit &&
450 git config fetch.recurseSubmodules false &&
451 head1=$(git rev-parse --short HEAD) &&
452 git add submodule &&
453 git commit -m "new submodule" &&
454 head2=$(git rev-parse --short HEAD) &&
455 echo "From $pwd/." > expect.err.2 &&
456 echo " $head1..$head2 super -> origin/super" >>expect.err.2 &&
457 head -3 expect.err >> expect.err.2 &&
459 cd downstream &&
460 git config submodule.submodule.fetchRecurseSubmodules on-demand &&
461 git fetch >../actual.out 2>../actual.err
462 ) &&
463 git config --unset fetch.recurseSubmodules &&
465 cd downstream &&
466 git config --unset submodule.submodule.fetchRecurseSubmodules
467 ) &&
468 test_must_be_empty actual.out &&
469 test_cmp expect.err.2 actual.err
472 test_expect_success "don't fetch submodule when newly recorded commits are already present" '
474 cd submodule &&
475 git checkout -q HEAD^^
476 ) &&
477 head1=$(git rev-parse --short HEAD) &&
478 git add submodule &&
479 git commit -m "submodule rewound" &&
480 head2=$(git rev-parse --short HEAD) &&
481 echo "From $pwd/." > expect.err &&
482 echo " $head1..$head2 super -> origin/super" >> expect.err &&
484 cd downstream &&
485 git fetch >../actual.out 2>../actual.err
486 ) &&
487 test_must_be_empty actual.out &&
488 test_cmp expect.err actual.err &&
490 cd submodule &&
491 git checkout -q sub
495 test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .gitmodules entry" '
497 cd downstream &&
498 git fetch --recurse-submodules
499 ) &&
500 add_upstream_commit &&
501 head1=$(git rev-parse --short HEAD) &&
502 git add submodule &&
503 git rm .gitmodules &&
504 git commit -m "new submodule without .gitmodules" &&
505 head2=$(git rev-parse --short HEAD) &&
506 echo "From $pwd/." >expect.err.2 &&
507 echo " $head1..$head2 super -> origin/super" >>expect.err.2 &&
508 head -3 expect.err >>expect.err.2 &&
510 cd downstream &&
511 rm .gitmodules &&
512 git config fetch.recurseSubmodules on-demand &&
513 # fake submodule configuration to avoid skipping submodule handling
514 git config -f .gitmodules submodule.fake.path fake &&
515 git config -f .gitmodules submodule.fake.url fakeurl &&
516 git add .gitmodules &&
517 git config --unset submodule.submodule.url &&
518 git fetch >../actual.out 2>../actual.err &&
519 # cleanup
520 git config --unset fetch.recurseSubmodules &&
521 git reset --hard
522 ) &&
523 test_must_be_empty actual.out &&
524 test_cmp expect.err.2 actual.err &&
525 git checkout HEAD^ -- .gitmodules &&
526 git add .gitmodules &&
527 git commit -m "new submodule restored .gitmodules"
530 test_expect_success 'fetching submodules respects parallel settings' '
531 git config fetch.recurseSubmodules true &&
533 cd downstream &&
534 GIT_TRACE=$(pwd)/trace.out git fetch &&
535 grep "1 tasks" trace.out &&
536 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
537 grep "7 tasks" trace.out &&
538 git config submodule.fetchJobs 8 &&
539 GIT_TRACE=$(pwd)/trace.out git fetch &&
540 grep "8 tasks" trace.out &&
541 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
542 grep "9 tasks" trace.out
546 test_expect_success 'fetching submodule into a broken repository' '
547 # Prepare src and src/sub nested in it
548 git init src &&
550 cd src &&
551 git init sub &&
552 git -C sub commit --allow-empty -m "initial in sub" &&
553 git submodule add -- ./sub sub &&
554 git commit -m "initial in top"
555 ) &&
557 # Clone the old-fashoned way
558 git clone src dst &&
559 git -C dst clone ../src/sub sub &&
561 # Make sure that old-fashoned layout is still supported
562 git -C dst status &&
564 # "diff" would find no change
565 git -C dst diff --exit-code &&
567 # Recursive-fetch works fine
568 git -C dst fetch --recurse-submodules &&
570 # Break the receiving submodule
571 rm -f dst/sub/.git/HEAD &&
573 # NOTE: without the fix the following tests will recurse forever!
574 # They should terminate with an error.
576 test_must_fail git -C dst status &&
577 test_must_fail git -C dst diff &&
578 test_must_fail git -C dst fetch --recurse-submodules
581 test_expect_success "fetch new commits when submodule got renamed" '
582 git clone . downstream_rename &&
584 cd downstream_rename &&
585 git submodule update --init --recursive &&
586 git checkout -b rename &&
587 git mv submodule submodule_renamed &&
589 cd submodule_renamed &&
590 git checkout -b rename_sub &&
591 echo a >a &&
592 git add a &&
593 git commit -ma &&
594 git push origin rename_sub &&
595 git rev-parse HEAD >../../expect
596 ) &&
597 git add submodule_renamed &&
598 git commit -m "update renamed submodule" &&
599 git push origin rename
600 ) &&
602 cd downstream &&
603 git fetch --recurse-submodules=on-demand &&
605 cd submodule &&
606 git rev-parse origin/rename_sub >../../actual
608 ) &&
609 test_cmp expect actual
612 test_expect_success "fetch new submodule commits on-demand outside standard refspec" '
613 # add a second submodule and ensure it is around in downstream first
614 git clone submodule sub1 &&
615 git submodule add ./sub1 &&
616 git commit -m "adding a second submodule" &&
617 git -C downstream pull &&
618 git -C downstream submodule update --init --recursive &&
620 git checkout --detach &&
622 C=$(git -C submodule commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
623 git -C submodule update-ref refs/changes/1 $C &&
624 git update-index --cacheinfo 160000 $C submodule &&
625 test_tick &&
627 D=$(git -C sub1 commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
628 git -C sub1 update-ref refs/changes/2 $D &&
629 git update-index --cacheinfo 160000 $D sub1 &&
631 git commit -m "updated submodules outside of refs/heads" &&
632 E=$(git rev-parse HEAD) &&
633 git update-ref refs/changes/3 $E &&
635 cd downstream &&
636 git fetch --recurse-submodules origin refs/changes/3:refs/heads/my_branch &&
637 git -C submodule cat-file -t $C &&
638 git -C sub1 cat-file -t $D &&
639 git checkout --recurse-submodules FETCH_HEAD
643 test_expect_success 'fetch new submodule commit on-demand in FETCH_HEAD' '
644 # depends on the previous test for setup
646 C=$(git -C submodule commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
647 git -C submodule update-ref refs/changes/4 $C &&
648 git update-index --cacheinfo 160000 $C submodule &&
649 test_tick &&
651 D=$(git -C sub1 commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
652 git -C sub1 update-ref refs/changes/5 $D &&
653 git update-index --cacheinfo 160000 $D sub1 &&
655 git commit -m "updated submodules outside of refs/heads" &&
656 E=$(git rev-parse HEAD) &&
657 git update-ref refs/changes/6 $E &&
659 cd downstream &&
660 git fetch --recurse-submodules origin refs/changes/6 &&
661 git -C submodule cat-file -t $C &&
662 git -C sub1 cat-file -t $D &&
663 git checkout --recurse-submodules FETCH_HEAD
667 test_expect_success 'fetch new submodule commits on-demand without .gitmodules entry' '
668 # depends on the previous test for setup
670 git config -f .gitmodules --remove-section submodule.sub1 &&
671 git add .gitmodules &&
672 git commit -m "delete gitmodules file" &&
673 git checkout -B super &&
674 git -C downstream fetch &&
675 git -C downstream checkout origin/super &&
677 C=$(git -C submodule commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
678 git -C submodule update-ref refs/changes/7 $C &&
679 git update-index --cacheinfo 160000 $C submodule &&
680 test_tick &&
682 D=$(git -C sub1 commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
683 git -C sub1 update-ref refs/changes/8 $D &&
684 git update-index --cacheinfo 160000 $D sub1 &&
686 git commit -m "updated submodules outside of refs/heads" &&
687 E=$(git rev-parse HEAD) &&
688 git update-ref refs/changes/9 $E &&
690 cd downstream &&
691 git fetch --recurse-submodules origin refs/changes/9 &&
692 git -C submodule cat-file -t $C &&
693 git -C sub1 cat-file -t $D &&
694 git checkout --recurse-submodules FETCH_HEAD
698 test_expect_success 'fetch new submodule commit intermittently referenced by superproject' '
699 # depends on the previous test for setup
701 D=$(git -C sub1 commit-tree -m "change 10 outside refs/heads" HEAD^{tree}) &&
702 E=$(git -C sub1 commit-tree -m "change 11 outside refs/heads" HEAD^{tree}) &&
703 F=$(git -C sub1 commit-tree -m "change 12 outside refs/heads" HEAD^{tree}) &&
705 git -C sub1 update-ref refs/changes/10 $D &&
706 git update-index --cacheinfo 160000 $D sub1 &&
707 git commit -m "updated submodules outside of refs/heads" &&
709 git -C sub1 update-ref refs/changes/11 $E &&
710 git update-index --cacheinfo 160000 $E sub1 &&
711 git commit -m "updated submodules outside of refs/heads" &&
713 git -C sub1 update-ref refs/changes/12 $F &&
714 git update-index --cacheinfo 160000 $F sub1 &&
715 git commit -m "updated submodules outside of refs/heads" &&
717 G=$(git rev-parse HEAD) &&
718 git update-ref refs/changes/13 $G &&
720 cd downstream &&
721 git fetch --recurse-submodules origin refs/changes/13 &&
723 git -C sub1 cat-file -t $D &&
724 git -C sub1 cat-file -t $E &&
725 git -C sub1 cat-file -t $F
729 add_commit_push () {
730 dir="$1" &&
731 msg="$2" &&
732 shift 2 &&
733 git -C "$dir" add "$@" &&
734 git -C "$dir" commit -a -m "$msg" &&
735 git -C "$dir" push
738 compare_refs_in_dir () {
739 fail= &&
740 if test "x$1" = 'x!'
741 then
742 fail='!' &&
743 shift
744 fi &&
745 git -C "$1" rev-parse --verify "$2" >expect &&
746 git -C "$3" rev-parse --verify "$4" >actual &&
747 eval $fail test_cmp expect actual
751 test_expect_success 'setup nested submodule fetch test' '
752 # does not depend on any previous test setups
754 for repo in outer middle inner
756 git init --bare $repo &&
757 git clone $repo ${repo}_content &&
758 echo "$repo" >"${repo}_content/file" &&
759 add_commit_push ${repo}_content "initial" file ||
760 return 1
761 done &&
763 git clone outer A &&
764 git -C A submodule add "$pwd/middle" &&
765 git -C A/middle/ submodule add "$pwd/inner" &&
766 add_commit_push A/middle/ "adding inner sub" .gitmodules inner &&
767 add_commit_push A/ "adding middle sub" .gitmodules middle &&
769 git clone outer B &&
770 git -C B/ submodule update --init middle &&
772 compare_refs_in_dir A HEAD B HEAD &&
773 compare_refs_in_dir A/middle HEAD B/middle HEAD &&
774 test_path_is_file B/file &&
775 test_path_is_file B/middle/file &&
776 test_path_is_missing B/middle/inner/file &&
778 echo "change on inner repo of A" >"A/middle/inner/file" &&
779 add_commit_push A/middle/inner "change on inner" file &&
780 add_commit_push A/middle "change on inner" inner &&
781 add_commit_push A "change on inner" middle
784 test_expect_success 'fetching a superproject containing an uninitialized sub/sub project' '
785 # depends on previous test for setup
787 git -C B/ fetch &&
788 compare_refs_in_dir A origin/HEAD B origin/HEAD
791 fetch_with_recursion_abort () {
792 # In a regression the following git call will run into infinite recursion.
793 # To handle that, we connect the sed command to the git call by a pipe
794 # so that sed can kill the infinite recursion when detected.
795 # The recursion creates git output like:
796 # Fetching submodule sub
797 # Fetching submodule sub/sub <-- [1]
798 # Fetching submodule sub/sub/sub
799 # ...
800 # [1] sed will stop reading and cause git to eventually stop and die
802 git -C "$1" fetch --recurse-submodules 2>&1 |
803 sed "/Fetching submodule $2[^$]/q" >out &&
804 ! grep "Fetching submodule $2[^$]" out
807 test_expect_success 'setup recursive fetch with uninit submodule' '
808 # does not depend on any previous test setups
810 test_create_repo super &&
811 test_commit -C super initial &&
812 test_create_repo sub &&
813 test_commit -C sub initial &&
814 git -C sub rev-parse HEAD >expect &&
816 git -C super submodule add ../sub &&
817 git -C super commit -m "add sub" &&
819 git clone super superclone &&
820 git -C superclone submodule status >out &&
821 sed -e "s/^-//" -e "s/ sub.*$//" out >actual &&
822 test_cmp expect actual
825 test_expect_success 'recursive fetch with uninit submodule' '
826 # depends on previous test for setup
828 fetch_with_recursion_abort superclone sub &&
829 git -C superclone submodule status >out &&
830 sed -e "s/^-//" -e "s/ sub$//" out >actual &&
831 test_cmp expect actual
834 test_expect_success 'recursive fetch after deinit a submodule' '
835 # depends on previous test for setup
837 git -C superclone submodule update --init sub &&
838 git -C superclone submodule deinit -f sub &&
840 fetch_with_recursion_abort superclone sub &&
841 git -C superclone submodule status >out &&
842 sed -e "s/^-//" -e "s/ sub$//" out >actual &&
843 test_cmp expect actual
846 test_done