t5526: stop asserting on stderr literally
[git/debian.git] / t / t5526-fetch-submodules.sh
blobe7136b68ba2423abd86f5c4cc22b4d7660f5e735
1 #!/bin/sh
2 # Copyright (c) 2010, Jens Lehmann
4 test_description='Recursive "git fetch" for submodules'
6 GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
7 export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
9 . ./test-lib.sh
11 pwd=$(pwd)
13 write_expected_sub () {
14 NEW_HEAD=$1 &&
15 cat >"$pwd/expect.err.sub" <<-EOF
16 Fetching submodule submodule
17 From $pwd/submodule
18 OLD_HEAD..$NEW_HEAD sub -> origin/sub
19 EOF
22 write_expected_deep () {
23 NEW_HEAD=$1 &&
24 cat >"$pwd/expect.err.deep" <<-EOF
25 Fetching submodule submodule/subdir/deepsubmodule
26 From $pwd/deepsubmodule
27 OLD_HEAD..$NEW_HEAD deep -> origin/deep
28 EOF
31 write_expected_super () {
32 NEW_HEAD=$1 &&
33 cat >"$pwd/expect.err.super" <<-EOF
34 From $pwd/.
35 OLD_HEAD..$NEW_HEAD super -> origin/super
36 EOF
39 # For each submodule in the test setup, this creates a commit and writes
40 # a file that contains the expected err if that new commit were fetched.
41 # These output files get concatenated in the right order by
42 # verify_fetch_result().
43 add_upstream_commit() {
45 cd submodule &&
46 echo new >> subfile &&
47 test_tick &&
48 git add subfile &&
49 git commit -m new subfile &&
50 new_head=$(git rev-parse --short HEAD) &&
51 write_expected_sub $new_head
52 ) &&
54 cd deepsubmodule &&
55 echo new >> deepsubfile &&
56 test_tick &&
57 git add deepsubfile &&
58 git commit -m new deepsubfile &&
59 new_head=$(git rev-parse --short HEAD) &&
60 write_expected_deep $new_head
64 # Verifies that the expected repositories were fetched. This is done by
65 # concatenating the files expect.err.[super|sub|deep] in the correct
66 # order and comparing it to the actual stderr.
68 # If a repo should not be fetched in the test, its corresponding
69 # expect.err file should be rm-ed.
70 verify_fetch_result () {
71 ACTUAL_ERR=$1 &&
72 rm -f expect.err.combined &&
73 if test -f expect.err.super
74 then
75 cat expect.err.super >>expect.err.combined
76 fi &&
77 if test -f expect.err.sub
78 then
79 cat expect.err.sub >>expect.err.combined
80 fi &&
81 if test -f expect.err.deep
82 then
83 cat expect.err.deep >>expect.err.combined
84 fi &&
85 sed -e 's/[0-9a-f][0-9a-f]*\.\./OLD_HEAD\.\./' "$ACTUAL_ERR" >actual.err.cmp &&
86 test_cmp expect.err.combined actual.err.cmp
89 test_expect_success setup '
90 mkdir deepsubmodule &&
92 cd deepsubmodule &&
93 git init &&
94 echo deepsubcontent > deepsubfile &&
95 git add deepsubfile &&
96 git commit -m new deepsubfile &&
97 git branch -M deep
98 ) &&
99 mkdir submodule &&
101 cd submodule &&
102 git init &&
103 echo subcontent > subfile &&
104 git add subfile &&
105 git submodule add "$pwd/deepsubmodule" subdir/deepsubmodule &&
106 git commit -a -m new &&
107 git branch -M sub
108 ) &&
109 git submodule add "$pwd/submodule" submodule &&
110 git commit -am initial &&
111 git branch -M super &&
112 git clone . downstream &&
114 cd downstream &&
115 git submodule update --init --recursive
119 test_expect_success "fetch --recurse-submodules recurses into submodules" '
120 add_upstream_commit &&
122 cd downstream &&
123 git fetch --recurse-submodules >../actual.out 2>../actual.err
124 ) &&
125 test_must_be_empty actual.out &&
126 verify_fetch_result actual.err
129 test_expect_success "submodule.recurse option triggers recursive fetch" '
130 add_upstream_commit &&
132 cd downstream &&
133 git -c submodule.recurse fetch >../actual.out 2>../actual.err
134 ) &&
135 test_must_be_empty actual.out &&
136 verify_fetch_result actual.err
139 test_expect_success "fetch --recurse-submodules -j2 has the same output behaviour" '
140 add_upstream_commit &&
142 cd downstream &&
143 GIT_TRACE="$TRASH_DIRECTORY/trace.out" git fetch --recurse-submodules -j2 2>../actual.err
144 ) &&
145 test_must_be_empty actual.out &&
146 verify_fetch_result actual.err &&
147 grep "2 tasks" trace.out
150 test_expect_success "fetch alone only fetches superproject" '
151 add_upstream_commit &&
153 cd downstream &&
154 git fetch >../actual.out 2>../actual.err
155 ) &&
156 test_must_be_empty actual.out &&
157 test_must_be_empty actual.err
160 test_expect_success "fetch --no-recurse-submodules only fetches superproject" '
162 cd downstream &&
163 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
164 ) &&
165 test_must_be_empty actual.out &&
166 test_must_be_empty actual.err
169 test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
171 cd downstream &&
172 git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
173 git fetch >../actual.out 2>../actual.err
174 ) &&
175 test_must_be_empty actual.out &&
176 verify_fetch_result actual.err
179 test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
180 add_upstream_commit &&
182 cd downstream &&
183 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
184 ) &&
185 test_must_be_empty actual.out &&
186 test_must_be_empty actual.err
189 test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
191 cd downstream &&
192 git config submodule.submodule.fetchRecurseSubmodules false &&
193 git fetch >../actual.out 2>../actual.err
194 ) &&
195 test_must_be_empty actual.out &&
196 test_must_be_empty actual.err
199 test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
201 cd downstream &&
202 git fetch --recurse-submodules >../actual.out 2>../actual.err &&
203 git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
204 git config --unset submodule.submodule.fetchRecurseSubmodules
205 ) &&
206 test_must_be_empty actual.out &&
207 verify_fetch_result actual.err
210 test_expect_success "--quiet propagates to submodules" '
212 cd downstream &&
213 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
214 ) &&
215 test_must_be_empty actual.out &&
216 test_must_be_empty actual.err
219 test_expect_success "--quiet propagates to parallel submodules" '
221 cd downstream &&
222 git fetch --recurse-submodules -j 2 --quiet >../actual.out 2>../actual.err
223 ) &&
224 test_must_be_empty actual.out &&
225 test_must_be_empty actual.err
228 test_expect_success "--dry-run propagates to submodules" '
229 add_upstream_commit &&
231 cd downstream &&
232 git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
233 ) &&
234 test_must_be_empty actual.out &&
235 verify_fetch_result actual.err
238 test_expect_success "Without --dry-run propagates to submodules" '
240 cd downstream &&
241 git fetch --recurse-submodules >../actual.out 2>../actual.err
242 ) &&
243 test_must_be_empty actual.out &&
244 verify_fetch_result actual.err
247 test_expect_success "recurseSubmodules=true propagates into submodules" '
248 add_upstream_commit &&
250 cd downstream &&
251 git config fetch.recurseSubmodules true &&
252 git fetch >../actual.out 2>../actual.err
253 ) &&
254 test_must_be_empty actual.out &&
255 verify_fetch_result actual.err
258 test_expect_success "--recurse-submodules overrides config in submodule" '
259 add_upstream_commit &&
261 cd downstream &&
263 cd submodule &&
264 git config fetch.recurseSubmodules false
265 ) &&
266 git fetch --recurse-submodules >../actual.out 2>../actual.err
267 ) &&
268 test_must_be_empty actual.out &&
269 verify_fetch_result actual.err
272 test_expect_success "--no-recurse-submodules overrides config setting" '
273 add_upstream_commit &&
275 cd downstream &&
276 git config fetch.recurseSubmodules true &&
277 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
278 ) &&
279 test_must_be_empty actual.out &&
280 test_must_be_empty actual.err
283 test_expect_success "Recursion doesn't happen when no new commits are fetched in the superproject" '
285 cd downstream &&
287 cd submodule &&
288 git config --unset fetch.recurseSubmodules
289 ) &&
290 git config --unset fetch.recurseSubmodules &&
291 git fetch >../actual.out 2>../actual.err
292 ) &&
293 test_must_be_empty actual.out &&
294 test_must_be_empty actual.err
297 test_expect_success "Recursion stops when no new submodule commits are fetched" '
298 git add submodule &&
299 git commit -m "new submodule" &&
300 new_head=$(git rev-parse --short HEAD) &&
301 write_expected_super $new_head &&
302 rm expect.err.deep &&
304 cd downstream &&
305 git fetch >../actual.out 2>../actual.err
306 ) &&
307 verify_fetch_result actual.err &&
308 test_must_be_empty actual.out
311 test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
312 add_upstream_commit &&
313 echo a > file &&
314 git add file &&
315 git commit -m "new file" &&
316 new_head=$(git rev-parse --short HEAD) &&
317 write_expected_super $new_head &&
318 rm expect.err.sub &&
319 rm expect.err.deep &&
321 cd downstream &&
322 git fetch >../actual.out 2>../actual.err
323 ) &&
324 test_must_be_empty actual.out &&
325 verify_fetch_result actual.err
328 test_expect_success "Recursion picks up config in submodule" '
330 cd downstream &&
331 git fetch --recurse-submodules &&
333 cd submodule &&
334 git config fetch.recurseSubmodules true
336 ) &&
337 add_upstream_commit &&
338 git add submodule &&
339 git commit -m "new submodule" &&
340 new_head=$(git rev-parse --short HEAD) &&
341 write_expected_super $new_head &&
343 cd downstream &&
344 git fetch >../actual.out 2>../actual.err &&
346 cd submodule &&
347 git config --unset fetch.recurseSubmodules
349 ) &&
350 verify_fetch_result actual.err &&
351 test_must_be_empty actual.out
354 test_expect_success "Recursion picks up all submodules when necessary" '
355 add_upstream_commit &&
357 cd submodule &&
359 cd subdir/deepsubmodule &&
360 git fetch &&
361 git checkout -q FETCH_HEAD
362 ) &&
363 git add subdir/deepsubmodule &&
364 git commit -m "new deepsubmodule" &&
365 new_head=$(git rev-parse --short HEAD) &&
366 write_expected_sub $new_head
367 ) &&
368 git add submodule &&
369 git commit -m "new submodule" &&
370 new_head=$(git rev-parse --short HEAD) &&
371 write_expected_super $new_head &&
373 cd downstream &&
374 git fetch >../actual.out 2>../actual.err
375 ) &&
376 verify_fetch_result actual.err &&
377 test_must_be_empty actual.out
380 test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
381 add_upstream_commit &&
383 cd submodule &&
385 cd subdir/deepsubmodule &&
386 git fetch &&
387 git checkout -q FETCH_HEAD
388 ) &&
389 git add subdir/deepsubmodule &&
390 git commit -m "new deepsubmodule" &&
391 new_head=$(git rev-parse --short HEAD) &&
392 write_expected_sub $new_head
393 ) &&
395 cd downstream &&
396 git config fetch.recurseSubmodules true &&
397 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
398 git config --unset fetch.recurseSubmodules
399 ) &&
400 test_must_be_empty actual.out &&
401 test_must_be_empty actual.err
404 test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
405 git add submodule &&
406 git commit -m "new submodule" &&
407 new_head=$(git rev-parse --short HEAD) &&
408 write_expected_super $new_head &&
410 cd downstream &&
411 git config fetch.recurseSubmodules false &&
413 cd submodule &&
414 git config -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive false
415 ) &&
416 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
417 git config --unset fetch.recurseSubmodules &&
419 cd submodule &&
420 git config --unset -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive
422 ) &&
423 test_must_be_empty actual.out &&
424 verify_fetch_result actual.err
427 test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
428 add_upstream_commit &&
429 echo a >> file &&
430 git add file &&
431 git commit -m "new file" &&
432 new_head=$(git rev-parse --short HEAD) &&
433 write_expected_super $new_head &&
434 rm expect.err.sub &&
435 rm expect.err.deep &&
437 cd downstream &&
438 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
439 ) &&
440 test_must_be_empty actual.out &&
441 verify_fetch_result actual.err
444 test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" '
446 cd downstream &&
447 git fetch --recurse-submodules
448 ) &&
449 add_upstream_commit &&
450 git config --global fetch.recurseSubmodules false &&
451 git add submodule &&
452 git commit -m "new submodule" &&
453 new_head=$(git rev-parse --short HEAD) &&
454 write_expected_super $new_head &&
455 rm expect.err.deep &&
457 cd downstream &&
458 git config fetch.recurseSubmodules on-demand &&
459 git fetch >../actual.out 2>../actual.err
460 ) &&
461 git config --global --unset fetch.recurseSubmodules &&
463 cd downstream &&
464 git config --unset fetch.recurseSubmodules
465 ) &&
466 test_must_be_empty actual.out &&
467 verify_fetch_result actual.err
470 test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
472 cd downstream &&
473 git fetch --recurse-submodules
474 ) &&
475 add_upstream_commit &&
476 git config fetch.recurseSubmodules false &&
477 git add submodule &&
478 git commit -m "new submodule" &&
479 new_head=$(git rev-parse --short HEAD) &&
480 write_expected_super $new_head &&
481 rm expect.err.deep &&
483 cd downstream &&
484 git config submodule.submodule.fetchRecurseSubmodules on-demand &&
485 git fetch >../actual.out 2>../actual.err
486 ) &&
487 git config --unset fetch.recurseSubmodules &&
489 cd downstream &&
490 git config --unset submodule.submodule.fetchRecurseSubmodules
491 ) &&
492 test_must_be_empty actual.out &&
493 verify_fetch_result actual.err
496 test_expect_success "don't fetch submodule when newly recorded commits are already present" '
498 cd submodule &&
499 git checkout -q HEAD^^
500 ) &&
501 git add submodule &&
502 git commit -m "submodule rewound" &&
503 new_head=$(git rev-parse --short HEAD) &&
504 write_expected_super $new_head &&
505 rm expect.err.sub &&
506 # This file does not exist, but rm -f for readability
507 rm -f expect.err.deep &&
509 cd downstream &&
510 git fetch >../actual.out 2>../actual.err
511 ) &&
512 test_must_be_empty actual.out &&
513 verify_fetch_result actual.err &&
515 cd submodule &&
516 git checkout -q sub
520 test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .gitmodules entry" '
522 cd downstream &&
523 git fetch --recurse-submodules
524 ) &&
525 add_upstream_commit &&
526 git add submodule &&
527 git rm .gitmodules &&
528 git commit -m "new submodule without .gitmodules" &&
529 new_head=$(git rev-parse --short HEAD) &&
530 write_expected_super $new_head &&
531 rm expect.err.deep &&
533 cd downstream &&
534 rm .gitmodules &&
535 git config fetch.recurseSubmodules on-demand &&
536 # fake submodule configuration to avoid skipping submodule handling
537 git config -f .gitmodules submodule.fake.path fake &&
538 git config -f .gitmodules submodule.fake.url fakeurl &&
539 git add .gitmodules &&
540 git config --unset submodule.submodule.url &&
541 git fetch >../actual.out 2>../actual.err &&
542 # cleanup
543 git config --unset fetch.recurseSubmodules &&
544 git reset --hard
545 ) &&
546 test_must_be_empty actual.out &&
547 verify_fetch_result actual.err &&
548 git checkout HEAD^ -- .gitmodules &&
549 git add .gitmodules &&
550 git commit -m "new submodule restored .gitmodules"
553 test_expect_success 'fetching submodules respects parallel settings' '
554 git config fetch.recurseSubmodules true &&
556 cd downstream &&
557 GIT_TRACE=$(pwd)/trace.out git fetch &&
558 grep "1 tasks" trace.out &&
559 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
560 grep "7 tasks" trace.out &&
561 git config submodule.fetchJobs 8 &&
562 GIT_TRACE=$(pwd)/trace.out git fetch &&
563 grep "8 tasks" trace.out &&
564 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
565 grep "9 tasks" trace.out
569 test_expect_success 'fetching submodule into a broken repository' '
570 # Prepare src and src/sub nested in it
571 git init src &&
573 cd src &&
574 git init sub &&
575 git -C sub commit --allow-empty -m "initial in sub" &&
576 git submodule add -- ./sub sub &&
577 git commit -m "initial in top"
578 ) &&
580 # Clone the old-fashoned way
581 git clone src dst &&
582 git -C dst clone ../src/sub sub &&
584 # Make sure that old-fashoned layout is still supported
585 git -C dst status &&
587 # "diff" would find no change
588 git -C dst diff --exit-code &&
590 # Recursive-fetch works fine
591 git -C dst fetch --recurse-submodules &&
593 # Break the receiving submodule
594 rm -f dst/sub/.git/HEAD &&
596 # NOTE: without the fix the following tests will recurse forever!
597 # They should terminate with an error.
599 test_must_fail git -C dst status &&
600 test_must_fail git -C dst diff &&
601 test_must_fail git -C dst fetch --recurse-submodules
604 test_expect_success "fetch new commits when submodule got renamed" '
605 git clone . downstream_rename &&
607 cd downstream_rename &&
608 git submodule update --init --recursive &&
609 git checkout -b rename &&
610 git mv submodule submodule_renamed &&
612 cd submodule_renamed &&
613 git checkout -b rename_sub &&
614 echo a >a &&
615 git add a &&
616 git commit -ma &&
617 git push origin rename_sub &&
618 git rev-parse HEAD >../../expect
619 ) &&
620 git add submodule_renamed &&
621 git commit -m "update renamed submodule" &&
622 git push origin rename
623 ) &&
625 cd downstream &&
626 git fetch --recurse-submodules=on-demand &&
628 cd submodule &&
629 git rev-parse origin/rename_sub >../../actual
631 ) &&
632 test_cmp expect actual
635 test_expect_success "fetch new submodule commits on-demand outside standard refspec" '
636 # add a second submodule and ensure it is around in downstream first
637 git clone submodule sub1 &&
638 git submodule add ./sub1 &&
639 git commit -m "adding a second submodule" &&
640 git -C downstream pull &&
641 git -C downstream submodule update --init --recursive &&
643 git checkout --detach &&
645 C=$(git -C submodule commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
646 git -C submodule update-ref refs/changes/1 $C &&
647 git update-index --cacheinfo 160000 $C submodule &&
648 test_tick &&
650 D=$(git -C sub1 commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
651 git -C sub1 update-ref refs/changes/2 $D &&
652 git update-index --cacheinfo 160000 $D sub1 &&
654 git commit -m "updated submodules outside of refs/heads" &&
655 E=$(git rev-parse HEAD) &&
656 git update-ref refs/changes/3 $E &&
658 cd downstream &&
659 git fetch --recurse-submodules origin refs/changes/3:refs/heads/my_branch &&
660 git -C submodule cat-file -t $C &&
661 git -C sub1 cat-file -t $D &&
662 git checkout --recurse-submodules FETCH_HEAD
666 test_expect_success 'fetch new submodule commit on-demand in FETCH_HEAD' '
667 # depends on the previous test for setup
669 C=$(git -C submodule commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
670 git -C submodule update-ref refs/changes/4 $C &&
671 git update-index --cacheinfo 160000 $C submodule &&
672 test_tick &&
674 D=$(git -C sub1 commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
675 git -C sub1 update-ref refs/changes/5 $D &&
676 git update-index --cacheinfo 160000 $D sub1 &&
678 git commit -m "updated submodules outside of refs/heads" &&
679 E=$(git rev-parse HEAD) &&
680 git update-ref refs/changes/6 $E &&
682 cd downstream &&
683 git fetch --recurse-submodules origin refs/changes/6 &&
684 git -C submodule cat-file -t $C &&
685 git -C sub1 cat-file -t $D &&
686 git checkout --recurse-submodules FETCH_HEAD
690 test_expect_success 'fetch new submodule commits on-demand without .gitmodules entry' '
691 # depends on the previous test for setup
693 git config -f .gitmodules --remove-section submodule.sub1 &&
694 git add .gitmodules &&
695 git commit -m "delete gitmodules file" &&
696 git checkout -B super &&
697 git -C downstream fetch &&
698 git -C downstream checkout origin/super &&
700 C=$(git -C submodule commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
701 git -C submodule update-ref refs/changes/7 $C &&
702 git update-index --cacheinfo 160000 $C submodule &&
703 test_tick &&
705 D=$(git -C sub1 commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
706 git -C sub1 update-ref refs/changes/8 $D &&
707 git update-index --cacheinfo 160000 $D sub1 &&
709 git commit -m "updated submodules outside of refs/heads" &&
710 E=$(git rev-parse HEAD) &&
711 git update-ref refs/changes/9 $E &&
713 cd downstream &&
714 git fetch --recurse-submodules origin refs/changes/9 &&
715 git -C submodule cat-file -t $C &&
716 git -C sub1 cat-file -t $D &&
717 git checkout --recurse-submodules FETCH_HEAD
721 test_expect_success 'fetch new submodule commit intermittently referenced by superproject' '
722 # depends on the previous test for setup
724 D=$(git -C sub1 commit-tree -m "change 10 outside refs/heads" HEAD^{tree}) &&
725 E=$(git -C sub1 commit-tree -m "change 11 outside refs/heads" HEAD^{tree}) &&
726 F=$(git -C sub1 commit-tree -m "change 12 outside refs/heads" HEAD^{tree}) &&
728 git -C sub1 update-ref refs/changes/10 $D &&
729 git update-index --cacheinfo 160000 $D sub1 &&
730 git commit -m "updated submodules outside of refs/heads" &&
732 git -C sub1 update-ref refs/changes/11 $E &&
733 git update-index --cacheinfo 160000 $E sub1 &&
734 git commit -m "updated submodules outside of refs/heads" &&
736 git -C sub1 update-ref refs/changes/12 $F &&
737 git update-index --cacheinfo 160000 $F sub1 &&
738 git commit -m "updated submodules outside of refs/heads" &&
740 G=$(git rev-parse HEAD) &&
741 git update-ref refs/changes/13 $G &&
743 cd downstream &&
744 git fetch --recurse-submodules origin refs/changes/13 &&
746 git -C sub1 cat-file -t $D &&
747 git -C sub1 cat-file -t $E &&
748 git -C sub1 cat-file -t $F
752 add_commit_push () {
753 dir="$1" &&
754 msg="$2" &&
755 shift 2 &&
756 git -C "$dir" add "$@" &&
757 git -C "$dir" commit -a -m "$msg" &&
758 git -C "$dir" push
761 compare_refs_in_dir () {
762 fail= &&
763 if test "x$1" = 'x!'
764 then
765 fail='!' &&
766 shift
767 fi &&
768 git -C "$1" rev-parse --verify "$2" >expect &&
769 git -C "$3" rev-parse --verify "$4" >actual &&
770 eval $fail test_cmp expect actual
774 test_expect_success 'setup nested submodule fetch test' '
775 # does not depend on any previous test setups
777 for repo in outer middle inner
779 git init --bare $repo &&
780 git clone $repo ${repo}_content &&
781 echo "$repo" >"${repo}_content/file" &&
782 add_commit_push ${repo}_content "initial" file ||
783 return 1
784 done &&
786 git clone outer A &&
787 git -C A submodule add "$pwd/middle" &&
788 git -C A/middle/ submodule add "$pwd/inner" &&
789 add_commit_push A/middle/ "adding inner sub" .gitmodules inner &&
790 add_commit_push A/ "adding middle sub" .gitmodules middle &&
792 git clone outer B &&
793 git -C B/ submodule update --init middle &&
795 compare_refs_in_dir A HEAD B HEAD &&
796 compare_refs_in_dir A/middle HEAD B/middle HEAD &&
797 test_path_is_file B/file &&
798 test_path_is_file B/middle/file &&
799 test_path_is_missing B/middle/inner/file &&
801 echo "change on inner repo of A" >"A/middle/inner/file" &&
802 add_commit_push A/middle/inner "change on inner" file &&
803 add_commit_push A/middle "change on inner" inner &&
804 add_commit_push A "change on inner" middle
807 test_expect_success 'fetching a superproject containing an uninitialized sub/sub project' '
808 # depends on previous test for setup
810 git -C B/ fetch &&
811 compare_refs_in_dir A origin/HEAD B origin/HEAD
814 fetch_with_recursion_abort () {
815 # In a regression the following git call will run into infinite recursion.
816 # To handle that, we connect the sed command to the git call by a pipe
817 # so that sed can kill the infinite recursion when detected.
818 # The recursion creates git output like:
819 # Fetching submodule sub
820 # Fetching submodule sub/sub <-- [1]
821 # Fetching submodule sub/sub/sub
822 # ...
823 # [1] sed will stop reading and cause git to eventually stop and die
825 git -C "$1" fetch --recurse-submodules 2>&1 |
826 sed "/Fetching submodule $2[^$]/q" >out &&
827 ! grep "Fetching submodule $2[^$]" out
830 test_expect_success 'setup recursive fetch with uninit submodule' '
831 # does not depend on any previous test setups
833 test_create_repo super &&
834 test_commit -C super initial &&
835 test_create_repo sub &&
836 test_commit -C sub initial &&
837 git -C sub rev-parse HEAD >expect &&
839 git -C super submodule add ../sub &&
840 git -C super commit -m "add sub" &&
842 git clone super superclone &&
843 git -C superclone submodule status >out &&
844 sed -e "s/^-//" -e "s/ sub.*$//" out >actual &&
845 test_cmp expect actual
848 test_expect_success 'recursive fetch with uninit submodule' '
849 # depends on previous test for setup
851 fetch_with_recursion_abort superclone sub &&
852 git -C superclone submodule status >out &&
853 sed -e "s/^-//" -e "s/ sub$//" out >actual &&
854 test_cmp expect actual
857 test_expect_success 'recursive fetch after deinit a submodule' '
858 # depends on previous test for setup
860 git -C superclone submodule update --init sub &&
861 git -C superclone submodule deinit -f sub &&
863 fetch_with_recursion_abort superclone sub &&
864 git -C superclone submodule status >out &&
865 sed -e "s/^-//" -e "s/ sub$//" out >actual &&
866 test_cmp expect actual
869 test_done