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' '
25 git config --global protocol.file.allow always &&
29 git commit -m upstream &&
31 git clone super submodule &&
32 git clone super rebasing &&
33 git clone super merging &&
34 git clone super none &&
36 git submodule add ../submodule submodule &&
38 git commit -m "submodule" &&
39 git submodule init submodule
42 echo "line2" > file &&
44 git commit -m "Commit 2"
48 git pull --rebase origin
51 git commit -m "submodule update"
54 git submodule add ../rebasing rebasing &&
56 git commit -m "rebasing"
59 git submodule add ../merging merging &&
61 git commit -m "rebasing"
64 git submodule add ../none none &&
68 git clone . recursivesuper &&
69 ( cd recursivesuper &&
70 git submodule add ../super super
74 test_expect_success
'update --remote falls back to using HEAD' '
75 test_create_repo main-branch-submodule &&
76 test_commit -C main-branch-submodule initial &&
78 test_create_repo main-branch &&
79 git -C main-branch submodule add ../main-branch-submodule &&
80 git -C main-branch commit -m add-submodule &&
82 git -C main-branch-submodule switch -c hello &&
83 test_commit -C main-branch-submodule world &&
85 git clone --recursive main-branch main-branch-clone &&
86 git -C main-branch-clone submodule update --remote main-branch-submodule &&
87 test_path_exists main-branch-clone/main-branch-submodule/world.t
90 test_expect_success
'submodule update detaching the HEAD ' '
91 (cd super/submodule &&
92 git reset --hard HEAD~1
98 git submodule update submodule &&
104 test_expect_success
'submodule update from subdirectory' '
105 (cd super/submodule &&
106 git reset --hard HEAD~1
113 git submodule update ../submodule &&
119 supersha1
=$
(git
-C super rev-parse HEAD
)
120 mergingsha1
=$
(git
-C super
/merging rev-parse HEAD
)
121 nonesha1
=$
(git
-C super
/none rev-parse HEAD
)
122 rebasingsha1
=$
(git
-C super
/rebasing rev-parse HEAD
)
123 submodulesha1
=$
(git
-C super
/submodule rev-parse HEAD
)
127 Submodule path '../super': checked out '$supersha1'
128 Submodule path '../super/merging': checked out '$mergingsha1'
129 Submodule path '../super/none': checked out '$nonesha1'
130 Submodule path '../super/rebasing': checked out '$rebasingsha1'
131 Submodule path '../super/submodule': checked out '$submodulesha1'
135 Cloning into '$pwd/recursivesuper/super/merging'...
136 Cloning into '$pwd/recursivesuper/super/none'...
137 Cloning into '$pwd/recursivesuper/super/rebasing'...
138 Cloning into '$pwd/recursivesuper/super/submodule'...
139 Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
140 Submodule 'none' ($pwd/none) registered for path '../super/none'
141 Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
142 Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
149 test_expect_success
'submodule update --init --recursive from subdirectory' '
150 git -C recursivesuper/super reset --hard HEAD^ &&
151 (cd recursivesuper &&
154 git submodule update --init --recursive ../super >../../actual 2>../../actual2
156 test_i18ncmp expect actual &&
157 sort actual2 >actual2.sorted &&
158 test_i18ncmp expect2 actual2.sorted
162 Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
165 test_expect_success
'submodule update --init from and of subdirectory' '
169 git submodule add "$(pwd)/../rebasing" foo/sub &&
171 git submodule deinit -f sub &&
172 git submodule update --init sub 2>../../actual2
175 test_i18ncmp expect2 actual2
178 test_expect_success
'submodule update does not fetch already present commits' '
180 echo line3 >> file &&
183 git commit -m "upstream line3"
185 (cd super/submodule &&
186 head=$(git rev-parse --verify HEAD) &&
187 echo "Submodule path ${SQ}submodule$SQ: checked out $SQ$head$SQ" > ../../expected &&
188 git reset --hard HEAD~1
191 git submodule update > ../actual 2> ../actual.err
193 test_i18ncmp expected actual &&
194 test_must_be_empty actual.err
197 test_expect_success
'submodule update should fail due to local changes' '
198 (cd super/submodule &&
199 git reset --hard HEAD~1 &&
200 echo "local change" > file
206 test_must_fail git submodule update submodule
209 test_expect_success
'submodule update should throw away changes with --force ' '
214 git submodule update --force submodule &&
220 test_expect_success
'submodule update --force forcibly checks out submodules' '
225 git submodule update --force submodule &&
227 test "$(git status -s file)" = ""
232 test_expect_success
'submodule update --remote should fetch upstream changes' '
234 echo line4 >> file &&
237 git commit -m "upstream line4"
240 git submodule update --remote --force submodule &&
242 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
246 test_expect_success
'submodule update --remote should fetch upstream changes with .' '
249 git config -f .gitmodules submodule."submodule".branch "." &&
250 git add .gitmodules &&
251 git commit -m "submodules: update from the respective superproject branch"
255 echo line4a >> file &&
258 git commit -m "upstream line4a" &&
259 git checkout -b test-branch &&
260 test_commit on-test-branch
264 git submodule update --remote --force submodule &&
265 git -C submodule log -1 --oneline >actual &&
266 git -C ../submodule log -1 --oneline master >expect &&
267 test_cmp expect actual &&
268 git checkout -b test-branch &&
269 git submodule update --remote --force submodule &&
270 git -C submodule log -1 --oneline >actual &&
271 git -C ../submodule log -1 --oneline test-branch >expect &&
272 test_cmp expect actual &&
273 git checkout master &&
274 git branch -d test-branch &&
275 git reset --hard HEAD^
279 test_expect_success
'local config should override .gitmodules branch' '
281 git checkout test-branch &&
282 echo line5 >> file &&
285 git commit -m "upstream line5" &&
289 git config submodule.submodule.branch test-branch &&
290 git submodule update --remote --force submodule &&
292 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
296 test_expect_success
'submodule update --rebase staying on master' '
297 (cd super/submodule &&
304 git submodule update --rebase submodule &&
310 test_expect_success
'submodule update --merge staying on master' '
311 (cd super/submodule &&
312 git reset --hard HEAD~1
318 git submodule update --merge submodule &&
324 test_expect_success
'submodule update - rebase in .git/config' '
326 git config submodule.submodule.update rebase
328 (cd super/submodule &&
329 git reset --hard HEAD~1
335 git submodule update submodule &&
341 test_expect_success
'submodule update - checkout in .git/config but --rebase given' '
343 git config submodule.submodule.update checkout
345 (cd super/submodule &&
346 git reset --hard HEAD~1
352 git submodule update --rebase submodule &&
358 test_expect_success
'submodule update - merge in .git/config' '
360 git config submodule.submodule.update merge
362 (cd super/submodule &&
363 git reset --hard HEAD~1
369 git submodule update submodule &&
375 test_expect_success
'submodule update - checkout in .git/config but --merge given' '
377 git config submodule.submodule.update checkout
379 (cd super/submodule &&
380 git reset --hard HEAD~1
386 git submodule update --merge submodule &&
392 test_expect_success
'submodule update - checkout in .git/config' '
394 git config submodule.submodule.update checkout
396 (cd super/submodule &&
397 git reset --hard HEAD^
403 git submodule update submodule &&
409 test_expect_success
'submodule update - command in .git/config' '
411 git config submodule.submodule.update "!git checkout"
413 (cd super/submodule &&
414 git reset --hard HEAD^
420 git submodule update submodule &&
426 test_expect_success
'submodule update - command in .gitmodules is rejected' '
427 test_when_finished "git -C super reset --hard HEAD^" &&
428 git -C super config -f .gitmodules submodule.submodule.update "!false" &&
429 git -C super commit -a -m "add command to .gitmodules file" &&
430 git -C super/submodule reset --hard $submodulesha1^ &&
431 test_must_fail git -C super submodule update submodule
434 test_expect_success
'fsck detects command in .gitmodules' '
435 git init command-in-gitmodules &&
437 cd command-in-gitmodules &&
438 git submodule add ../submodule submodule &&
439 test_commit adding-submodule &&
441 git config -f .gitmodules submodule.submodule.update "!false" &&
442 git add .gitmodules &&
443 test_commit configuring-update &&
444 test_must_fail git fsck
449 Execution of 'false $submodulesha1' failed in submodule path 'submodule'
452 test_expect_success
'submodule update - command in .git/config catches failure' '
454 git config submodule.submodule.update "!false"
456 (cd super/submodule &&
457 git reset --hard $submodulesha1^
460 test_must_fail git submodule update submodule 2>../actual
462 test_i18ncmp actual expect
466 Execution of 'false $submodulesha1' failed in submodule path '../submodule'
469 test_expect_success
'submodule update - command in .git/config catches failure -- subdirectory' '
471 git config submodule.submodule.update "!false"
473 (cd super/submodule &&
474 git reset --hard $submodulesha1^
477 mkdir tmp && cd tmp &&
478 test_must_fail git submodule update ../submodule 2>../../actual
480 test_i18ncmp actual expect
483 test_expect_success
'submodule update - command run for initial population of submodule' '
484 cat >expect <<-EOF &&
485 Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
487 rm -rf super/submodule &&
488 test_must_fail git -C super submodule update 2>actual &&
489 test_i18ncmp expect actual &&
490 git -C super submodule update --checkout
494 Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
495 Failed to recurse into submodule path '../super'
498 test_expect_success
'recursive submodule update - command in .git/config catches failure -- subdirectory' '
499 (cd recursivesuper &&
500 git submodule update --remote super &&
502 git commit -m "update to latest to have more than one commit in submodules"
504 git -C recursivesuper/super config submodule.submodule.update "!false" &&
505 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
506 (cd recursivesuper &&
507 mkdir -p tmp && cd tmp &&
508 test_must_fail git submodule update --recursive ../super 2>../../actual
510 test_i18ncmp actual expect
513 test_expect_success
'submodule init does not copy command into .git/config' '
514 test_when_finished "git -C super update-index --force-remove submodule1" &&
515 test_when_finished git config -f super/.gitmodules \
516 --remove-section submodule.submodule1 &&
518 git ls-files -s submodule >out &&
519 H=$(cut -d" " -f2 out) &&
521 git update-index --add --cacheinfo 160000 $H submodule1 &&
522 git config -f .gitmodules submodule.submodule1.path submodule1 &&
523 git config -f .gitmodules submodule.submodule1.url ../submodule &&
524 git config -f .gitmodules submodule.submodule1.update !false &&
525 test_must_fail git submodule init submodule1 &&
526 test_expect_code 1 git config submodule.submodule1.update >actual &&
527 test_must_be_empty actual
531 test_expect_success
'submodule init picks up rebase' '
533 git config -f .gitmodules submodule.rebasing.update rebase &&
534 git submodule init rebasing &&
535 test "rebase" = "$(git config submodule.rebasing.update)"
539 test_expect_success
'submodule init picks up merge' '
541 git config -f .gitmodules submodule.merging.update merge &&
542 git submodule init merging &&
543 test "merge" = "$(git config submodule.merging.update)"
547 test_expect_success
'submodule update --merge - ignores --merge for new submodules' '
548 test_config -C super submodule.submodule.update checkout &&
551 git submodule update submodule &&
552 git status -s submodule >expect &&
554 git submodule update --merge submodule &&
555 git status -s submodule >actual &&
556 test_cmp expect actual
560 test_expect_success
'submodule update --rebase - ignores --rebase 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 --rebase submodule &&
568 git status -s submodule >actual &&
569 test_cmp expect actual
573 test_expect_success
'submodule update ignores update=merge config for new submodules' '
576 git submodule update submodule &&
577 git status -s submodule >expect &&
579 git config submodule.submodule.update merge &&
580 git submodule update submodule &&
581 git status -s submodule >actual &&
582 git config --unset submodule.submodule.update &&
583 test_cmp expect actual
587 test_expect_success
'submodule update ignores update=rebase config for new submodules' '
590 git submodule update submodule &&
591 git status -s submodule >expect &&
593 git config submodule.submodule.update rebase &&
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 init picks up update=none' '
603 git config -f .gitmodules submodule.none.update none &&
604 git submodule init none &&
605 test "none" = "$(git config submodule.none.update)"
609 test_expect_success
'submodule update - update=none in .git/config' '
611 git config submodule.submodule.update none &&
613 git checkout master &&
616 git diff --name-only >out &&
617 grep ^submodule$ out &&
618 git submodule update &&
619 git diff --name-only >out &&
620 grep ^submodule$ out &&
624 git config --unset submodule.submodule.update &&
625 git submodule update submodule
629 test_expect_success
'submodule update - update=none in .git/config but --checkout given' '
631 git config submodule.submodule.update none &&
633 git checkout master &&
636 git diff --name-only >out &&
637 grep ^submodule$ out &&
638 git submodule update --checkout &&
639 git diff --name-only >out &&
640 ! grep ^submodule$ out &&
644 git config --unset submodule.submodule.update
648 test_expect_success
'submodule update --init skips submodule with update=none' '
650 git add .gitmodules &&
651 git commit -m ".gitmodules"
653 git clone super cloned &&
655 git submodule update --init &&
656 test_path_exists submodule/.git &&
657 test_path_is_missing none/.git
661 test_expect_success
'submodule update continues after checkout error' '
663 git reset --hard HEAD &&
664 git submodule add ../submodule submodule2 &&
665 git submodule init &&
666 git commit -am "new_submodule" &&
668 git rev-parse --verify HEAD >../expect
671 test_commit "update_submodule" file
674 test_commit "update_submodule2" file
677 git add submodule2 &&
678 git commit -m "two_new_submodule_commits" &&
682 git checkout HEAD^ &&
683 test_must_fail git submodule update &&
685 git rev-parse --verify HEAD >../actual
687 test_cmp expect actual
690 test_expect_success
'submodule update continues after recursive checkout error' '
692 git reset --hard HEAD &&
693 git checkout master &&
694 git submodule update &&
696 git submodule add ../submodule subsubmodule &&
697 git submodule init &&
698 git commit -m "new_subsubmodule"
701 git commit -m "update_submodule" &&
704 test_commit "update_subsubmodule" file
706 git add subsubmodule &&
707 test_commit "update_submodule_again" file &&
709 test_commit "update_subsubmodule_again" file
711 test_commit "update_submodule_again_again" file
714 git rev-parse --verify HEAD >../expect &&
715 test_commit "update_submodule2_again" file
718 git add submodule2 &&
719 git commit -m "new_commits" &&
720 git checkout HEAD^ &&
722 git checkout HEAD^ &&
727 test_must_fail git submodule update --recursive &&
729 git rev-parse --verify HEAD >../actual
731 test_cmp expect actual
735 test_expect_success
'submodule update exit immediately in case of merge conflict' '
737 git checkout master &&
738 git reset --hard HEAD &&
741 git reset --hard HEAD
744 git submodule update --recursive &&
746 test_commit "update_submodule_2" file
749 test_commit "update_submodule2_2" file
752 git add submodule2 &&
753 git commit -m "two_new_submodule_commits" &&
755 git checkout master &&
756 test_commit "conflict" file &&
757 echo "conflict" > file
759 git checkout HEAD^ &&
761 git rev-parse --verify HEAD >../expect
763 git config submodule.submodule.update merge &&
764 test_must_fail git submodule update &&
766 git rev-parse --verify HEAD >../actual
768 test_cmp expect actual
772 test_expect_success
'submodule update exit immediately after recursive rebase error' '
774 git checkout master &&
775 git reset --hard HEAD &&
777 git reset --hard HEAD &&
778 git submodule update --recursive
781 test_commit "update_submodule_3" file
784 test_commit "update_submodule2_3" file
787 git add submodule2 &&
788 git commit -m "two_new_submodule_commits" &&
790 git checkout master &&
791 test_commit "conflict2" file &&
792 echo "conflict" > file
794 git checkout HEAD^ &&
796 git rev-parse --verify HEAD >../expect
798 git config submodule.submodule.update rebase &&
799 test_must_fail git submodule update &&
801 git rev-parse --verify HEAD >../actual
803 test_cmp expect actual
807 test_expect_success
'add different submodules to the same path' '
809 git submodule add ../submodule s1 &&
810 test_must_fail git submodule add ../merging s1
814 test_expect_success
'submodule add places git-dir in superprojects git-dir' '
817 git submodule add ../submodule deeper/submodule &&
818 (cd deeper/submodule &&
819 git log > ../../expected
821 (cd .git/modules/deeper/submodule &&
822 git log > ../../../../actual
824 test_cmp expected actual
828 test_expect_success
'submodule update places git-dir in superprojects git-dir' '
830 git commit -m "added submodule"
832 git clone super super2 &&
834 git submodule init deeper/submodule &&
835 git submodule update &&
836 (cd deeper/submodule &&
837 git log > ../../expected
839 (cd .git/modules/deeper/submodule &&
840 git log > ../../../../actual
842 test_cmp expected actual
846 test_expect_success
'submodule add places git-dir in superprojects git-dir recursive' '
848 (cd deeper/submodule &&
849 git submodule add ../submodule subsubmodule &&
851 git log > ../../../expected
853 git commit -m "added subsubmodule" &&
856 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
857 git log > ../../../../../actual
859 git add deeper/submodule &&
860 git commit -m "update submodule" &&
862 test_cmp expected actual
866 test_expect_success
'submodule update places git-dir in superprojects git-dir recursive' '
867 mkdir super_update_r &&
868 (cd super_update_r &&
871 mkdir subsuper_update_r &&
872 (cd subsuper_update_r &&
875 mkdir subsubsuper_update_r &&
876 (cd subsubsuper_update_r &&
879 git clone subsubsuper_update_r subsubsuper_update_r2 &&
880 (cd subsubsuper_update_r2 &&
881 test_commit "update_subsubsuper" file &&
882 git push origin master
884 git clone subsuper_update_r subsuper_update_r2 &&
885 (cd subsuper_update_r2 &&
886 test_commit "update_subsuper" file &&
887 git submodule add ../subsubsuper_update_r subsubmodule &&
888 git commit -am "subsubmodule" &&
889 git push origin master
891 git clone super_update_r super_update_r2 &&
892 (cd super_update_r2 &&
893 test_commit "update_super" file &&
894 git submodule add ../subsuper_update_r submodule &&
895 git commit -am "submodule" &&
896 git push origin master
898 rm -rf super_update_r2 &&
899 git clone super_update_r super_update_r2 &&
900 (cd super_update_r2 &&
901 git submodule update --init --recursive >actual &&
902 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
903 (cd submodule/subsubmodule &&
904 git log > ../../expected
906 (cd .git/modules/submodule/modules/subsubmodule &&
907 git log > ../../../../../actual
909 test_cmp expected actual
913 test_expect_success
'submodule add properly re-creates deeper level submodules' '
915 git reset --hard master &&
917 git submodule add --force ../submodule deeper/submodule
921 test_expect_success
'submodule update properly revives a moved submodule' '
923 H=$(git rev-parse --short HEAD) &&
924 git commit -am "pre move" &&
925 H2=$(git rev-parse --short HEAD) &&
927 sed "s/$H/XXX/" out >expect &&
928 H=$(cd submodule2 && git rev-parse HEAD) &&
929 git rm --cached submodule2 &&
931 mkdir -p "moved/sub module" &&
932 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
933 git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
934 git commit -am "post move" &&
935 git submodule update &&
937 sed "s/$H2/XXX/" out >actual &&
938 test_cmp expect actual
942 test_expect_success SYMLINKS
'submodule update can handle symbolic links in pwd' '
943 mkdir -p linked/dir &&
944 ln -s linked/dir linkto &&
946 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
948 git submodule update --init --recursive
953 test_expect_success
'submodule update clone shallow submodule' '
954 test_when_finished "rm -rf super3" &&
955 first=$(git -C cloned rev-parse HEAD:submodule) &&
956 second=$(git -C submodule rev-parse HEAD) &&
957 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
958 git clone cloned super3 &&
962 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
963 mv -f .gitmodules.tmp .gitmodules &&
964 git submodule update --init --depth=$commit_count &&
965 git -C submodule log --oneline >out &&
966 test_line_count = 1 out
970 test_expect_success
'submodule update clone shallow submodule outside of depth' '
971 test_when_finished "rm -rf super3" &&
972 git clone cloned super3 &&
976 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
977 mv -f .gitmodules.tmp .gitmodules &&
978 # Some protocol versions (e.g. 2) support fetching
979 # unadvertised objects, so restrict this test to v0.
980 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
981 git submodule update --init --depth=1 2>actual &&
982 test_i18ngrep "Direct fetching of that commit failed." actual &&
983 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
984 git submodule update --init --depth=1 >actual &&
985 git -C submodule log --oneline >out &&
986 test_line_count = 1 out
990 test_expect_success
'submodule update --recursive drops module name before recursing' '
992 (cd deeper/submodule/subsubmodule &&
995 git submodule update --recursive deeper/submodule >actual &&
996 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
1000 test_expect_success
'submodule update can be run in parallel' '
1002 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
1003 grep "7 tasks" trace.out &&
1004 git config submodule.fetchJobs 8 &&
1005 GIT_TRACE=$(pwd)/trace.out git submodule update &&
1006 grep "8 tasks" trace.out &&
1007 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
1008 grep "9 tasks" trace.out
1012 test_expect_success
'git clone passes the parallel jobs config on to submodules' '
1013 test_when_finished "rm -rf super4" &&
1014 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
1015 grep "7 tasks" trace.out &&
1017 git config --global submodule.fetchJobs 8 &&
1018 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
1019 grep "8 tasks" trace.out &&
1021 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
1022 grep "9 tasks" trace.out &&
1026 test_expect_success
'submodule update --quiet passes quietness to merge/rebase' '
1028 test_commit -C rebasing message &&
1029 git submodule update --rebase --quiet >out 2>err &&
1030 test_must_be_empty out &&
1031 test_must_be_empty err &&
1032 git submodule update --rebase -v >out 2>err &&
1033 test_file_not_empty out &&
1034 test_must_be_empty err