3 # Copyright (c) 2009 Red Hat, Inc.
6 test_description
='Test updating submodules
8 This test verifies that "git submodule update" detaches the HEAD of the
9 submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
12 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
13 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
15 TEST_PASSES_SANITIZE_LEAK
=true
21 sha_main
=$
(git rev-list
--max-count=1 main
)
22 sha_head
=$
(git rev-list
--max-count=1 HEAD
)
24 test "$sha_main" = "$sha_head"
28 test_expect_success
'setup a submodule tree' '
29 git config --global protocol.file.allow always &&
33 git commit -m upstream &&
35 git clone super submodule &&
36 git clone super rebasing &&
37 git clone super merging &&
38 git clone super none &&
40 git submodule add ../submodule submodule &&
42 git commit -m "submodule" &&
43 git submodule init submodule
46 echo "line2" > file &&
48 git commit -m "Commit 2"
52 git pull --rebase origin
55 git commit -m "submodule update"
58 git submodule add ../rebasing rebasing &&
60 git commit -m "rebasing"
63 git submodule add ../merging merging &&
65 git commit -m "rebasing"
68 git submodule add ../none none &&
72 git clone . recursivesuper &&
73 ( cd recursivesuper &&
74 git submodule add ../super super
78 test_expect_success
'update --remote falls back to using HEAD' '
79 test_create_repo main-branch-submodule &&
80 test_commit -C main-branch-submodule initial &&
82 test_create_repo main-branch &&
83 git -C main-branch submodule add ../main-branch-submodule &&
84 git -C main-branch commit -m add-submodule &&
86 git -C main-branch-submodule switch -c hello &&
87 test_commit -C main-branch-submodule world &&
89 git clone --recursive main-branch main-branch-clone &&
90 git -C main-branch-clone submodule update --remote main-branch-submodule &&
91 test_path_exists main-branch-clone/main-branch-submodule/world.t
94 test_expect_success
'submodule update detaching the HEAD ' '
95 (cd super/submodule &&
96 git reset --hard HEAD~1
102 git submodule update submodule &&
108 test_expect_success
'submodule update from subdirectory' '
109 (cd super/submodule &&
110 git reset --hard HEAD~1
117 git submodule update ../submodule &&
123 supersha1
=$
(git
-C super rev-parse HEAD
)
124 mergingsha1
=$
(git
-C super
/merging rev-parse HEAD
)
125 nonesha1
=$
(git
-C super
/none rev-parse HEAD
)
126 rebasingsha1
=$
(git
-C super
/rebasing rev-parse HEAD
)
127 submodulesha1
=$
(git
-C super
/submodule rev-parse HEAD
)
131 Submodule path '../super': checked out '$supersha1'
132 Submodule path '../super/merging': checked out '$mergingsha1'
133 Submodule path '../super/none': checked out '$nonesha1'
134 Submodule path '../super/rebasing': checked out '$rebasingsha1'
135 Submodule path '../super/submodule': checked out '$submodulesha1'
139 Cloning into '$pwd/recursivesuper/super/merging'...
140 Cloning into '$pwd/recursivesuper/super/none'...
141 Cloning into '$pwd/recursivesuper/super/rebasing'...
142 Cloning into '$pwd/recursivesuper/super/submodule'...
143 Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
144 Submodule 'none' ($pwd/none) registered for path '../super/none'
145 Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
146 Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
153 test_expect_success
'submodule update --init --recursive from subdirectory' '
154 git -C recursivesuper/super reset --hard HEAD^ &&
155 (cd recursivesuper &&
158 git submodule update --init --recursive ../super >../../actual 2>../../actual2
160 test_cmp expect actual &&
161 sort actual2 >actual2.sorted &&
162 test_cmp expect2 actual2.sorted
166 Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
169 test_expect_success
'submodule update --init from and of subdirectory' '
173 git submodule add "$(pwd)/../rebasing" foo/sub &&
175 git submodule deinit -f sub &&
176 git submodule update --init sub 2>../../actual2
179 test_cmp expect2 actual2
182 test_expect_success
'submodule update does not fetch already present commits' '
184 echo line3 >> file &&
187 git commit -m "upstream line3"
189 (cd super/submodule &&
190 head=$(git rev-parse --verify HEAD) &&
191 echo "Submodule path ${SQ}submodule$SQ: checked out $SQ$head$SQ" > ../../expected &&
192 git reset --hard HEAD~1
195 git submodule update > ../actual 2> ../actual.err
197 test_cmp expected actual &&
198 test_must_be_empty actual.err
201 test_expect_success
'submodule update should fail due to local changes' '
202 (cd super/submodule &&
203 git reset --hard HEAD~1 &&
204 echo "local change" > file
210 test_must_fail git submodule update submodule 2>../actual.raw
212 sed "s/^> //" >expect <<-\EOF &&
213 > error: Your local changes to the following files would be overwritten by checkout:
215 > Please commit your changes or stash them before you switch branches.
217 > fatal: Unable to checkout OID in submodule path '\''submodule'\''
219 sed -e "s/checkout $SQ[^$SQ]*$SQ/checkout OID/" <actual.raw >actual &&
220 test_cmp expect actual
223 test_expect_success
'submodule update should throw away changes with --force ' '
228 git submodule update --force submodule &&
234 test_expect_success
'submodule update --force forcibly checks out submodules' '
239 git submodule update --force submodule &&
241 test "$(git status -s file)" = ""
246 test_expect_success
'submodule update --remote should fetch upstream changes' '
248 echo line4 >> file &&
251 git commit -m "upstream line4"
254 git submodule update --remote --force submodule &&
256 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
260 test_expect_success
'submodule update --remote should fetch upstream changes with .' '
263 git config -f .gitmodules submodule."submodule".branch "." &&
264 git add .gitmodules &&
265 git commit -m "submodules: update from the respective superproject branch"
269 echo line4a >> file &&
272 git commit -m "upstream line4a" &&
273 git checkout -b test-branch &&
274 test_commit on-test-branch
278 git submodule update --remote --force submodule &&
279 git -C submodule log -1 --oneline >actual &&
280 git -C ../submodule log -1 --oneline main >expect &&
281 test_cmp expect actual &&
282 git checkout -b test-branch &&
283 git submodule update --remote --force submodule &&
284 git -C submodule log -1 --oneline >actual &&
285 git -C ../submodule log -1 --oneline test-branch >expect &&
286 test_cmp expect actual &&
288 git branch -d test-branch &&
289 git reset --hard HEAD^
293 test_expect_success
'local config should override .gitmodules branch' '
295 git checkout test-branch &&
296 echo line5 >> file &&
299 git commit -m "upstream line5" &&
303 git config submodule.submodule.branch test-branch &&
304 git submodule update --remote --force submodule &&
306 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
310 test_expect_success
'submodule update --rebase staying on main' '
311 (cd super/submodule &&
318 git submodule update --rebase submodule &&
324 test_expect_success
'submodule update --merge staying on main' '
325 (cd super/submodule &&
326 git reset --hard HEAD~1
332 git submodule update --merge submodule &&
338 test_expect_success
'submodule update - rebase in .git/config' '
340 git config submodule.submodule.update rebase
342 (cd super/submodule &&
343 git reset --hard HEAD~1
349 git submodule update submodule &&
355 test_expect_success
'submodule update - checkout in .git/config but --rebase given' '
357 git config submodule.submodule.update checkout
359 (cd super/submodule &&
360 git reset --hard HEAD~1
366 git submodule update --rebase submodule &&
372 test_expect_success
'submodule update - merge in .git/config' '
374 git config submodule.submodule.update merge
376 (cd super/submodule &&
377 git reset --hard HEAD~1
383 git submodule update submodule &&
389 test_expect_success
'submodule update - checkout in .git/config but --merge given' '
391 git config submodule.submodule.update checkout
393 (cd super/submodule &&
394 git reset --hard HEAD~1
400 git submodule update --merge submodule &&
406 test_expect_success
'submodule update - checkout in .git/config' '
408 git config submodule.submodule.update checkout
410 (cd super/submodule &&
411 git reset --hard HEAD^
417 git submodule update submodule &&
423 test_expect_success
'submodule update - command in .git/config' '
425 git config submodule.submodule.update "!git checkout"
427 (cd super/submodule &&
428 git reset --hard HEAD^
434 git submodule update submodule &&
440 test_expect_success
'submodule update - command in .gitmodules is rejected' '
441 test_when_finished "git -C super reset --hard HEAD^" &&
442 git -C super config -f .gitmodules submodule.submodule.update "!false" &&
443 git -C super commit -a -m "add command to .gitmodules file" &&
444 git -C super/submodule reset --hard $submodulesha1^ &&
445 test_must_fail git -C super submodule update submodule
448 test_expect_success
'fsck detects command in .gitmodules' '
449 git init command-in-gitmodules &&
451 cd command-in-gitmodules &&
452 git submodule add ../submodule submodule &&
453 test_commit adding-submodule &&
455 git config -f .gitmodules submodule.submodule.update "!false" &&
456 git add .gitmodules &&
457 test_commit configuring-update &&
458 test_must_fail git fsck
463 fatal: Execution of 'false $submodulesha1' failed in submodule path 'submodule'
466 test_expect_success
'submodule update - command in .git/config catches failure' '
468 git config submodule.submodule.update "!false"
470 (cd super/submodule &&
471 git reset --hard $submodulesha1^
474 test_must_fail git submodule update submodule 2>../actual
476 test_cmp actual expect
480 fatal: Execution of 'false $submodulesha1' failed in submodule path '../submodule'
483 test_expect_success
'submodule update - command in .git/config catches failure -- subdirectory' '
485 git config submodule.submodule.update "!false"
487 (cd super/submodule &&
488 git reset --hard $submodulesha1^
491 mkdir tmp && cd tmp &&
492 test_must_fail git submodule update ../submodule 2>../../actual
494 test_cmp actual expect
497 test_expect_success
'submodule update - command run for initial population of submodule' '
498 cat >expect <<-EOF &&
499 fatal: Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
501 rm -rf super/submodule &&
502 test_must_fail git -C super submodule update 2>actual &&
503 test_cmp expect actual &&
504 git -C super submodule update --checkout
508 fatal: Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
509 fatal: Failed to recurse into submodule path '../super'
512 test_expect_success
'recursive submodule update - command in .git/config catches failure -- subdirectory' '
513 (cd recursivesuper &&
514 git submodule update --remote super &&
516 git commit -m "update to latest to have more than one commit in submodules"
518 git -C recursivesuper/super config submodule.submodule.update "!false" &&
519 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
520 (cd recursivesuper &&
521 mkdir -p tmp && cd tmp &&
522 test_must_fail git submodule update --recursive ../super 2>../../actual
524 test_cmp actual expect
527 test_expect_success
'submodule init does not copy command into .git/config' '
528 test_when_finished "git -C super update-index --force-remove submodule1" &&
529 test_when_finished git config -f super/.gitmodules \
530 --remove-section submodule.submodule1 &&
532 git ls-files -s submodule >out &&
533 H=$(cut -d" " -f2 out) &&
535 git update-index --add --cacheinfo 160000 $H submodule1 &&
536 git config -f .gitmodules submodule.submodule1.path submodule1 &&
537 git config -f .gitmodules submodule.submodule1.url ../submodule &&
538 git config -f .gitmodules submodule.submodule1.update !false &&
539 test_must_fail git submodule init submodule1 &&
540 test_expect_code 1 git config submodule.submodule1.update >actual &&
541 test_must_be_empty actual
545 test_expect_success
'submodule init picks up rebase' '
547 git config -f .gitmodules submodule.rebasing.update rebase &&
548 git submodule init rebasing &&
549 test "rebase" = "$(git config submodule.rebasing.update)"
553 test_expect_success
'submodule init picks up merge' '
555 git config -f .gitmodules submodule.merging.update merge &&
556 git submodule init merging &&
557 test "merge" = "$(git config submodule.merging.update)"
561 test_expect_success
'submodule update --merge - ignores --merge for new submodules' '
562 test_config -C super submodule.submodule.update checkout &&
565 git submodule update submodule &&
566 git status -s submodule >expect &&
568 git submodule update --merge submodule &&
569 git status -s submodule >actual &&
570 test_cmp expect actual
574 test_expect_success
'submodule update --rebase - ignores --rebase for new submodules' '
575 test_config -C super submodule.submodule.update checkout &&
578 git submodule update submodule &&
579 git status -s submodule >expect &&
581 git submodule update --rebase submodule &&
582 git status -s submodule >actual &&
583 test_cmp expect actual
587 test_expect_success
'submodule update ignores update=merge config for new submodules' '
590 git submodule update submodule &&
591 git status -s submodule >expect &&
593 git config submodule.submodule.update merge &&
594 git submodule update submodule &&
595 git status -s submodule >actual &&
596 git config --unset submodule.submodule.update &&
597 test_cmp expect actual
601 test_expect_success
'submodule update ignores update=rebase config for new submodules' '
604 git submodule update submodule &&
605 git status -s submodule >expect &&
607 git config submodule.submodule.update rebase &&
608 git submodule update submodule &&
609 git status -s submodule >actual &&
610 git config --unset submodule.submodule.update &&
611 test_cmp expect actual
615 test_expect_success
'submodule init picks up update=none' '
617 git config -f .gitmodules submodule.none.update none &&
618 git submodule init none &&
619 test "none" = "$(git config submodule.none.update)"
623 test_expect_success
'submodule update - update=none in .git/config' '
625 git config submodule.submodule.update none &&
630 git diff --name-only >out &&
631 grep ^submodule$ out &&
632 git submodule update &&
633 git diff --name-only >out &&
634 grep ^submodule$ out &&
638 git config --unset submodule.submodule.update &&
639 git submodule update submodule
643 test_expect_success
'submodule update - update=none in .git/config but --checkout given' '
645 git config submodule.submodule.update none &&
650 git diff --name-only >out &&
651 grep ^submodule$ out &&
652 git submodule update --checkout &&
653 git diff --name-only >out &&
654 ! grep ^submodule$ out &&
658 git config --unset submodule.submodule.update
662 test_expect_success
'submodule update --init skips submodule with update=none' '
664 git add .gitmodules &&
665 git commit -m ".gitmodules"
667 git clone super cloned &&
669 git submodule update --init &&
670 test_path_exists submodule/.git &&
671 test_path_is_missing none/.git
675 test_expect_success
'submodule update with pathspec warns against uninitialized ones' '
676 test_when_finished "rm -fr selective" &&
677 git clone super selective &&
680 git submodule init submodule &&
682 git submodule update submodule 2>err &&
683 ! grep "Submodule path .* not initialized" err &&
685 git submodule update rebasing 2>err &&
686 grep "Submodule path .rebasing. not initialized" err &&
688 test_path_exists submodule/.git &&
689 test_path_is_missing rebasing/.git
694 test_expect_success
'submodule update without pathspec updates only initialized ones' '
695 test_when_finished "rm -fr selective" &&
696 git clone super selective &&
699 git submodule init submodule &&
700 git submodule update 2>err &&
701 test_path_exists submodule/.git &&
702 test_path_is_missing rebasing/.git &&
703 ! grep "Submodule path .* not initialized" err
708 test_expect_success
'submodule update continues after checkout error' '
710 git reset --hard HEAD &&
711 git submodule add ../submodule submodule2 &&
712 git submodule init &&
713 git commit -am "new_submodule" &&
715 git rev-parse --verify HEAD >../expect
718 test_commit "update_submodule" file
721 test_commit "update_submodule2" file
724 git add submodule2 &&
725 git commit -m "two_new_submodule_commits" &&
729 git checkout HEAD^ &&
730 test_must_fail git submodule update &&
732 git rev-parse --verify HEAD >../actual
734 test_cmp expect actual
737 test_expect_success
'submodule update continues after recursive checkout error' '
739 git reset --hard HEAD &&
741 git submodule update &&
743 git submodule add ../submodule subsubmodule &&
744 git submodule init &&
745 git commit -m "new_subsubmodule"
748 git commit -m "update_submodule" &&
751 test_commit "update_subsubmodule" file
753 git add subsubmodule &&
754 test_commit "update_submodule_again" file &&
756 test_commit "update_subsubmodule_again" file
758 test_commit "update_submodule_again_again" file
761 git rev-parse --verify HEAD >../expect &&
762 test_commit "update_submodule2_again" file
765 git add submodule2 &&
766 git commit -m "new_commits" &&
767 git checkout HEAD^ &&
769 git checkout HEAD^ &&
774 test_expect_code 1 git submodule update --recursive &&
776 git rev-parse --verify HEAD >../actual
778 test_cmp expect actual
782 test_expect_success
'submodule update exit immediately in case of merge conflict' '
785 git reset --hard HEAD &&
788 git reset --hard HEAD
791 git submodule update --recursive &&
793 test_commit "update_submodule_2" file
796 test_commit "update_submodule2_2" file
799 git add submodule2 &&
800 git commit -m "two_new_submodule_commits" &&
803 test_commit "conflict" file &&
804 echo "conflict" > file
806 git checkout HEAD^ &&
808 git rev-parse --verify HEAD >../expect
810 git config submodule.submodule.update merge &&
811 test_must_fail git submodule update &&
813 git rev-parse --verify HEAD >../actual
815 test_cmp expect actual
819 test_expect_success
'submodule update exit immediately after recursive rebase error' '
822 git reset --hard HEAD &&
824 git reset --hard HEAD &&
825 git submodule update --recursive
828 test_commit "update_submodule_3" file
831 test_commit "update_submodule2_3" file
834 git add submodule2 &&
835 git commit -m "two_new_submodule_commits" &&
838 test_commit "conflict2" file &&
839 echo "conflict" > file
841 git checkout HEAD^ &&
843 git rev-parse --verify HEAD >../expect
845 git config submodule.submodule.update rebase &&
846 test_must_fail git submodule update &&
848 git rev-parse --verify HEAD >../actual
850 test_cmp expect actual
854 test_expect_success
'add different submodules to the same path' '
856 git submodule add ../submodule s1 &&
857 test_must_fail git submodule add ../merging s1
861 test_expect_success
'submodule add places git-dir in superprojects git-dir' '
864 git submodule add ../submodule deeper/submodule &&
865 (cd deeper/submodule &&
866 git log > ../../expected
868 (cd .git/modules/deeper/submodule &&
869 git log > ../../../../actual
871 test_cmp expected actual
875 test_expect_success
'submodule update places git-dir in superprojects git-dir' '
877 git commit -m "added submodule"
879 git clone super super2 &&
881 git submodule init deeper/submodule &&
882 git submodule update &&
883 (cd deeper/submodule &&
884 git log > ../../expected
886 (cd .git/modules/deeper/submodule &&
887 git log > ../../../../actual
889 test_cmp expected actual
893 test_expect_success
'submodule add places git-dir in superprojects git-dir recursive' '
895 (cd deeper/submodule &&
896 git submodule add ../submodule subsubmodule &&
898 git log > ../../../expected
900 git commit -m "added subsubmodule" &&
903 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
904 git log > ../../../../../actual
906 git add deeper/submodule &&
907 git commit -m "update submodule" &&
909 test_cmp expected actual
913 test_expect_success
'submodule update places git-dir in superprojects git-dir recursive' '
914 mkdir super_update_r &&
915 (cd super_update_r &&
918 mkdir subsuper_update_r &&
919 (cd subsuper_update_r &&
922 mkdir subsubsuper_update_r &&
923 (cd subsubsuper_update_r &&
926 git clone subsubsuper_update_r subsubsuper_update_r2 &&
927 (cd subsubsuper_update_r2 &&
928 test_commit "update_subsubsuper" file &&
931 git clone subsuper_update_r subsuper_update_r2 &&
932 (cd subsuper_update_r2 &&
933 test_commit "update_subsuper" file &&
934 git submodule add ../subsubsuper_update_r subsubmodule &&
935 git commit -am "subsubmodule" &&
938 git clone super_update_r super_update_r2 &&
939 (cd super_update_r2 &&
940 test_commit "update_super" file &&
941 git submodule add ../subsuper_update_r submodule &&
942 git commit -am "submodule" &&
945 rm -rf super_update_r2 &&
946 git clone super_update_r super_update_r2 &&
947 (cd super_update_r2 &&
948 git submodule update --init --recursive >actual &&
949 test_grep "Submodule path .submodule/subsubmodule.: checked out" actual &&
950 (cd submodule/subsubmodule &&
951 git log > ../../expected
953 (cd .git/modules/submodule/modules/subsubmodule &&
954 git log > ../../../../../actual
956 test_cmp expected actual
960 test_expect_success
'submodule add properly re-creates deeper level submodules' '
962 git reset --hard main &&
964 git submodule add --force ../submodule deeper/submodule
968 test_expect_success
'submodule update properly revives a moved submodule' '
970 H=$(git rev-parse --short HEAD) &&
971 git commit -am "pre move" &&
972 H2=$(git rev-parse --short HEAD) &&
974 sed "s/$H/XXX/" out >expect &&
975 H=$(cd submodule2 && git rev-parse HEAD) &&
976 git rm --cached submodule2 &&
978 mkdir -p "moved/sub module" &&
979 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
980 git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
981 git commit -am "post move" &&
982 git submodule update &&
984 sed "s/$H2/XXX/" out >actual &&
985 test_cmp expect actual
989 test_expect_success SYMLINKS
'submodule update can handle symbolic links in pwd' '
990 mkdir -p linked/dir &&
991 ln -s linked/dir linkto &&
993 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
995 git submodule update --init --recursive
1000 test_expect_success
'submodule update clone shallow submodule' '
1001 test_when_finished "rm -rf super3" &&
1002 first=$(git -C cloned rev-parse HEAD:submodule) &&
1003 second=$(git -C submodule rev-parse HEAD) &&
1004 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
1005 git clone cloned super3 &&
1009 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
1010 mv -f .gitmodules.tmp .gitmodules &&
1011 git submodule update --init --depth=$commit_count &&
1012 git -C submodule log --oneline >out &&
1013 test_line_count = 1 out
1017 test_expect_success
'submodule update clone shallow submodule outside of depth' '
1018 test_when_finished "rm -rf super3" &&
1019 git clone cloned super3 &&
1023 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
1024 mv -f .gitmodules.tmp .gitmodules &&
1025 # Some protocol versions (e.g. 2) support fetching
1026 # unadvertised objects, so restrict this test to v0.
1027 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1028 git submodule update --init --depth=1 2>actual &&
1029 test_grep "Direct fetching of that commit failed." actual &&
1030 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
1031 git submodule update --init --depth=1 >actual &&
1032 git -C submodule log --oneline >out &&
1033 test_line_count = 1 out
1037 test_expect_success
'submodule update --recursive drops module name before recursing' '
1039 (cd deeper/submodule/subsubmodule &&
1042 git submodule update --recursive deeper/submodule >actual &&
1043 test_grep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
1047 test_expect_success
'submodule update can be run in parallel' '
1049 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
1050 grep "7 tasks" trace.out &&
1051 git config submodule.fetchJobs 8 &&
1052 GIT_TRACE=$(pwd)/trace.out git submodule update &&
1053 grep "8 tasks" trace.out &&
1054 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
1055 grep "9 tasks" trace.out
1059 test_expect_success
'git clone passes the parallel jobs config on to submodules' '
1060 test_when_finished "rm -rf super4" &&
1061 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
1062 grep "7 tasks" trace.out &&
1064 git config --global submodule.fetchJobs 8 &&
1065 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
1066 grep "8 tasks" trace.out &&
1068 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
1069 grep "9 tasks" trace.out &&
1073 test_expect_success
'submodule update --quiet passes quietness to merge/rebase' '
1075 test_commit -C rebasing message &&
1076 git submodule update --rebase --quiet >out 2>err &&
1077 test_must_be_empty out &&
1078 test_must_be_empty err &&
1079 git submodule update --rebase >out 2>err &&
1080 test_file_not_empty out &&
1081 test_must_be_empty err
1085 test_expect_success
'submodule update --quiet passes quietness to fetch with a shallow clone' '
1086 test_when_finished "rm -rf super4 super5 super6" &&
1087 git clone . super4 &&
1089 git submodule add --quiet file://"$TRASH_DIRECTORY"/submodule submodule3 &&
1090 git commit -am "setup submodule3"
1093 test_commit line6 file
1095 git clone super4 super5 &&
1097 git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
1098 test_must_be_empty out &&
1099 test_must_be_empty err
1101 git clone super4 super6 &&
1103 git submodule update --init --depth=1 submodule3 >out 2>err &&
1104 test_file_not_empty out &&
1105 test_file_not_empty err
1109 test_expect_success
'submodule update --filter requires --init' '
1110 test_expect_code 129 git -C super submodule update --filter blob:none
1113 test_expect_success
'submodule update --filter sets partial clone settings' '
1114 test_when_finished "rm -rf super-filter" &&
1115 git clone cloned super-filter &&
1116 git -C super-filter submodule update --init --filter blob:none &&
1117 test_cmp_config -C super-filter/submodule true remote.origin.promisor &&
1118 test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter
1121 # NEEDSWORK: Clean up the tests so that we can reuse the test setup.
1122 # Don't reuse the existing repos because the earlier tests have
1123 # intentionally disruptive configurations.
1124 test_expect_success
'setup clean recursive superproject' '
1126 test_commit -C bottom "bottom" &&
1128 git -C middle submodule add ../bottom bottom &&
1129 git -C middle commit -m "middle" &&
1131 git -C top submodule add ../middle middle &&
1132 git -C top commit -m "top" &&
1133 git clone --recurse-submodules top top-clean
1136 test_expect_success
'submodule update should skip unmerged submodules' '
1137 test_when_finished "rm -fr top-cloned" &&
1138 cp -r top-clean top-cloned &&
1140 # Create an upstream commit in each repo, starting with bottom
1141 test_commit -C bottom upstream_commit &&
1142 # Create middle commit
1143 git -C middle/bottom fetch &&
1144 git -C middle/bottom checkout -f FETCH_HEAD &&
1145 git -C middle add bottom &&
1146 git -C middle commit -m "upstream_commit" &&
1148 git -C top/middle fetch &&
1149 git -C top/middle checkout -f FETCH_HEAD &&
1150 git -C top add middle &&
1151 git -C top commit -m "upstream_commit" &&
1153 # Create a downstream conflict
1154 test_commit -C top-cloned/middle/bottom downstream_commit &&
1155 git -C top-cloned/middle add bottom &&
1156 git -C top-cloned/middle commit -m "downstream_commit" &&
1157 git -C top-cloned/middle fetch --recurse-submodules origin &&
1158 test_must_fail git -C top-cloned/middle merge origin/main &&
1160 # Make the update of "middle" a no-op, otherwise we error out
1161 # because of its unmerged state
1162 test_config -C top-cloned submodule.middle.update !true &&
1163 git -C top-cloned submodule update --recursive 2>actual.err &&
1164 cat >expect.err <<-\EOF &&
1165 Skipping unmerged submodule middle/bottom
1167 test_cmp expect.err actual.err
1170 test_expect_success
'submodule update --recursive skip submodules with strategy=none' '
1171 test_when_finished "rm -fr top-cloned" &&
1172 cp -r top-clean top-cloned &&
1174 test_commit -C top-cloned/middle/bottom downstream_commit &&
1175 git -C top-cloned/middle config submodule.bottom.update none &&
1176 git -C top-cloned submodule update --recursive 2>actual.err &&
1177 cat >expect.err <<-\EOF &&
1178 Skipping submodule '\''middle/bottom'\''
1180 test_cmp expect.err actual.err
1183 add_submodule_commit_and_validate
() {
1184 HASH
=$
(git rev-parse HEAD
) &&
1185 git update-index
--add --cacheinfo 160000,$HASH,sub
&&
1186 git commit
-m "create submodule" &&
1187 echo "160000 commit $HASH sub" >expect
&&
1188 git ls-tree HEAD
-- sub
>actual
&&
1189 test_cmp expect actual
1192 test_expect_success
'commit with staged submodule change' '
1193 add_submodule_commit_and_validate
1196 test_expect_success
'commit with staged submodule change with ignoreSubmodules dirty' '
1197 test_config diff.ignoreSubmodules dirty &&
1198 add_submodule_commit_and_validate
1201 test_expect_success
'commit with staged submodule change with ignoreSubmodules all' '
1202 test_config diff.ignoreSubmodules all &&
1203 add_submodule_commit_and_validate
1206 test_expect_success CASE_INSENSITIVE_FS
,SYMLINKS \
1207 'submodule paths must not follow symlinks' '
1209 # This is only needed because we want to run this in a self-contained
1210 # test without having to spin up an HTTP server; However, it would not
1211 # be needed in a real-world scenario where the submodule is simply
1212 # hosted on a public site.
1213 test_config_global protocol.file.allow always &&
1215 # Make sure that Git tries to use symlinks on Windows
1216 test_config_global core.symlinks true &&
1218 tell_tale_path="$PWD/tell.tale" &&
1223 write_script y/hooks/post-checkout <<-EOF &&
1225 echo hook-run >"$tell_tale_path"
1227 git add y/hooks/post-checkout &&
1229 git commit -m post-checkout
1232 hook_repo_path="$(pwd)/hook" &&
1236 git submodule add --name x/y "$hook_repo_path" A/modules/x &&
1238 git commit -m add-submodule &&
1240 printf .git >dotgit.txt &&
1241 git hash-object -w --stdin <dotgit.txt >dot-git.hash &&
1242 printf "120000 %s 0\ta\n" "$(cat dot-git.hash)" >index.info &&
1243 git update-index --index-info <index.info &&
1245 git commit -m add-symlink
1248 test_path_is_missing "$tell_tale_path" &&
1249 git clone --recursive captain hooked 2>err &&
1250 test_grep ! HOOK-RUN err &&
1251 test_path_is_missing "$tell_tale_path"