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
20 sha_main
=$
(git rev-list
--max-count=1 main
)
21 sha_head
=$
(git rev-list
--max-count=1 HEAD
)
23 test "$sha_main" = "$sha_head"
27 test_expect_success
'setup a submodule tree' '
28 git config --global protocol.file.allow always &&
32 git commit -m upstream &&
34 git clone super submodule &&
35 git clone super rebasing &&
36 git clone super merging &&
37 git clone super none &&
39 git submodule add ../submodule submodule &&
41 git commit -m "submodule" &&
42 git submodule init submodule
45 echo "line2" > file &&
47 git commit -m "Commit 2"
51 git pull --rebase origin
54 git commit -m "submodule update"
57 git submodule add ../rebasing rebasing &&
59 git commit -m "rebasing"
62 git submodule add ../merging merging &&
64 git commit -m "rebasing"
67 git submodule add ../none none &&
71 git clone . recursivesuper &&
72 ( cd recursivesuper &&
73 git submodule add ../super super
77 test_expect_success
'update --remote falls back to using HEAD' '
78 test_create_repo main-branch-submodule &&
79 test_commit -C main-branch-submodule initial &&
81 test_create_repo main-branch &&
82 git -C main-branch submodule add ../main-branch-submodule &&
83 git -C main-branch commit -m add-submodule &&
85 git -C main-branch-submodule switch -c hello &&
86 test_commit -C main-branch-submodule world &&
88 git clone --recursive main-branch main-branch-clone &&
89 git -C main-branch-clone submodule update --remote main-branch-submodule &&
90 test_path_exists main-branch-clone/main-branch-submodule/world.t
93 test_expect_success
'submodule update detaching the HEAD ' '
94 (cd super/submodule &&
95 git reset --hard HEAD~1
101 git submodule update submodule &&
107 test_expect_success
'submodule update from subdirectory' '
108 (cd super/submodule &&
109 git reset --hard HEAD~1
116 git submodule update ../submodule &&
122 supersha1
=$
(git
-C super rev-parse HEAD
)
123 mergingsha1
=$
(git
-C super
/merging rev-parse HEAD
)
124 nonesha1
=$
(git
-C super
/none rev-parse HEAD
)
125 rebasingsha1
=$
(git
-C super
/rebasing rev-parse HEAD
)
126 submodulesha1
=$
(git
-C super
/submodule rev-parse HEAD
)
130 Submodule path '../super': checked out '$supersha1'
131 Submodule path '../super/merging': checked out '$mergingsha1'
132 Submodule path '../super/none': checked out '$nonesha1'
133 Submodule path '../super/rebasing': checked out '$rebasingsha1'
134 Submodule path '../super/submodule': checked out '$submodulesha1'
138 Cloning into '$pwd/recursivesuper/super/merging'...
139 Cloning into '$pwd/recursivesuper/super/none'...
140 Cloning into '$pwd/recursivesuper/super/rebasing'...
141 Cloning into '$pwd/recursivesuper/super/submodule'...
142 Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
143 Submodule 'none' ($pwd/none) registered for path '../super/none'
144 Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
145 Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
152 test_expect_success
'submodule update --init --recursive from subdirectory' '
153 git -C recursivesuper/super reset --hard HEAD^ &&
154 (cd recursivesuper &&
157 git submodule update --init --recursive ../super >../../actual 2>../../actual2
159 test_cmp expect actual &&
160 sort actual2 >actual2.sorted &&
161 test_cmp expect2 actual2.sorted
165 Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
168 test_expect_success
'submodule update --init from and of subdirectory' '
172 git submodule add "$(pwd)/../rebasing" foo/sub &&
174 git submodule deinit -f sub &&
175 git submodule update --init sub 2>../../actual2
178 test_cmp expect2 actual2
181 test_expect_success
'submodule update does not fetch already present commits' '
183 echo line3 >> file &&
186 git commit -m "upstream line3"
188 (cd super/submodule &&
189 head=$(git rev-parse --verify HEAD) &&
190 echo "Submodule path ${SQ}submodule$SQ: checked out $SQ$head$SQ" > ../../expected &&
191 git reset --hard HEAD~1
194 git submodule update > ../actual 2> ../actual.err
196 test_cmp expected actual &&
197 test_must_be_empty actual.err
200 test_expect_success
'submodule update should fail due to local changes' '
201 (cd super/submodule &&
202 git reset --hard HEAD~1 &&
203 echo "local change" > file
209 test_must_fail git submodule update submodule 2>../actual.raw
211 sed "s/^> //" >expect <<-\EOF &&
212 > error: Your local changes to the following files would be overwritten by checkout:
214 > Please commit your changes or stash them before you switch branches.
216 > fatal: Unable to checkout OID in submodule path '\''submodule'\''
218 sed -e "s/checkout $SQ[^$SQ]*$SQ/checkout OID/" <actual.raw >actual &&
219 test_cmp expect actual
222 test_expect_success
'submodule update should throw away changes with --force ' '
227 git submodule update --force submodule &&
233 test_expect_success
'submodule update --force forcibly checks out submodules' '
238 git submodule update --force submodule &&
240 test "$(git status -s file)" = ""
245 test_expect_success
'submodule update --remote should fetch upstream changes' '
247 echo line4 >> file &&
250 git commit -m "upstream line4"
253 git submodule update --remote --force submodule &&
255 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
259 test_expect_success
'submodule update --remote should fetch upstream changes with .' '
262 git config -f .gitmodules submodule."submodule".branch "." &&
263 git add .gitmodules &&
264 git commit -m "submodules: update from the respective superproject branch"
268 echo line4a >> file &&
271 git commit -m "upstream line4a" &&
272 git checkout -b test-branch &&
273 test_commit on-test-branch
277 git submodule update --remote --force submodule &&
278 git -C submodule log -1 --oneline >actual &&
279 git -C ../submodule log -1 --oneline main >expect &&
280 test_cmp expect actual &&
281 git checkout -b test-branch &&
282 git submodule update --remote --force submodule &&
283 git -C submodule log -1 --oneline >actual &&
284 git -C ../submodule log -1 --oneline test-branch >expect &&
285 test_cmp expect actual &&
287 git branch -d test-branch &&
288 git reset --hard HEAD^
292 test_expect_success
'local config should override .gitmodules branch' '
294 git checkout test-branch &&
295 echo line5 >> file &&
298 git commit -m "upstream line5" &&
302 git config submodule.submodule.branch test-branch &&
303 git submodule update --remote --force submodule &&
305 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
309 test_expect_success
'submodule update --rebase staying on main' '
310 (cd super/submodule &&
317 git submodule update --rebase submodule &&
323 test_expect_success
'submodule update --merge staying on main' '
324 (cd super/submodule &&
325 git reset --hard HEAD~1
331 git submodule update --merge submodule &&
337 test_expect_success
'submodule update - rebase in .git/config' '
339 git config submodule.submodule.update rebase
341 (cd super/submodule &&
342 git reset --hard HEAD~1
348 git submodule update submodule &&
354 test_expect_success
'submodule update - checkout in .git/config but --rebase given' '
356 git config submodule.submodule.update checkout
358 (cd super/submodule &&
359 git reset --hard HEAD~1
365 git submodule update --rebase submodule &&
371 test_expect_success
'submodule update - merge in .git/config' '
373 git config submodule.submodule.update merge
375 (cd super/submodule &&
376 git reset --hard HEAD~1
382 git submodule update submodule &&
388 test_expect_success
'submodule update - checkout in .git/config but --merge given' '
390 git config submodule.submodule.update checkout
392 (cd super/submodule &&
393 git reset --hard HEAD~1
399 git submodule update --merge submodule &&
405 test_expect_success
'submodule update - checkout in .git/config' '
407 git config submodule.submodule.update checkout
409 (cd super/submodule &&
410 git reset --hard HEAD^
416 git submodule update submodule &&
422 test_expect_success
'submodule update - command in .git/config' '
424 git config submodule.submodule.update "!git checkout"
426 (cd super/submodule &&
427 git reset --hard HEAD^
433 git submodule update submodule &&
439 test_expect_success
'submodule update - command in .gitmodules is rejected' '
440 test_when_finished "git -C super reset --hard HEAD^" &&
441 git -C super config -f .gitmodules submodule.submodule.update "!false" &&
442 git -C super commit -a -m "add command to .gitmodules file" &&
443 git -C super/submodule reset --hard $submodulesha1^ &&
444 test_must_fail git -C super submodule update submodule
447 test_expect_success
'fsck detects command in .gitmodules' '
448 git init command-in-gitmodules &&
450 cd command-in-gitmodules &&
451 git submodule add ../submodule submodule &&
452 test_commit adding-submodule &&
454 git config -f .gitmodules submodule.submodule.update "!false" &&
455 git add .gitmodules &&
456 test_commit configuring-update &&
457 test_must_fail git fsck
462 fatal: Execution of 'false $submodulesha1' failed in submodule path 'submodule'
465 test_expect_success
'submodule update - command in .git/config catches failure' '
467 git config submodule.submodule.update "!false"
469 (cd super/submodule &&
470 git reset --hard $submodulesha1^
473 test_must_fail git submodule update submodule 2>../actual
475 test_cmp actual expect
479 fatal: Execution of 'false $submodulesha1' failed in submodule path '../submodule'
482 test_expect_success
'submodule update - command in .git/config catches failure -- subdirectory' '
484 git config submodule.submodule.update "!false"
486 (cd super/submodule &&
487 git reset --hard $submodulesha1^
490 mkdir tmp && cd tmp &&
491 test_must_fail git submodule update ../submodule 2>../../actual
493 test_cmp actual expect
496 test_expect_success
'submodule update - command run for initial population of submodule' '
497 cat >expect <<-EOF &&
498 fatal: Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
500 rm -rf super/submodule &&
501 test_must_fail git -C super submodule update 2>actual &&
502 test_cmp expect actual &&
503 git -C super submodule update --checkout
507 fatal: Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
508 fatal: Failed to recurse into submodule path '../super'
511 test_expect_success
'recursive submodule update - command in .git/config catches failure -- subdirectory' '
512 (cd recursivesuper &&
513 git submodule update --remote super &&
515 git commit -m "update to latest to have more than one commit in submodules"
517 git -C recursivesuper/super config submodule.submodule.update "!false" &&
518 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
519 (cd recursivesuper &&
520 mkdir -p tmp && cd tmp &&
521 test_must_fail git submodule update --recursive ../super 2>../../actual
523 test_cmp actual expect
526 test_expect_success
'submodule init does not copy command into .git/config' '
527 test_when_finished "git -C super update-index --force-remove submodule1" &&
528 test_when_finished git config -f super/.gitmodules \
529 --remove-section submodule.submodule1 &&
531 git ls-files -s submodule >out &&
532 H=$(cut -d" " -f2 out) &&
534 git update-index --add --cacheinfo 160000 $H submodule1 &&
535 git config -f .gitmodules submodule.submodule1.path submodule1 &&
536 git config -f .gitmodules submodule.submodule1.url ../submodule &&
537 git config -f .gitmodules submodule.submodule1.update !false &&
538 test_must_fail git submodule init submodule1 &&
539 test_expect_code 1 git config submodule.submodule1.update >actual &&
540 test_must_be_empty actual
544 test_expect_success
'submodule init picks up rebase' '
546 git config -f .gitmodules submodule.rebasing.update rebase &&
547 git submodule init rebasing &&
548 test "rebase" = "$(git config submodule.rebasing.update)"
552 test_expect_success
'submodule init picks up merge' '
554 git config -f .gitmodules submodule.merging.update merge &&
555 git submodule init merging &&
556 test "merge" = "$(git config submodule.merging.update)"
560 test_expect_success
'submodule update --merge - ignores --merge for new submodules' '
561 test_config -C super submodule.submodule.update checkout &&
564 git submodule update submodule &&
565 git status -s submodule >expect &&
567 git submodule update --merge submodule &&
568 git status -s submodule >actual &&
569 test_cmp expect actual
573 test_expect_success
'submodule update --rebase - ignores --rebase for new submodules' '
574 test_config -C super submodule.submodule.update checkout &&
577 git submodule update submodule &&
578 git status -s submodule >expect &&
580 git submodule update --rebase submodule &&
581 git status -s submodule >actual &&
582 test_cmp expect actual
586 test_expect_success
'submodule update ignores update=merge config for new submodules' '
589 git submodule update submodule &&
590 git status -s submodule >expect &&
592 git config submodule.submodule.update merge &&
593 git submodule update submodule &&
594 git status -s submodule >actual &&
595 git config --unset submodule.submodule.update &&
596 test_cmp expect actual
600 test_expect_success
'submodule update ignores update=rebase config for new submodules' '
603 git submodule update submodule &&
604 git status -s submodule >expect &&
606 git config submodule.submodule.update rebase &&
607 git submodule update submodule &&
608 git status -s submodule >actual &&
609 git config --unset submodule.submodule.update &&
610 test_cmp expect actual
614 test_expect_success
'submodule init picks up update=none' '
616 git config -f .gitmodules submodule.none.update none &&
617 git submodule init none &&
618 test "none" = "$(git config submodule.none.update)"
622 test_expect_success
'submodule update - update=none in .git/config' '
624 git config submodule.submodule.update none &&
629 git diff --name-only >out &&
630 grep ^submodule$ out &&
631 git submodule update &&
632 git diff --name-only >out &&
633 grep ^submodule$ out &&
637 git config --unset submodule.submodule.update &&
638 git submodule update submodule
642 test_expect_success
'submodule update - update=none in .git/config but --checkout given' '
644 git config submodule.submodule.update none &&
649 git diff --name-only >out &&
650 grep ^submodule$ out &&
651 git submodule update --checkout &&
652 git diff --name-only >out &&
653 ! grep ^submodule$ out &&
657 git config --unset submodule.submodule.update
661 test_expect_success
'submodule update --init skips submodule with update=none' '
663 git add .gitmodules &&
664 git commit -m ".gitmodules"
666 git clone super cloned &&
668 git submodule update --init &&
669 test_path_exists submodule/.git &&
670 test_path_is_missing none/.git
674 test_expect_success
'submodule update with pathspec warns against uninitialized ones' '
675 test_when_finished "rm -fr selective" &&
676 git clone super selective &&
679 git submodule init submodule &&
681 git submodule update submodule 2>err &&
682 ! grep "Submodule path .* not initialized" err &&
684 git submodule update rebasing 2>err &&
685 grep "Submodule path .rebasing. not initialized" err &&
687 test_path_exists submodule/.git &&
688 test_path_is_missing rebasing/.git
693 test_expect_success
'submodule update without pathspec updates only initialized ones' '
694 test_when_finished "rm -fr selective" &&
695 git clone super selective &&
698 git submodule init submodule &&
699 git submodule update 2>err &&
700 test_path_exists submodule/.git &&
701 test_path_is_missing rebasing/.git &&
702 ! grep "Submodule path .* not initialized" err
707 test_expect_success
'submodule update continues after checkout error' '
709 git reset --hard HEAD &&
710 git submodule add ../submodule submodule2 &&
711 git submodule init &&
712 git commit -am "new_submodule" &&
714 git rev-parse --verify HEAD >../expect
717 test_commit "update_submodule" file
720 test_commit "update_submodule2" file
723 git add submodule2 &&
724 git commit -m "two_new_submodule_commits" &&
728 git checkout HEAD^ &&
729 test_must_fail git submodule update &&
731 git rev-parse --verify HEAD >../actual
733 test_cmp expect actual
736 test_expect_success
'submodule update continues after recursive checkout error' '
738 git reset --hard HEAD &&
740 git submodule update &&
742 git submodule add ../submodule subsubmodule &&
743 git submodule init &&
744 git commit -m "new_subsubmodule"
747 git commit -m "update_submodule" &&
750 test_commit "update_subsubmodule" file
752 git add subsubmodule &&
753 test_commit "update_submodule_again" file &&
755 test_commit "update_subsubmodule_again" file
757 test_commit "update_submodule_again_again" file
760 git rev-parse --verify HEAD >../expect &&
761 test_commit "update_submodule2_again" file
764 git add submodule2 &&
765 git commit -m "new_commits" &&
766 git checkout HEAD^ &&
768 git checkout HEAD^ &&
773 test_expect_code 1 git submodule update --recursive &&
775 git rev-parse --verify HEAD >../actual
777 test_cmp expect actual
781 test_expect_success
'submodule update exit immediately in case of merge conflict' '
784 git reset --hard HEAD &&
787 git reset --hard HEAD
790 git submodule update --recursive &&
792 test_commit "update_submodule_2" file
795 test_commit "update_submodule2_2" file
798 git add submodule2 &&
799 git commit -m "two_new_submodule_commits" &&
802 test_commit "conflict" file &&
803 echo "conflict" > file
805 git checkout HEAD^ &&
807 git rev-parse --verify HEAD >../expect
809 git config submodule.submodule.update merge &&
810 test_must_fail git submodule update &&
812 git rev-parse --verify HEAD >../actual
814 test_cmp expect actual
818 test_expect_success
'submodule update exit immediately after recursive rebase error' '
821 git reset --hard HEAD &&
823 git reset --hard HEAD &&
824 git submodule update --recursive
827 test_commit "update_submodule_3" file
830 test_commit "update_submodule2_3" file
833 git add submodule2 &&
834 git commit -m "two_new_submodule_commits" &&
837 test_commit "conflict2" file &&
838 echo "conflict" > file
840 git checkout HEAD^ &&
842 git rev-parse --verify HEAD >../expect
844 git config submodule.submodule.update rebase &&
845 test_must_fail git submodule update &&
847 git rev-parse --verify HEAD >../actual
849 test_cmp expect actual
853 test_expect_success
'add different submodules to the same path' '
855 git submodule add ../submodule s1 &&
856 test_must_fail git submodule add ../merging s1
860 test_expect_success
'submodule add places git-dir in superprojects git-dir' '
863 git submodule add ../submodule deeper/submodule &&
864 (cd deeper/submodule &&
865 git log > ../../expected
867 (cd .git/modules/deeper/submodule &&
868 git log > ../../../../actual
870 test_cmp expected actual
874 test_expect_success
'submodule update places git-dir in superprojects git-dir' '
876 git commit -m "added submodule"
878 git clone super super2 &&
880 git submodule init deeper/submodule &&
881 git submodule update &&
882 (cd deeper/submodule &&
883 git log > ../../expected
885 (cd .git/modules/deeper/submodule &&
886 git log > ../../../../actual
888 test_cmp expected actual
892 test_expect_success
'submodule add places git-dir in superprojects git-dir recursive' '
894 (cd deeper/submodule &&
895 git submodule add ../submodule subsubmodule &&
897 git log > ../../../expected
899 git commit -m "added subsubmodule" &&
902 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
903 git log > ../../../../../actual
905 git add deeper/submodule &&
906 git commit -m "update submodule" &&
908 test_cmp expected actual
912 test_expect_success
'submodule update places git-dir in superprojects git-dir recursive' '
913 mkdir super_update_r &&
914 (cd super_update_r &&
917 mkdir subsuper_update_r &&
918 (cd subsuper_update_r &&
921 mkdir subsubsuper_update_r &&
922 (cd subsubsuper_update_r &&
925 git clone subsubsuper_update_r subsubsuper_update_r2 &&
926 (cd subsubsuper_update_r2 &&
927 test_commit "update_subsubsuper" file &&
930 git clone subsuper_update_r subsuper_update_r2 &&
931 (cd subsuper_update_r2 &&
932 test_commit "update_subsuper" file &&
933 git submodule add ../subsubsuper_update_r subsubmodule &&
934 git commit -am "subsubmodule" &&
937 git clone super_update_r super_update_r2 &&
938 (cd super_update_r2 &&
939 test_commit "update_super" file &&
940 git submodule add ../subsuper_update_r submodule &&
941 git commit -am "submodule" &&
944 rm -rf super_update_r2 &&
945 git clone super_update_r super_update_r2 &&
946 (cd super_update_r2 &&
947 git submodule update --init --recursive >actual &&
948 test_grep "Submodule path .submodule/subsubmodule.: checked out" actual &&
949 (cd submodule/subsubmodule &&
950 git log > ../../expected
952 (cd .git/modules/submodule/modules/subsubmodule &&
953 git log > ../../../../../actual
955 test_cmp expected actual
959 test_expect_success
'submodule add properly re-creates deeper level submodules' '
961 git reset --hard main &&
963 git submodule add --force ../submodule deeper/submodule
967 test_expect_success
'submodule update properly revives a moved submodule' '
969 H=$(git rev-parse --short HEAD) &&
970 git commit -am "pre move" &&
971 H2=$(git rev-parse --short HEAD) &&
973 sed "s/$H/XXX/" out >expect &&
974 H=$(cd submodule2 && git rev-parse HEAD) &&
975 git rm --cached submodule2 &&
977 mkdir -p "moved/sub module" &&
978 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
979 git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
980 git commit -am "post move" &&
981 git submodule update &&
983 sed "s/$H2/XXX/" out >actual &&
984 test_cmp expect actual
988 test_expect_success SYMLINKS
'submodule update can handle symbolic links in pwd' '
989 mkdir -p linked/dir &&
990 ln -s linked/dir linkto &&
992 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
994 git submodule update --init --recursive
999 test_expect_success
'submodule update clone shallow submodule' '
1000 test_when_finished "rm -rf super3" &&
1001 first=$(git -C cloned rev-parse HEAD:submodule) &&
1002 second=$(git -C submodule rev-parse HEAD) &&
1003 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
1004 git clone cloned super3 &&
1008 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
1009 mv -f .gitmodules.tmp .gitmodules &&
1010 git submodule update --init --depth=$commit_count &&
1011 git -C submodule log --oneline >out &&
1012 test_line_count = 1 out
1016 test_expect_success
'submodule update clone shallow submodule outside of depth' '
1017 test_when_finished "rm -rf super3" &&
1018 git clone cloned super3 &&
1022 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
1023 mv -f .gitmodules.tmp .gitmodules &&
1024 # Some protocol versions (e.g. 2) support fetching
1025 # unadvertised objects, so restrict this test to v0.
1026 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1027 git submodule update --init --depth=1 2>actual &&
1028 test_grep "Direct fetching of that commit failed." actual &&
1029 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
1030 git submodule update --init --depth=1 >actual &&
1031 git -C submodule log --oneline >out &&
1032 test_line_count = 1 out
1036 test_expect_success
'submodule update --recursive drops module name before recursing' '
1038 (cd deeper/submodule/subsubmodule &&
1041 git submodule update --recursive deeper/submodule >actual &&
1042 test_grep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
1046 test_expect_success
'submodule update can be run in parallel' '
1048 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
1049 grep "7 tasks" trace.out &&
1050 git config submodule.fetchJobs 8 &&
1051 GIT_TRACE=$(pwd)/trace.out git submodule update &&
1052 grep "8 tasks" trace.out &&
1053 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
1054 grep "9 tasks" trace.out
1058 test_expect_success
'git clone passes the parallel jobs config on to submodules' '
1059 test_when_finished "rm -rf super4" &&
1060 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
1061 grep "7 tasks" trace.out &&
1063 git config --global submodule.fetchJobs 8 &&
1064 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
1065 grep "8 tasks" trace.out &&
1067 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
1068 grep "9 tasks" trace.out &&
1072 test_expect_success
'submodule update --quiet passes quietness to merge/rebase' '
1074 test_commit -C rebasing message &&
1075 git submodule update --rebase --quiet >out 2>err &&
1076 test_must_be_empty out &&
1077 test_must_be_empty err &&
1078 git submodule update --rebase >out 2>err &&
1079 test_file_not_empty out &&
1080 test_must_be_empty err
1084 test_expect_success
'submodule update --quiet passes quietness to fetch with a shallow clone' '
1085 test_when_finished "rm -rf super4 super5 super6" &&
1086 git clone . super4 &&
1088 git submodule add --quiet file://"$TRASH_DIRECTORY"/submodule submodule3 &&
1089 git commit -am "setup submodule3"
1092 test_commit line6 file
1094 git clone super4 super5 &&
1096 git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
1097 test_must_be_empty out &&
1098 test_must_be_empty err
1100 git clone super4 super6 &&
1102 git submodule update --init --depth=1 submodule3 >out 2>err &&
1103 test_file_not_empty out &&
1104 test_file_not_empty err
1108 test_expect_success
'submodule update --filter requires --init' '
1109 test_expect_code 129 git -C super submodule update --filter blob:none
1112 test_expect_success
'submodule update --filter sets partial clone settings' '
1113 test_when_finished "rm -rf super-filter" &&
1114 git clone cloned super-filter &&
1115 git -C super-filter submodule update --init --filter blob:none &&
1116 test_cmp_config -C super-filter/submodule true remote.origin.promisor &&
1117 test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter
1120 # NEEDSWORK: Clean up the tests so that we can reuse the test setup.
1121 # Don't reuse the existing repos because the earlier tests have
1122 # intentionally disruptive configurations.
1123 test_expect_success
'setup clean recursive superproject' '
1125 test_commit -C bottom "bottom" &&
1127 git -C middle submodule add ../bottom bottom &&
1128 git -C middle commit -m "middle" &&
1130 git -C top submodule add ../middle middle &&
1131 git -C top commit -m "top" &&
1132 git clone --recurse-submodules top top-clean
1135 test_expect_success
'submodule update should skip unmerged submodules' '
1136 test_when_finished "rm -fr top-cloned" &&
1137 cp -r top-clean top-cloned &&
1139 # Create an upstream commit in each repo, starting with bottom
1140 test_commit -C bottom upstream_commit &&
1141 # Create middle commit
1142 git -C middle/bottom fetch &&
1143 git -C middle/bottom checkout -f FETCH_HEAD &&
1144 git -C middle add bottom &&
1145 git -C middle commit -m "upstream_commit" &&
1147 git -C top/middle fetch &&
1148 git -C top/middle checkout -f FETCH_HEAD &&
1149 git -C top add middle &&
1150 git -C top commit -m "upstream_commit" &&
1152 # Create a downstream conflict
1153 test_commit -C top-cloned/middle/bottom downstream_commit &&
1154 git -C top-cloned/middle add bottom &&
1155 git -C top-cloned/middle commit -m "downstream_commit" &&
1156 git -C top-cloned/middle fetch --recurse-submodules origin &&
1157 test_must_fail git -C top-cloned/middle merge origin/main &&
1159 # Make the update of "middle" a no-op, otherwise we error out
1160 # because of its unmerged state
1161 test_config -C top-cloned submodule.middle.update !true &&
1162 git -C top-cloned submodule update --recursive 2>actual.err &&
1163 cat >expect.err <<-\EOF &&
1164 Skipping unmerged submodule middle/bottom
1166 test_cmp expect.err actual.err
1169 test_expect_success
'submodule update --recursive skip submodules with strategy=none' '
1170 test_when_finished "rm -fr top-cloned" &&
1171 cp -r top-clean top-cloned &&
1173 test_commit -C top-cloned/middle/bottom downstream_commit &&
1174 git -C top-cloned/middle config submodule.bottom.update none &&
1175 git -C top-cloned submodule update --recursive 2>actual.err &&
1176 cat >expect.err <<-\EOF &&
1177 Skipping submodule '\''middle/bottom'\''
1179 test_cmp expect.err actual.err
1182 add_submodule_commit_and_validate
() {
1183 HASH
=$
(git rev-parse HEAD
) &&
1184 git update-index
--add --cacheinfo 160000,$HASH,sub
&&
1185 git commit
-m "create submodule" &&
1186 echo "160000 commit $HASH sub" >expect
&&
1187 git ls-tree HEAD
-- sub
>actual
&&
1188 test_cmp expect actual
1191 test_expect_success
'commit with staged submodule change' '
1192 add_submodule_commit_and_validate
1195 test_expect_success
'commit with staged submodule change with ignoreSubmodules dirty' '
1196 test_config diff.ignoreSubmodules dirty &&
1197 add_submodule_commit_and_validate
1200 test_expect_success
'commit with staged submodule change with ignoreSubmodules all' '
1201 test_config diff.ignoreSubmodules all &&
1202 add_submodule_commit_and_validate
1205 test_expect_success CASE_INSENSITIVE_FS
,SYMLINKS \
1206 'submodule paths must not follow symlinks' '
1208 # This is only needed because we want to run this in a self-contained
1209 # test without having to spin up an HTTP server; However, it would not
1210 # be needed in a real-world scenario where the submodule is simply
1211 # hosted on a public site.
1212 test_config_global protocol.file.allow always &&
1214 # Make sure that Git tries to use symlinks on Windows
1215 test_config_global core.symlinks true &&
1217 tell_tale_path="$PWD/tell.tale" &&
1222 write_script y/hooks/post-checkout <<-EOF &&
1224 echo hook-run >"$tell_tale_path"
1226 git add y/hooks/post-checkout &&
1228 git commit -m post-checkout
1231 hook_repo_path="$(pwd)/hook" &&
1235 git submodule add --name x/y "$hook_repo_path" A/modules/x &&
1237 git commit -m add-submodule &&
1239 printf .git >dotgit.txt &&
1240 git hash-object -w --stdin <dotgit.txt >dot-git.hash &&
1241 printf "120000 %s 0\ta\n" "$(cat dot-git.hash)" >index.info &&
1242 git update-index --index-info <index.info &&
1244 git commit -m add-symlink
1247 test_path_is_missing "$tell_tale_path" &&
1248 git clone --recursive captain hooked 2>err &&
1249 test_grep ! HOOK-RUN err &&
1250 test_path_is_missing "$tell_tale_path"