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
13 write_expected_sub
() {
16 cat >"$pwd/expect.err.sub" <<-EOF
17 Fetching submodule submodule${SUPER_HEAD:+ at commit $SUPER_HEAD}
19 OLD_HEAD..$NEW_HEAD sub -> origin/sub
23 write_expected_sub2
() {
26 cat >"$pwd/expect.err.sub2" <<-EOF
27 Fetching submodule submodule2${SUPER_HEAD:+ at commit $SUPER_HEAD}
29 OLD_HEAD..$NEW_HEAD sub2 -> origin/sub2
33 write_expected_deep
() {
36 cat >"$pwd/expect.err.deep" <<-EOF
37 Fetching submodule submodule/subdir/deepsubmodule${SUB_HEAD:+ at commit $SUB_HEAD}
38 From $pwd/deepsubmodule
39 OLD_HEAD..$NEW_HEAD deep -> origin/deep
43 write_expected_super
() {
45 cat >"$pwd/expect.err.super" <<-EOF
47 OLD_HEAD..$NEW_HEAD super -> origin/super
51 # For each submodule in the test setup, this creates a commit and writes
52 # a file that contains the expected err if that new commit were fetched.
53 # These output files get concatenated in the right order by
54 # verify_fetch_result().
55 add_submodule_commits
() {
58 echo new
>> subfile
&&
61 git commit
-m new subfile
&&
62 new_head
=$
(git rev-parse
--short HEAD
) &&
63 write_expected_sub
$new_head
67 echo new
>> deepsubfile
&&
69 git add deepsubfile
&&
70 git commit
-m new deepsubfile
&&
71 new_head
=$
(git rev-parse
--short HEAD
) &&
72 write_expected_deep
$new_head
76 # For each superproject in the test setup, update its submodule, add the
77 # submodule and create a new commit with the submodule change.
79 # This requires add_submodule_commits() to be called first, otherwise
80 # the submodules will not have changed and cannot be "git add"-ed.
81 add_superproject_commits
() {
85 cd subdir
/deepsubmodule
&&
87 git checkout
-q FETCH_HEAD
89 git add subdir
/deepsubmodule
&&
90 git commit
-m "new deep submodule"
93 git commit
-m "new submodule" &&
94 super_head
=$
(git rev-parse
--short HEAD
) &&
95 sub_head
=$
(git
-C submodule rev-parse
--short HEAD
) &&
96 write_expected_super
$super_head &&
97 write_expected_sub
$sub_head
100 # Verifies that the expected repositories were fetched. This is done by
101 # concatenating the files expect.err.[super|sub|deep] in the correct
102 # order and comparing it to the actual stderr.
104 # If a repo should not be fetched in the test, its corresponding
105 # expect.err file should be rm-ed.
106 verify_fetch_result
() {
108 rm -f expect.err.combined
&&
109 if test -f expect.err.super
111 cat expect.err.super
>>expect.err.combined
113 if test -f expect.err.sub
115 cat expect.err.sub
>>expect.err.combined
117 if test -f expect.err.deep
119 cat expect.err.deep
>>expect.err.combined
121 if test -f expect.err.sub2
123 cat expect.err.sub2
>>expect.err.combined
125 sed -e 's/[0-9a-f][0-9a-f]*\.\./OLD_HEAD\.\./' "$ACTUAL_ERR" >actual.err.
cmp &&
126 test_cmp expect.err.combined actual.err.
cmp
129 test_expect_success setup
'
130 git config --global protocol.file.allow always &&
131 mkdir deepsubmodule &&
135 echo deepsubcontent > deepsubfile &&
136 git add deepsubfile &&
137 git commit -m new deepsubfile &&
144 echo subcontent > subfile &&
146 git submodule add "$pwd/deepsubmodule" subdir/deepsubmodule &&
147 git commit -a -m new &&
150 git submodule add "$pwd/submodule" submodule &&
151 git commit -am initial &&
152 git branch -M super &&
153 git clone . downstream &&
156 git submodule update --init --recursive
160 test_expect_success
"fetch --recurse-submodules recurses into submodules" '
161 add_submodule_commits &&
164 git fetch --recurse-submodules >../actual.out 2>../actual.err
166 test_must_be_empty actual.out &&
167 verify_fetch_result actual.err
170 test_expect_success
"submodule.recurse option triggers recursive fetch" '
171 add_submodule_commits &&
174 git -c submodule.recurse fetch >../actual.out 2>../actual.err
176 test_must_be_empty actual.out &&
177 verify_fetch_result actual.err
180 test_expect_success
"fetch --recurse-submodules -j2 has the same output behaviour" '
181 test_when_finished "rm -f trace.out" &&
182 add_submodule_commits &&
185 GIT_TRACE="$TRASH_DIRECTORY/trace.out" git fetch --recurse-submodules -j2 2>../actual.err
187 test_must_be_empty actual.out &&
188 verify_fetch_result actual.err &&
189 grep "2 tasks" trace.out
192 test_expect_success
"fetch alone only fetches superproject" '
193 add_submodule_commits &&
196 git fetch >../actual.out 2>../actual.err
198 test_must_be_empty actual.out &&
199 test_must_be_empty actual.err
202 test_expect_success
"fetch --no-recurse-submodules only fetches superproject" '
205 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
207 test_must_be_empty actual.out &&
208 test_must_be_empty actual.err
211 test_expect_success
"using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
214 git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
215 git fetch >../actual.out 2>../actual.err
217 test_must_be_empty actual.out &&
218 verify_fetch_result actual.err
221 test_expect_success
"--no-recurse-submodules overrides .gitmodules config" '
222 add_submodule_commits &&
225 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
227 test_must_be_empty actual.out &&
228 test_must_be_empty actual.err
231 test_expect_success
"using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
234 git config submodule.submodule.fetchRecurseSubmodules false &&
235 git fetch >../actual.out 2>../actual.err
237 test_must_be_empty actual.out &&
238 test_must_be_empty actual.err
241 test_expect_success
"--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
244 git fetch --recurse-submodules >../actual.out 2>../actual.err &&
245 git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
246 git config --unset submodule.submodule.fetchRecurseSubmodules
248 test_must_be_empty actual.out &&
249 verify_fetch_result actual.err
252 test_expect_success
"--quiet propagates to submodules" '
255 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
257 test_must_be_empty actual.out &&
258 test_must_be_empty actual.err
261 test_expect_success
"--quiet propagates to parallel submodules" '
264 git fetch --recurse-submodules -j 2 --quiet >../actual.out 2>../actual.err
266 test_must_be_empty actual.out &&
267 test_must_be_empty actual.err
270 test_expect_success
"--dry-run propagates to submodules" '
271 add_submodule_commits &&
274 git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
276 test_must_be_empty actual.out &&
277 verify_fetch_result actual.err
280 test_expect_success
"Without --dry-run propagates to submodules" '
283 git fetch --recurse-submodules >../actual.out 2>../actual.err
285 test_must_be_empty actual.out &&
286 verify_fetch_result actual.err
289 test_expect_success
"recurseSubmodules=true propagates into submodules" '
290 add_submodule_commits &&
293 git config fetch.recurseSubmodules true &&
294 git fetch >../actual.out 2>../actual.err
296 test_must_be_empty actual.out &&
297 verify_fetch_result actual.err
300 test_expect_success
"--recurse-submodules overrides config in submodule" '
301 add_submodule_commits &&
306 git config fetch.recurseSubmodules false
308 git fetch --recurse-submodules >../actual.out 2>../actual.err
310 test_must_be_empty actual.out &&
311 verify_fetch_result actual.err
314 test_expect_success
"--no-recurse-submodules overrides config setting" '
315 add_submodule_commits &&
318 git config fetch.recurseSubmodules true &&
319 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
321 test_must_be_empty actual.out &&
322 test_must_be_empty actual.err
325 test_expect_success
"Recursion doesn't happen when no new commits are fetched in the superproject" '
330 git config --unset fetch.recurseSubmodules
332 git config --unset fetch.recurseSubmodules &&
333 git fetch >../actual.out 2>../actual.err
335 test_must_be_empty actual.out &&
336 test_must_be_empty actual.err
339 test_expect_success
"Recursion stops when no new submodule commits are fetched" '
341 git commit -m "new submodule" &&
342 new_head=$(git rev-parse --short HEAD) &&
343 write_expected_super $new_head &&
344 rm expect.err.deep &&
347 git fetch >../actual.out 2>../actual.err
349 verify_fetch_result actual.err &&
350 test_must_be_empty actual.out
353 test_expect_success
"Recursion doesn't happen when new superproject commits don't change any submodules" '
354 add_submodule_commits &&
357 git commit -m "new file" &&
358 new_head=$(git rev-parse --short HEAD) &&
359 write_expected_super $new_head &&
361 rm expect.err.deep &&
364 git fetch >../actual.out 2>../actual.err
366 test_must_be_empty actual.out &&
367 verify_fetch_result actual.err
370 test_expect_success
"Recursion picks up config in submodule" '
373 git fetch --recurse-submodules &&
376 git config fetch.recurseSubmodules true
379 add_submodule_commits &&
381 git commit -m "new submodule" &&
382 new_head=$(git rev-parse --short HEAD) &&
383 write_expected_super $new_head &&
386 git fetch >../actual.out 2>../actual.err &&
389 git config --unset fetch.recurseSubmodules
392 verify_fetch_result actual.err &&
393 test_must_be_empty actual.out
396 test_expect_success
"Recursion picks up all submodules when necessary" '
397 add_submodule_commits &&
398 add_superproject_commits &&
401 git fetch >../actual.out 2>../actual.err
403 verify_fetch_result actual.err &&
404 test_must_be_empty actual.out
407 test_expect_success
"'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
408 add_submodule_commits &&
411 git config fetch.recurseSubmodules true &&
412 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
413 git config --unset fetch.recurseSubmodules
415 test_must_be_empty actual.out &&
416 test_must_be_empty actual.err
419 test_expect_success
"'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
420 add_submodule_commits &&
421 add_superproject_commits &&
424 git config fetch.recurseSubmodules false &&
427 git config -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive false
429 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
430 git config --unset fetch.recurseSubmodules &&
433 git config --unset -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive
436 test_must_be_empty actual.out &&
437 verify_fetch_result actual.err
440 # These tests verify that we can fetch submodules that aren't in the
443 # First, test the simple case where the index is empty and we only fetch
444 # submodules that are not in the index.
445 test_expect_success
'setup downstream branch without submodules' '
448 git checkout --recurse-submodules -b no-submodules &&
449 git rm .gitmodules &&
451 git commit -m "no submodules" &&
452 git checkout --recurse-submodules super
456 test_expect_success
"'--recurse-submodules=on-demand' should fetch submodule commits if the submodule is changed but the index has no submodules" '
457 add_submodule_commits &&
458 add_superproject_commits &&
459 # Fetch the new superproject commit
462 git switch --recurse-submodules no-submodules &&
463 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
465 super_head=$(git rev-parse --short HEAD) &&
466 sub_head=$(git -C submodule rev-parse --short HEAD) &&
467 deep_head=$(git -C submodule/subdir/deepsubmodule rev-parse --short HEAD) &&
469 # assert that these are fetched from commits, not the index
470 write_expected_sub $sub_head $super_head &&
471 write_expected_deep $deep_head $sub_head &&
473 test_must_be_empty actual.out &&
474 verify_fetch_result actual.err
477 test_expect_success
"'--recurse-submodules' should fetch submodule commits if the submodule is changed but the index has no submodules" '
478 add_submodule_commits &&
479 add_superproject_commits &&
480 # Fetch the new superproject commit
483 git switch --recurse-submodules no-submodules &&
484 git fetch --recurse-submodules >../actual.out 2>../actual.err
486 super_head=$(git rev-parse --short HEAD) &&
487 sub_head=$(git -C submodule rev-parse --short HEAD) &&
488 deep_head=$(git -C submodule/subdir/deepsubmodule rev-parse --short HEAD) &&
490 # assert that these are fetched from commits, not the index
491 write_expected_sub $sub_head $super_head &&
492 write_expected_deep $deep_head $sub_head &&
494 test_must_be_empty actual.out &&
495 verify_fetch_result actual.err
498 test_expect_success
"'--recurse-submodules' should ignore changed, inactive submodules" '
499 add_submodule_commits &&
500 add_superproject_commits &&
502 # Fetch the new superproject commit
505 git switch --recurse-submodules no-submodules &&
506 git -c submodule.submodule.active=false fetch --recurse-submodules >../actual.out 2>../actual.err
508 test_must_be_empty actual.out &&
509 super_head=$(git rev-parse --short HEAD) &&
510 write_expected_super $super_head &&
511 # Neither should be fetched because the submodule is inactive
513 rm expect.err.deep &&
514 verify_fetch_result actual.err
517 # Now that we know we can fetch submodules that are not in the index,
518 # test that we can fetch index and non-index submodules in the same
520 test_expect_success
'setup downstream branch with other submodule' '
525 echo sub2content >sub2file &&
527 git commit -a -m new &&
530 git checkout -b super-sub2-only &&
531 git submodule add "$pwd/submodule2" submodule2 &&
532 git commit -m "add sub2" &&
533 git checkout super &&
536 git fetch --recurse-submodules origin &&
537 git checkout super-sub2-only &&
538 # Explicitly run "git submodule update" because sub2 is new
539 # and has not been cloned.
540 git submodule update --init &&
541 git checkout --recurse-submodules super
545 test_expect_success
"'--recurse-submodules' should fetch submodule commits in changed submodules and the index" '
546 test_when_finished "rm expect.err.sub2" &&
547 # Create new commit in origin/super
548 add_submodule_commits &&
549 add_superproject_commits &&
551 # Create new commit in origin/super-sub2-only
552 git checkout super-sub2-only &&
555 test_commit --no-tag foo
557 git add submodule2 &&
558 git commit -m "new submodule2" &&
560 git checkout super &&
563 git fetch --recurse-submodules >../actual.out 2>../actual.err
565 test_must_be_empty actual.out &&
566 sub2_head=$(git -C submodule2 rev-parse --short HEAD) &&
567 super_head=$(git rev-parse --short super) &&
568 super_sub2_only_head=$(git rev-parse --short super-sub2-only) &&
569 write_expected_sub2 $sub2_head $super_sub2_only_head &&
571 # write_expected_super cannot handle >1 branch. Since this is a
572 # one-off, construct expect.err.super manually.
573 cat >"$pwd/expect.err.super" <<-EOF &&
575 OLD_HEAD..$super_head super -> origin/super
576 OLD_HEAD..$super_sub2_only_head super-sub2-only -> origin/super-sub2-only
578 verify_fetch_result actual.err
581 test_expect_success
"'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
582 add_submodule_commits &&
585 git commit -m "new file" &&
586 new_head=$(git rev-parse --short HEAD) &&
587 write_expected_super $new_head &&
589 rm expect.err.deep &&
592 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
594 test_must_be_empty actual.out &&
595 verify_fetch_result actual.err
598 test_expect_success
"'fetch.recurseSubmodules=on-demand' overrides global config" '
601 git fetch --recurse-submodules
603 add_submodule_commits &&
604 git config --global fetch.recurseSubmodules false &&
606 git commit -m "new submodule" &&
607 new_head=$(git rev-parse --short HEAD) &&
608 write_expected_super $new_head &&
609 rm expect.err.deep &&
612 git config fetch.recurseSubmodules on-demand &&
613 git fetch >../actual.out 2>../actual.err
615 git config --global --unset fetch.recurseSubmodules &&
618 git config --unset fetch.recurseSubmodules
620 test_must_be_empty actual.out &&
621 verify_fetch_result actual.err
624 test_expect_success
"'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
627 git fetch --recurse-submodules
629 add_submodule_commits &&
630 git config fetch.recurseSubmodules false &&
632 git commit -m "new submodule" &&
633 new_head=$(git rev-parse --short HEAD) &&
634 write_expected_super $new_head &&
635 rm expect.err.deep &&
638 git config submodule.submodule.fetchRecurseSubmodules on-demand &&
639 git fetch >../actual.out 2>../actual.err
641 git config --unset fetch.recurseSubmodules &&
644 git config --unset submodule.submodule.fetchRecurseSubmodules
646 test_must_be_empty actual.out &&
647 verify_fetch_result actual.err
650 test_expect_success
"don't fetch submodule when newly recorded commits are already present" '
653 git checkout -q HEAD^^
656 git commit -m "submodule rewound" &&
657 new_head=$(git rev-parse --short HEAD) &&
658 write_expected_super $new_head &&
660 # This file does not exist, but rm -f for readability
661 rm -f expect.err.deep &&
664 git fetch >../actual.out 2>../actual.err
666 test_must_be_empty actual.out &&
667 verify_fetch_result actual.err &&
674 test_expect_success
"'fetch.recurseSubmodules=on-demand' works also without .gitmodules entry" '
677 git fetch --recurse-submodules
679 add_submodule_commits &&
681 git rm .gitmodules &&
682 git commit -m "new submodule without .gitmodules" &&
683 new_head=$(git rev-parse --short HEAD) &&
684 write_expected_super $new_head &&
685 rm expect.err.deep &&
689 git config fetch.recurseSubmodules on-demand &&
690 # fake submodule configuration to avoid skipping submodule handling
691 git config -f .gitmodules submodule.fake.path fake &&
692 git config -f .gitmodules submodule.fake.url fakeurl &&
693 git add .gitmodules &&
694 git config --unset submodule.submodule.url &&
695 git fetch >../actual.out 2>../actual.err &&
697 git config --unset fetch.recurseSubmodules &&
700 test_must_be_empty actual.out &&
701 verify_fetch_result actual.err &&
702 git checkout HEAD^ -- .gitmodules &&
703 git add .gitmodules &&
704 git commit -m "new submodule restored .gitmodules"
707 test_expect_success
'fetching submodules respects parallel settings' '
708 git config fetch.recurseSubmodules true &&
709 test_when_finished "rm -f downstream/trace.out" &&
712 GIT_TRACE=$(pwd)/trace.out git fetch &&
713 grep "1 tasks" trace.out &&
716 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
717 grep "7 tasks" trace.out &&
720 git config submodule.fetchJobs 8 &&
721 GIT_TRACE=$(pwd)/trace.out git fetch &&
722 grep "8 tasks" trace.out &&
725 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
726 grep "9 tasks" trace.out &&
729 GIT_TRACE=$(pwd)/trace.out git -c submodule.fetchJobs=0 fetch &&
730 grep "preparing to run up to [0-9]* tasks" trace.out &&
731 ! grep "up to 0 tasks" trace.out &&
736 test_expect_success
'fetching submodule into a broken repository' '
737 # Prepare src and src/sub nested in it
742 git -C sub commit --allow-empty -m "initial in sub" &&
743 git submodule add -- ./sub sub &&
744 git commit -m "initial in top"
747 # Clone the old-fashoned way
749 git -C dst clone ../src/sub sub &&
751 # Make sure that old-fashoned layout is still supported
754 # "diff" would find no change
755 git -C dst diff --exit-code &&
757 # Recursive-fetch works fine
758 git -C dst fetch --recurse-submodules &&
760 # Break the receiving submodule
761 rm -f dst/sub/.git/HEAD &&
763 # NOTE: without the fix the following tests will recurse forever!
764 # They should terminate with an error.
766 test_must_fail git -C dst status &&
767 test_must_fail git -C dst diff &&
768 test_must_fail git -C dst fetch --recurse-submodules
771 test_expect_success
"fetch new commits when submodule got renamed" '
772 git clone . downstream_rename &&
774 cd downstream_rename &&
775 git submodule update --init --recursive &&
776 git checkout -b rename &&
777 git mv submodule submodule_renamed &&
779 cd submodule_renamed &&
780 git checkout -b rename_sub &&
784 git push origin rename_sub &&
785 git rev-parse HEAD >../../expect
787 git add submodule_renamed &&
788 git commit -m "update renamed submodule" &&
789 git push origin rename
793 git fetch --recurse-submodules=on-demand &&
796 git rev-parse origin/rename_sub >../../actual
799 test_cmp expect actual
802 test_expect_success
"fetch new submodule commits on-demand outside standard refspec" '
803 # add a second submodule and ensure it is around in downstream first
804 git clone submodule sub1 &&
805 git submodule add ./sub1 &&
806 git commit -m "adding a second submodule" &&
807 git -C downstream pull &&
808 git -C downstream submodule update --init --recursive &&
810 git checkout --detach &&
812 C=$(git -C submodule commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
813 git -C submodule update-ref refs/changes/1 $C &&
814 git update-index --cacheinfo 160000 $C submodule &&
817 D=$(git -C sub1 commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
818 git -C sub1 update-ref refs/changes/2 $D &&
819 git update-index --cacheinfo 160000 $D sub1 &&
821 git commit -m "updated submodules outside of refs/heads" &&
822 E=$(git rev-parse HEAD) &&
823 git update-ref refs/changes/3 $E &&
826 git fetch --recurse-submodules origin refs/changes/3:refs/heads/my_branch &&
827 git -C submodule cat-file -t $C &&
828 git -C sub1 cat-file -t $D &&
829 git checkout --recurse-submodules FETCH_HEAD
833 test_expect_success
'fetch new submodule commit on-demand in FETCH_HEAD' '
834 # depends on the previous test for setup
836 C=$(git -C submodule commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
837 git -C submodule update-ref refs/changes/4 $C &&
838 git update-index --cacheinfo 160000 $C submodule &&
841 D=$(git -C sub1 commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
842 git -C sub1 update-ref refs/changes/5 $D &&
843 git update-index --cacheinfo 160000 $D sub1 &&
845 git commit -m "updated submodules outside of refs/heads" &&
846 E=$(git rev-parse HEAD) &&
847 git update-ref refs/changes/6 $E &&
850 git fetch --recurse-submodules origin refs/changes/6 &&
851 git -C submodule cat-file -t $C &&
852 git -C sub1 cat-file -t $D &&
853 git checkout --recurse-submodules FETCH_HEAD
857 test_expect_success
'fetch new submodule commits on-demand without .gitmodules entry' '
858 # depends on the previous test for setup
860 git config -f .gitmodules --remove-section submodule.sub1 &&
861 git add .gitmodules &&
862 git commit -m "delete gitmodules file" &&
863 git checkout -B super &&
864 git -C downstream fetch &&
865 git -C downstream checkout origin/super &&
867 C=$(git -C submodule commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
868 git -C submodule update-ref refs/changes/7 $C &&
869 git update-index --cacheinfo 160000 $C submodule &&
872 D=$(git -C sub1 commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
873 git -C sub1 update-ref refs/changes/8 $D &&
874 git update-index --cacheinfo 160000 $D sub1 &&
876 git commit -m "updated submodules outside of refs/heads" &&
877 E=$(git rev-parse HEAD) &&
878 git update-ref refs/changes/9 $E &&
881 git fetch --recurse-submodules origin refs/changes/9 &&
882 git -C submodule cat-file -t $C &&
883 git -C sub1 cat-file -t $D &&
884 git checkout --recurse-submodules FETCH_HEAD
888 test_expect_success
'fetch new submodule commit intermittently referenced by superproject' '
889 # depends on the previous test for setup
891 D=$(git -C sub1 commit-tree -m "change 10 outside refs/heads" HEAD^{tree}) &&
892 E=$(git -C sub1 commit-tree -m "change 11 outside refs/heads" HEAD^{tree}) &&
893 F=$(git -C sub1 commit-tree -m "change 12 outside refs/heads" HEAD^{tree}) &&
895 git -C sub1 update-ref refs/changes/10 $D &&
896 git update-index --cacheinfo 160000 $D sub1 &&
897 git commit -m "updated submodules outside of refs/heads" &&
899 git -C sub1 update-ref refs/changes/11 $E &&
900 git update-index --cacheinfo 160000 $E sub1 &&
901 git commit -m "updated submodules outside of refs/heads" &&
903 git -C sub1 update-ref refs/changes/12 $F &&
904 git update-index --cacheinfo 160000 $F sub1 &&
905 git commit -m "updated submodules outside of refs/heads" &&
907 G=$(git rev-parse HEAD) &&
908 git update-ref refs/changes/13 $G &&
911 git fetch --recurse-submodules origin refs/changes/13 &&
913 git -C sub1 cat-file -t $D &&
914 git -C sub1 cat-file -t $E &&
915 git -C sub1 cat-file -t $F
923 git
-C "$dir" add
"$@" &&
924 git
-C "$dir" commit
-a -m "$msg" &&
928 compare_refs_in_dir
() {
935 git
-C "$1" rev-parse
--verify "$2" >expect
&&
936 git
-C "$3" rev-parse
--verify "$4" >actual
&&
937 eval $fail test_cmp expect actual
941 test_expect_success
'setup nested submodule fetch test' '
942 # does not depend on any previous test setups
944 for repo in outer middle inner
946 git init --bare $repo &&
947 git clone $repo ${repo}_content &&
948 echo "$repo" >"${repo}_content/file" &&
949 add_commit_push ${repo}_content "initial" file ||
954 git -C A submodule add "$pwd/middle" &&
955 git -C A/middle/ submodule add "$pwd/inner" &&
956 add_commit_push A/middle/ "adding inner sub" .gitmodules inner &&
957 add_commit_push A/ "adding middle sub" .gitmodules middle &&
960 git -C B/ submodule update --init middle &&
962 compare_refs_in_dir A HEAD B HEAD &&
963 compare_refs_in_dir A/middle HEAD B/middle HEAD &&
964 test_path_is_file B/file &&
965 test_path_is_file B/middle/file &&
966 test_path_is_missing B/middle/inner/file &&
968 echo "change on inner repo of A" >"A/middle/inner/file" &&
969 add_commit_push A/middle/inner "change on inner" file &&
970 add_commit_push A/middle "change on inner" inner &&
971 add_commit_push A "change on inner" middle
974 test_expect_success
'fetching a superproject containing an uninitialized sub/sub project' '
975 # depends on previous test for setup
978 compare_refs_in_dir A origin/HEAD B origin/HEAD
981 fetch_with_recursion_abort
() {
982 # In a regression the following git call will run into infinite recursion.
983 # To handle that, we connect the sed command to the git call by a pipe
984 # so that sed can kill the infinite recursion when detected.
985 # The recursion creates git output like:
986 # Fetching submodule sub
987 # Fetching submodule sub/sub <-- [1]
988 # Fetching submodule sub/sub/sub
990 # [1] sed will stop reading and cause git to eventually stop and die
992 git
-C "$1" fetch
--recurse-submodules 2>&1 |
993 sed "/Fetching submodule $2[^$]/q" >out
&&
994 ! grep "Fetching submodule $2[^$]" out
997 test_expect_success
'setup recursive fetch with uninit submodule' '
998 # does not depend on any previous test setups
1000 test_create_repo super &&
1001 test_commit -C super initial &&
1002 test_create_repo sub &&
1003 test_commit -C sub initial &&
1004 git -C sub rev-parse HEAD >expect &&
1006 git -C super submodule add ../sub &&
1007 git -C super commit -m "add sub" &&
1009 git clone super superclone &&
1010 git -C superclone submodule status >out &&
1011 sed -e "s/^-//" -e "s/ sub.*$//" out >actual &&
1012 test_cmp expect actual
1015 test_expect_success
'recursive fetch with uninit submodule' '
1016 # depends on previous test for setup
1018 fetch_with_recursion_abort superclone sub &&
1019 git -C superclone submodule status >out &&
1020 sed -e "s/^-//" -e "s/ sub$//" out >actual &&
1021 test_cmp expect actual
1024 test_expect_success
'recursive fetch after deinit a submodule' '
1025 # depends on previous test for setup
1027 git -C superclone submodule update --init sub &&
1028 git -C superclone submodule deinit -f sub &&
1030 fetch_with_recursion_abort superclone sub &&
1031 git -C superclone submodule status >out &&
1032 sed -e "s/^-//" -e "s/ sub$//" out >actual &&
1033 test_cmp expect actual
1036 test_expect_success
'setup repo with upstreams that share a submodule name' '
1037 mkdir same-name-1 &&
1041 test_commit --no-tag a
1043 git clone same-name-1 same-name-2 &&
1044 # same-name-1 and same-name-2 both add a submodule with the
1049 git -C submodule init -b main &&
1050 test_commit -C submodule --no-tag a1 &&
1051 git submodule add "$pwd/same-name-1/submodule" &&
1052 git add submodule &&
1053 git commit -m "super-a1"
1058 git -C submodule init -b main &&
1059 test_commit -C submodule --no-tag a2 &&
1060 git submodule add "$pwd/same-name-2/submodule" &&
1061 git add submodule &&
1062 git commit -m "super-a2"
1064 git clone same-name-1 -o same-name-1 same-name-downstream &&
1066 cd same-name-downstream &&
1067 git remote add same-name-2 ../same-name-2 &&
1069 # init downstream with same-name-1
1070 git submodule update --init
1074 test_expect_success
'fetch --recurse-submodules updates name-conflicted, populated submodule' '
1075 test_when_finished "git -C same-name-downstream checkout main" &&
1078 test_commit -C submodule --no-tag b1 &&
1079 git add submodule &&
1080 git commit -m "super-b1"
1084 test_commit -C submodule --no-tag b2 &&
1085 git add submodule &&
1086 git commit -m "super-b2"
1089 cd same-name-downstream &&
1090 # even though the .gitmodules is correct, we cannot
1091 # fetch from same-name-2
1092 git checkout same-name-2/main &&
1093 git fetch --recurse-submodules same-name-1 &&
1094 test_must_fail git fetch --recurse-submodules same-name-2
1096 super_head1=$(git -C same-name-1 rev-parse HEAD) &&
1097 git -C same-name-downstream cat-file -e $super_head1 &&
1099 super_head2=$(git -C same-name-2 rev-parse HEAD) &&
1100 git -C same-name-downstream cat-file -e $super_head2 &&
1102 sub_head1=$(git -C same-name-1/submodule rev-parse HEAD) &&
1103 git -C same-name-downstream/submodule cat-file -e $sub_head1 &&
1105 sub_head2=$(git -C same-name-2/submodule rev-parse HEAD) &&
1106 test_must_fail git -C same-name-downstream/submodule cat-file -e $sub_head2
1109 test_expect_success
'fetch --recurse-submodules updates name-conflicted, unpopulated submodule' '
1112 test_commit -C submodule --no-tag c1 &&
1113 git add submodule &&
1114 git commit -m "super-c1"
1118 test_commit -C submodule --no-tag c2 &&
1119 git add submodule &&
1120 git commit -m "super-c2"
1123 cd same-name-downstream &&
1124 git checkout main &&
1125 git rm .gitmodules &&
1127 git commit -m "no submodules" &&
1128 git fetch --recurse-submodules same-name-1
1130 head1=$(git -C same-name-1/submodule rev-parse HEAD) &&
1131 head2=$(git -C same-name-2/submodule rev-parse HEAD) &&
1133 cd same-name-downstream/.git/modules/submodule &&
1134 # The submodule has core.worktree pointing to the "git
1135 # rm"-ed directory, overwrite the invalid value. See
1136 # comment in get_fetch_task_from_changed() for more
1138 git --work-tree=. cat-file -e $head1 &&
1139 test_must_fail git --work-tree=. cat-file -e $head2
1143 test_expect_success
'fetch --all with --recurse-submodules' '
1144 test_when_finished "rm -fr src_clone" &&
1145 git clone --recurse-submodules src src_clone &&
1148 git config submodule.recurse true &&
1149 git config fetch.parallel 0 &&
1150 git fetch --all 2>../fetch-log
1152 grep "^Fetching submodule sub$" fetch-log >fetch-subs &&
1153 test_line_count = 1 fetch-subs
1156 test_expect_success
'fetch --all with --recurse-submodules with multiple' '
1157 test_when_finished "rm -fr src_clone" &&
1158 git clone --recurse-submodules src src_clone &&
1161 git remote add secondary ../src &&
1162 git config submodule.recurse true &&
1163 git config fetch.parallel 0 &&
1164 git fetch --all 2>../fetch-log
1166 grep "Fetching submodule sub" fetch-log >fetch-subs &&
1167 test_line_count = 2 fetch-subs