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.
17 sha_master
=$
(git rev-list
--max-count=1 master
)
18 sha_head
=$
(git rev-list
--max-count=1 HEAD
)
20 test "$sha_master" = "$sha_head"
24 test_expect_success
'setup a submodule tree' '
28 git commit -m upstream &&
30 git clone super submodule &&
31 git clone super rebasing &&
32 git clone super merging &&
33 git clone super none &&
35 git submodule add ../submodule submodule &&
37 git commit -m "submodule" &&
38 git submodule init submodule
41 echo "line2" > file &&
43 git commit -m "Commit 2"
47 git pull --rebase origin
50 git commit -m "submodule update"
53 git submodule add ../rebasing rebasing &&
55 git commit -m "rebasing"
58 git submodule add ../merging merging &&
60 git commit -m "rebasing"
63 git submodule add ../none none &&
67 git clone . recursivesuper &&
68 ( cd recursivesuper &&
69 git submodule add ../super super
73 test_expect_success
'update --remote falls back to using HEAD' '
74 test_create_repo main-branch-submodule &&
75 test_commit -C main-branch-submodule initial &&
77 test_create_repo main-branch &&
78 git -C main-branch submodule add ../main-branch-submodule &&
79 git -C main-branch commit -m add-submodule &&
81 git -C main-branch-submodule switch -c hello &&
82 test_commit -C main-branch-submodule world &&
84 git clone --recursive main-branch main-branch-clone &&
85 git -C main-branch-clone submodule update --remote main-branch-submodule &&
86 test_path_exists main-branch-clone/main-branch-submodule/world.t
89 test_expect_success
'submodule update detaching the HEAD ' '
90 (cd super/submodule &&
91 git reset --hard HEAD~1
97 git submodule update submodule &&
103 test_expect_success
'submodule update from subdirectory' '
104 (cd super/submodule &&
105 git reset --hard HEAD~1
112 git submodule update ../submodule &&
118 supersha1
=$
(git
-C super rev-parse HEAD
)
119 mergingsha1
=$
(git
-C super
/merging rev-parse HEAD
)
120 nonesha1
=$
(git
-C super
/none rev-parse HEAD
)
121 rebasingsha1
=$
(git
-C super
/rebasing rev-parse HEAD
)
122 submodulesha1
=$
(git
-C super
/submodule rev-parse HEAD
)
126 Submodule path '../super': checked out '$supersha1'
127 Submodule path '../super/merging': checked out '$mergingsha1'
128 Submodule path '../super/none': checked out '$nonesha1'
129 Submodule path '../super/rebasing': checked out '$rebasingsha1'
130 Submodule path '../super/submodule': checked out '$submodulesha1'
134 Cloning into '$pwd/recursivesuper/super/merging'...
135 Cloning into '$pwd/recursivesuper/super/none'...
136 Cloning into '$pwd/recursivesuper/super/rebasing'...
137 Cloning into '$pwd/recursivesuper/super/submodule'...
138 Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
139 Submodule 'none' ($pwd/none) registered for path '../super/none'
140 Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
141 Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
148 test_expect_success
'submodule update --init --recursive from subdirectory' '
149 git -C recursivesuper/super reset --hard HEAD^ &&
150 (cd recursivesuper &&
153 git submodule update --init --recursive ../super >../../actual 2>../../actual2
155 test_i18ncmp expect actual &&
156 sort actual2 >actual2.sorted &&
157 test_i18ncmp expect2 actual2.sorted
161 Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
164 test_expect_success
'submodule update --init from and of subdirectory' '
168 git submodule add "$(pwd)/../rebasing" foo/sub &&
170 git submodule deinit -f sub &&
171 git submodule update --init sub 2>../../actual2
174 test_i18ncmp expect2 actual2
177 test_expect_success
'submodule update does not fetch already present commits' '
179 echo line3 >> file &&
182 git commit -m "upstream line3"
184 (cd super/submodule &&
185 head=$(git rev-parse --verify HEAD) &&
186 echo "Submodule path ${SQ}submodule$SQ: checked out $SQ$head$SQ" > ../../expected &&
187 git reset --hard HEAD~1
190 git submodule update > ../actual 2> ../actual.err
192 test_i18ncmp expected actual &&
193 test_must_be_empty actual.err
196 test_expect_success
'submodule update should fail due to local changes' '
197 (cd super/submodule &&
198 git reset --hard HEAD~1 &&
199 echo "local change" > file
205 test_must_fail git submodule update submodule
208 test_expect_success
'submodule update should throw away changes with --force ' '
213 git submodule update --force submodule &&
219 test_expect_success
'submodule update --force forcibly checks out submodules' '
224 git submodule update --force submodule &&
226 test "$(git status -s file)" = ""
231 test_expect_success
'submodule update --remote should fetch upstream changes' '
233 echo line4 >> file &&
236 git commit -m "upstream line4"
239 git submodule update --remote --force submodule &&
241 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
245 test_expect_success
'submodule update --remote should fetch upstream changes with .' '
248 git config -f .gitmodules submodule."submodule".branch "." &&
249 git add .gitmodules &&
250 git commit -m "submodules: update from the respective superproject branch"
254 echo line4a >> file &&
257 git commit -m "upstream line4a" &&
258 git checkout -b test-branch &&
259 test_commit on-test-branch
263 git submodule update --remote --force submodule &&
264 git -C submodule log -1 --oneline >actual &&
265 git -C ../submodule log -1 --oneline master >expect &&
266 test_cmp expect actual &&
267 git checkout -b test-branch &&
268 git submodule update --remote --force submodule &&
269 git -C submodule log -1 --oneline >actual &&
270 git -C ../submodule log -1 --oneline test-branch >expect &&
271 test_cmp expect actual &&
272 git checkout master &&
273 git branch -d test-branch &&
274 git reset --hard HEAD^
278 test_expect_success
'local config should override .gitmodules branch' '
280 git checkout test-branch &&
281 echo line5 >> file &&
284 git commit -m "upstream line5" &&
288 git config submodule.submodule.branch test-branch &&
289 git submodule update --remote --force submodule &&
291 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
295 test_expect_success
'submodule update --rebase staying on master' '
296 (cd super/submodule &&
303 git submodule update --rebase submodule &&
309 test_expect_success
'submodule update --merge staying on master' '
310 (cd super/submodule &&
311 git reset --hard HEAD~1
317 git submodule update --merge submodule &&
323 test_expect_success
'submodule update - rebase in .git/config' '
325 git config submodule.submodule.update rebase
327 (cd super/submodule &&
328 git reset --hard HEAD~1
334 git submodule update submodule &&
340 test_expect_success
'submodule update - checkout in .git/config but --rebase given' '
342 git config submodule.submodule.update checkout
344 (cd super/submodule &&
345 git reset --hard HEAD~1
351 git submodule update --rebase submodule &&
357 test_expect_success
'submodule update - merge in .git/config' '
359 git config submodule.submodule.update merge
361 (cd super/submodule &&
362 git reset --hard HEAD~1
368 git submodule update submodule &&
374 test_expect_success
'submodule update - checkout in .git/config but --merge given' '
376 git config submodule.submodule.update checkout
378 (cd super/submodule &&
379 git reset --hard HEAD~1
385 git submodule update --merge submodule &&
391 test_expect_success
'submodule update - checkout in .git/config' '
393 git config submodule.submodule.update checkout
395 (cd super/submodule &&
396 git reset --hard HEAD^
402 git submodule update submodule &&
408 test_expect_success
'submodule update - command in .git/config' '
410 git config submodule.submodule.update "!git checkout"
412 (cd super/submodule &&
413 git reset --hard HEAD^
419 git submodule update submodule &&
425 test_expect_success
'submodule update - command in .gitmodules is rejected' '
426 test_when_finished "git -C super reset --hard HEAD^" &&
427 git -C super config -f .gitmodules submodule.submodule.update "!false" &&
428 git -C super commit -a -m "add command to .gitmodules file" &&
429 git -C super/submodule reset --hard $submodulesha1^ &&
430 test_must_fail git -C super submodule update submodule
433 test_expect_success
'fsck detects command in .gitmodules' '
434 git init command-in-gitmodules &&
436 cd command-in-gitmodules &&
437 git submodule add ../submodule submodule &&
438 test_commit adding-submodule &&
440 git config -f .gitmodules submodule.submodule.update "!false" &&
441 git add .gitmodules &&
442 test_commit configuring-update &&
443 test_must_fail git fsck
448 Execution of 'false $submodulesha1' failed in submodule path 'submodule'
451 test_expect_success
'submodule update - command in .git/config catches failure' '
453 git config submodule.submodule.update "!false"
455 (cd super/submodule &&
456 git reset --hard $submodulesha1^
459 test_must_fail git submodule update submodule 2>../actual
461 test_i18ncmp actual expect
465 Execution of 'false $submodulesha1' failed in submodule path '../submodule'
468 test_expect_success
'submodule update - command in .git/config catches failure -- subdirectory' '
470 git config submodule.submodule.update "!false"
472 (cd super/submodule &&
473 git reset --hard $submodulesha1^
476 mkdir tmp && cd tmp &&
477 test_must_fail git submodule update ../submodule 2>../../actual
479 test_i18ncmp actual expect
482 test_expect_success
'submodule update - command run for initial population of submodule' '
483 cat >expect <<-EOF &&
484 Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
486 rm -rf super/submodule &&
487 test_must_fail git -C super submodule update 2>actual &&
488 test_i18ncmp expect actual &&
489 git -C super submodule update --checkout
493 Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
494 Failed to recurse into submodule path '../super'
497 test_expect_success
'recursive submodule update - command in .git/config catches failure -- subdirectory' '
498 (cd recursivesuper &&
499 git submodule update --remote super &&
501 git commit -m "update to latest to have more than one commit in submodules"
503 git -C recursivesuper/super config submodule.submodule.update "!false" &&
504 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
505 (cd recursivesuper &&
506 mkdir -p tmp && cd tmp &&
507 test_must_fail git submodule update --recursive ../super 2>../../actual
509 test_i18ncmp actual expect
512 test_expect_success
'submodule init does not copy command into .git/config' '
513 test_when_finished "git -C super update-index --force-remove submodule1" &&
514 test_when_finished git config -f super/.gitmodules \
515 --remove-section submodule.submodule1 &&
517 git ls-files -s submodule >out &&
518 H=$(cut -d" " -f2 out) &&
520 git update-index --add --cacheinfo 160000 $H submodule1 &&
521 git config -f .gitmodules submodule.submodule1.path submodule1 &&
522 git config -f .gitmodules submodule.submodule1.url ../submodule &&
523 git config -f .gitmodules submodule.submodule1.update !false &&
524 test_must_fail git submodule init submodule1 &&
525 test_expect_code 1 git config submodule.submodule1.update >actual &&
526 test_must_be_empty actual
530 test_expect_success
'submodule init picks up rebase' '
532 git config -f .gitmodules submodule.rebasing.update rebase &&
533 git submodule init rebasing &&
534 test "rebase" = "$(git config submodule.rebasing.update)"
538 test_expect_success
'submodule init picks up merge' '
540 git config -f .gitmodules submodule.merging.update merge &&
541 git submodule init merging &&
542 test "merge" = "$(git config submodule.merging.update)"
546 test_expect_success
'submodule update --merge - ignores --merge for new submodules' '
547 test_config -C super submodule.submodule.update checkout &&
550 git submodule update submodule &&
551 git status -s submodule >expect &&
553 git submodule update --merge submodule &&
554 git status -s submodule >actual &&
555 test_cmp expect actual
559 test_expect_success
'submodule update --rebase - ignores --rebase for new submodules' '
560 test_config -C super submodule.submodule.update checkout &&
563 git submodule update submodule &&
564 git status -s submodule >expect &&
566 git submodule update --rebase submodule &&
567 git status -s submodule >actual &&
568 test_cmp expect actual
572 test_expect_success
'submodule update ignores update=merge config for new submodules' '
575 git submodule update submodule &&
576 git status -s submodule >expect &&
578 git config submodule.submodule.update merge &&
579 git submodule update submodule &&
580 git status -s submodule >actual &&
581 git config --unset submodule.submodule.update &&
582 test_cmp expect actual
586 test_expect_success
'submodule update ignores update=rebase config for new submodules' '
589 git submodule update submodule &&
590 git status -s submodule >expect &&
592 git config submodule.submodule.update rebase &&
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 init picks up update=none' '
602 git config -f .gitmodules submodule.none.update none &&
603 git submodule init none &&
604 test "none" = "$(git config submodule.none.update)"
608 test_expect_success
'submodule update - update=none in .git/config' '
610 git config submodule.submodule.update none &&
612 git checkout master &&
615 git diff --name-only >out &&
616 grep ^submodule$ out &&
617 git submodule update &&
618 git diff --name-only >out &&
619 grep ^submodule$ out &&
623 git config --unset submodule.submodule.update &&
624 git submodule update submodule
628 test_expect_success
'submodule update - update=none in .git/config but --checkout given' '
630 git config submodule.submodule.update none &&
632 git checkout master &&
635 git diff --name-only >out &&
636 grep ^submodule$ out &&
637 git submodule update --checkout &&
638 git diff --name-only >out &&
639 ! grep ^submodule$ out &&
643 git config --unset submodule.submodule.update
647 test_expect_success
'submodule update --init skips submodule with update=none' '
649 git add .gitmodules &&
650 git commit -m ".gitmodules"
652 git clone super cloned &&
654 git submodule update --init &&
655 test_path_exists submodule/.git &&
656 test_path_is_missing none/.git
660 test_expect_success
'submodule update continues after checkout error' '
662 git reset --hard HEAD &&
663 git submodule add ../submodule submodule2 &&
664 git submodule init &&
665 git commit -am "new_submodule" &&
667 git rev-parse --verify HEAD >../expect
670 test_commit "update_submodule" file
673 test_commit "update_submodule2" file
676 git add submodule2 &&
677 git commit -m "two_new_submodule_commits" &&
681 git checkout HEAD^ &&
682 test_must_fail git submodule update &&
684 git rev-parse --verify HEAD >../actual
686 test_cmp expect actual
689 test_expect_success
'submodule update continues after recursive checkout error' '
691 git reset --hard HEAD &&
692 git checkout master &&
693 git submodule update &&
695 git submodule add ../submodule subsubmodule &&
696 git submodule init &&
697 git commit -m "new_subsubmodule"
700 git commit -m "update_submodule" &&
703 test_commit "update_subsubmodule" file
705 git add subsubmodule &&
706 test_commit "update_submodule_again" file &&
708 test_commit "update_subsubmodule_again" file
710 test_commit "update_submodule_again_again" file
713 git rev-parse --verify HEAD >../expect &&
714 test_commit "update_submodule2_again" file
717 git add submodule2 &&
718 git commit -m "new_commits" &&
719 git checkout HEAD^ &&
721 git checkout HEAD^ &&
726 test_must_fail git submodule update --recursive &&
728 git rev-parse --verify HEAD >../actual
730 test_cmp expect actual
734 test_expect_success
'submodule update exit immediately in case of merge conflict' '
736 git checkout master &&
737 git reset --hard HEAD &&
740 git reset --hard HEAD
743 git submodule update --recursive &&
745 test_commit "update_submodule_2" file
748 test_commit "update_submodule2_2" file
751 git add submodule2 &&
752 git commit -m "two_new_submodule_commits" &&
754 git checkout master &&
755 test_commit "conflict" file &&
756 echo "conflict" > file
758 git checkout HEAD^ &&
760 git rev-parse --verify HEAD >../expect
762 git config submodule.submodule.update merge &&
763 test_must_fail git submodule update &&
765 git rev-parse --verify HEAD >../actual
767 test_cmp expect actual
771 test_expect_success
'submodule update exit immediately after recursive rebase error' '
773 git checkout master &&
774 git reset --hard HEAD &&
776 git reset --hard HEAD &&
777 git submodule update --recursive
780 test_commit "update_submodule_3" file
783 test_commit "update_submodule2_3" file
786 git add submodule2 &&
787 git commit -m "two_new_submodule_commits" &&
789 git checkout master &&
790 test_commit "conflict2" file &&
791 echo "conflict" > file
793 git checkout HEAD^ &&
795 git rev-parse --verify HEAD >../expect
797 git config submodule.submodule.update rebase &&
798 test_must_fail git submodule update &&
800 git rev-parse --verify HEAD >../actual
802 test_cmp expect actual
806 test_expect_success
'add different submodules to the same path' '
808 git submodule add ../submodule s1 &&
809 test_must_fail git submodule add ../merging s1
813 test_expect_success
'submodule add places git-dir in superprojects git-dir' '
816 git submodule add ../submodule deeper/submodule &&
817 (cd deeper/submodule &&
818 git log > ../../expected
820 (cd .git/modules/deeper/submodule &&
821 git log > ../../../../actual
823 test_cmp expected actual
827 test_expect_success
'submodule update places git-dir in superprojects git-dir' '
829 git commit -m "added submodule"
831 git clone super super2 &&
833 git submodule init deeper/submodule &&
834 git submodule update &&
835 (cd deeper/submodule &&
836 git log > ../../expected
838 (cd .git/modules/deeper/submodule &&
839 git log > ../../../../actual
841 test_cmp expected actual
845 test_expect_success
'submodule add places git-dir in superprojects git-dir recursive' '
847 (cd deeper/submodule &&
848 git submodule add ../submodule subsubmodule &&
850 git log > ../../../expected
852 git commit -m "added subsubmodule" &&
855 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
856 git log > ../../../../../actual
858 git add deeper/submodule &&
859 git commit -m "update submodule" &&
861 test_cmp expected actual
865 test_expect_success
'submodule update places git-dir in superprojects git-dir recursive' '
866 mkdir super_update_r &&
867 (cd super_update_r &&
870 mkdir subsuper_update_r &&
871 (cd subsuper_update_r &&
874 mkdir subsubsuper_update_r &&
875 (cd subsubsuper_update_r &&
878 git clone subsubsuper_update_r subsubsuper_update_r2 &&
879 (cd subsubsuper_update_r2 &&
880 test_commit "update_subsubsuper" file &&
881 git push origin master
883 git clone subsuper_update_r subsuper_update_r2 &&
884 (cd subsuper_update_r2 &&
885 test_commit "update_subsuper" file &&
886 git submodule add ../subsubsuper_update_r subsubmodule &&
887 git commit -am "subsubmodule" &&
888 git push origin master
890 git clone super_update_r super_update_r2 &&
891 (cd super_update_r2 &&
892 test_commit "update_super" file &&
893 git submodule add ../subsuper_update_r submodule &&
894 git commit -am "submodule" &&
895 git push origin master
897 rm -rf super_update_r2 &&
898 git clone super_update_r super_update_r2 &&
899 (cd super_update_r2 &&
900 git submodule update --init --recursive >actual &&
901 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
902 (cd submodule/subsubmodule &&
903 git log > ../../expected
905 (cd .git/modules/submodule/modules/subsubmodule &&
906 git log > ../../../../../actual
908 test_cmp expected actual
912 test_expect_success
'submodule add properly re-creates deeper level submodules' '
914 git reset --hard master &&
916 git submodule add --force ../submodule deeper/submodule
920 test_expect_success
'submodule update properly revives a moved submodule' '
922 H=$(git rev-parse --short HEAD) &&
923 git commit -am "pre move" &&
924 H2=$(git rev-parse --short HEAD) &&
926 sed "s/$H/XXX/" out >expect &&
927 H=$(cd submodule2 && git rev-parse HEAD) &&
928 git rm --cached submodule2 &&
930 mkdir -p "moved/sub module" &&
931 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
932 git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
933 git commit -am "post move" &&
934 git submodule update &&
936 sed "s/$H2/XXX/" out >actual &&
937 test_cmp expect actual
941 test_expect_success SYMLINKS
'submodule update can handle symbolic links in pwd' '
942 mkdir -p linked/dir &&
943 ln -s linked/dir linkto &&
945 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
947 git submodule update --init --recursive
952 test_expect_success
'submodule update clone shallow submodule' '
953 test_when_finished "rm -rf super3" &&
954 first=$(git -C cloned rev-parse HEAD:submodule) &&
955 second=$(git -C submodule rev-parse HEAD) &&
956 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
957 git clone cloned super3 &&
961 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
962 mv -f .gitmodules.tmp .gitmodules &&
963 git submodule update --init --depth=$commit_count &&
964 git -C submodule log --oneline >out &&
965 test_line_count = 1 out
969 test_expect_success
'submodule update clone shallow submodule outside of depth' '
970 test_when_finished "rm -rf super3" &&
971 git clone cloned super3 &&
975 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
976 mv -f .gitmodules.tmp .gitmodules &&
977 # Some protocol versions (e.g. 2) support fetching
978 # unadvertised objects, so restrict this test to v0.
979 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
980 git submodule update --init --depth=1 2>actual &&
981 test_i18ngrep "Direct fetching of that commit failed." actual &&
982 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
983 git submodule update --init --depth=1 >actual &&
984 git -C submodule log --oneline >out &&
985 test_line_count = 1 out
989 test_expect_success
'submodule update --recursive drops module name before recursing' '
991 (cd deeper/submodule/subsubmodule &&
994 git submodule update --recursive deeper/submodule >actual &&
995 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
999 test_expect_success
'submodule update can be run in parallel' '
1001 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
1002 grep "7 tasks" trace.out &&
1003 git config submodule.fetchJobs 8 &&
1004 GIT_TRACE=$(pwd)/trace.out git submodule update &&
1005 grep "8 tasks" trace.out &&
1006 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
1007 grep "9 tasks" trace.out
1011 test_expect_success
'git clone passes the parallel jobs config on to submodules' '
1012 test_when_finished "rm -rf super4" &&
1013 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
1014 grep "7 tasks" trace.out &&
1016 git config --global submodule.fetchJobs 8 &&
1017 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
1018 grep "8 tasks" trace.out &&
1020 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
1021 grep "9 tasks" trace.out &&