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
'submodule update detaching the HEAD ' '
74 (cd super/submodule &&
75 git reset --hard HEAD~1
81 git submodule update submodule &&
87 test_expect_success
'submodule update from subdirectory' '
88 (cd super/submodule &&
89 git reset --hard HEAD~1
96 git submodule update ../submodule &&
102 supersha1
=$
(git
-C super rev-parse HEAD
)
103 mergingsha1
=$
(git
-C super
/merging rev-parse HEAD
)
104 nonesha1
=$
(git
-C super
/none rev-parse HEAD
)
105 rebasingsha1
=$
(git
-C super
/rebasing rev-parse HEAD
)
106 submodulesha1
=$
(git
-C super
/submodule rev-parse HEAD
)
110 Submodule path '../super': checked out '$supersha1'
111 Submodule path '../super/merging': checked out '$mergingsha1'
112 Submodule path '../super/none': checked out '$nonesha1'
113 Submodule path '../super/rebasing': checked out '$rebasingsha1'
114 Submodule path '../super/submodule': checked out '$submodulesha1'
118 Cloning into '$pwd/recursivesuper/super/merging'...
119 Cloning into '$pwd/recursivesuper/super/none'...
120 Cloning into '$pwd/recursivesuper/super/rebasing'...
121 Cloning into '$pwd/recursivesuper/super/submodule'...
122 Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
123 Submodule 'none' ($pwd/none) registered for path '../super/none'
124 Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
125 Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
132 test_expect_success
'submodule update --init --recursive from subdirectory' '
133 git -C recursivesuper/super reset --hard HEAD^ &&
134 (cd recursivesuper &&
137 git submodule update --init --recursive ../super >../../actual 2>../../actual2
139 test_i18ncmp expect actual &&
140 sort actual2 >actual2.sorted &&
141 test_i18ncmp expect2 actual2.sorted
145 Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
148 test_expect_success
'submodule update --init from and of subdirectory' '
152 git submodule add "$(pwd)/../rebasing" foo/sub &&
154 git submodule deinit -f sub &&
155 git submodule update --init sub 2>../../actual2
158 test_i18ncmp expect2 actual2
162 test_expect_success
'submodule update does not fetch already present commits' '
164 echo line3 >> file &&
167 git commit -m "upstream line3"
169 (cd super/submodule &&
170 head=$(git rev-parse --verify HEAD) &&
171 echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
172 git reset --hard HEAD~1
175 git submodule update > ../actual 2> ../actual.err
177 test_i18ncmp expected actual &&
178 test_must_be_empty actual.err
181 test_expect_success
'submodule update should fail due to local changes' '
182 (cd super/submodule &&
183 git reset --hard HEAD~1 &&
184 echo "local change" > file
190 test_must_fail git submodule update submodule
193 test_expect_success
'submodule update should throw away changes with --force ' '
198 git submodule update --force submodule &&
204 test_expect_success
'submodule update --force forcibly checks out submodules' '
209 git submodule update --force submodule &&
211 test "$(git status -s file)" = ""
216 test_expect_success
'submodule update --remote should fetch upstream changes' '
218 echo line4 >> file &&
221 git commit -m "upstream line4"
224 git submodule update --remote --force submodule &&
226 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
230 test_expect_success
'submodule update --remote should fetch upstream changes with .' '
233 git config -f .gitmodules submodule."submodule".branch "." &&
234 git add .gitmodules &&
235 git commit -m "submodules: update from the respective superproject branch"
239 echo line4a >> file &&
242 git commit -m "upstream line4a" &&
243 git checkout -b test-branch &&
244 test_commit on-test-branch
248 git submodule update --remote --force submodule &&
249 git -C submodule log -1 --oneline >actual &&
250 git -C ../submodule log -1 --oneline master >expect &&
251 test_cmp expect actual &&
252 git checkout -b test-branch &&
253 git submodule update --remote --force submodule &&
254 git -C submodule log -1 --oneline >actual &&
255 git -C ../submodule log -1 --oneline test-branch >expect &&
256 test_cmp expect actual &&
257 git checkout master &&
258 git branch -d test-branch &&
259 git reset --hard HEAD^
263 test_expect_success
'local config should override .gitmodules branch' '
265 git checkout test-branch &&
266 echo line5 >> file &&
269 git commit -m "upstream line5" &&
273 git config submodule.submodule.branch test-branch &&
274 git submodule update --remote --force submodule &&
276 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
280 test_expect_success
'submodule update --rebase staying on master' '
281 (cd super/submodule &&
288 git submodule update --rebase submodule &&
294 test_expect_success
'submodule update --merge staying on master' '
295 (cd super/submodule &&
296 git reset --hard HEAD~1
302 git submodule update --merge submodule &&
308 test_expect_success
'submodule update - rebase in .git/config' '
310 git config submodule.submodule.update rebase
312 (cd super/submodule &&
313 git reset --hard HEAD~1
319 git submodule update submodule &&
325 test_expect_success
'submodule update - checkout in .git/config but --rebase given' '
327 git config submodule.submodule.update checkout
329 (cd super/submodule &&
330 git reset --hard HEAD~1
336 git submodule update --rebase submodule &&
342 test_expect_success
'submodule update - merge in .git/config' '
344 git config submodule.submodule.update merge
346 (cd super/submodule &&
347 git reset --hard HEAD~1
353 git submodule update submodule &&
359 test_expect_success
'submodule update - checkout in .git/config but --merge given' '
361 git config submodule.submodule.update checkout
363 (cd super/submodule &&
364 git reset --hard HEAD~1
370 git submodule update --merge submodule &&
376 test_expect_success
'submodule update - checkout in .git/config' '
378 git config submodule.submodule.update checkout
380 (cd super/submodule &&
381 git reset --hard HEAD^
387 git submodule update submodule &&
393 test_expect_success
'submodule update - command in .git/config' '
395 git config submodule.submodule.update "!git checkout"
397 (cd super/submodule &&
398 git reset --hard HEAD^
404 git submodule update submodule &&
410 test_expect_success
'submodule update - command in .gitmodules is ignored' '
411 test_when_finished "git -C super reset --hard HEAD^" &&
412 git -C super config -f .gitmodules submodule.submodule.update "!false" &&
413 git -C super commit -a -m "add command to .gitmodules file" &&
414 git -C super/submodule reset --hard $submodulesha1^ &&
415 git -C super submodule update submodule
419 Execution of 'false $submodulesha1' failed in submodule path 'submodule'
422 test_expect_success
'submodule update - command in .git/config catches failure' '
424 git config submodule.submodule.update "!false"
426 (cd super/submodule &&
427 git reset --hard $submodulesha1^
430 test_must_fail git submodule update submodule 2>../actual
432 test_i18ncmp actual expect
436 Execution of 'false $submodulesha1' failed in submodule path '../submodule'
439 test_expect_success
'submodule update - command in .git/config catches failure -- subdirectory' '
441 git config submodule.submodule.update "!false"
443 (cd super/submodule &&
444 git reset --hard $submodulesha1^
447 mkdir tmp && cd tmp &&
448 test_must_fail git submodule update ../submodule 2>../../actual
450 test_i18ncmp actual expect
453 test_expect_success
'submodule update - command run for initial population of submodule' '
454 cat >expect <<-EOF &&
455 Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
457 rm -rf super/submodule &&
458 test_must_fail git -C super submodule update 2>actual &&
459 test_i18ncmp expect actual &&
460 git -C super submodule update --checkout
464 Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
465 Failed to recurse into submodule path '../super'
468 test_expect_success
'recursive submodule update - command in .git/config catches failure -- subdirectory' '
469 (cd recursivesuper &&
470 git submodule update --remote super &&
472 git commit -m "update to latest to have more than one commit in submodules"
474 git -C recursivesuper/super config submodule.submodule.update "!false" &&
475 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
476 (cd recursivesuper &&
477 mkdir -p tmp && cd tmp &&
478 test_must_fail git submodule update --recursive ../super 2>../../actual
480 test_i18ncmp actual expect
483 test_expect_success
'submodule init does not copy command into .git/config' '
485 git ls-files -s submodule >out &&
486 H=$(cut -d" " -f2 out) &&
488 git update-index --add --cacheinfo 160000 $H submodule1 &&
489 git config -f .gitmodules submodule.submodule1.path submodule1 &&
490 git config -f .gitmodules submodule.submodule1.url ../submodule &&
491 git config -f .gitmodules submodule.submodule1.update !false &&
492 git submodule init submodule1 &&
493 echo "none" >expect &&
494 git config submodule.submodule1.update >actual &&
495 test_cmp expect actual
499 test_expect_success
'submodule init picks up rebase' '
501 git config -f .gitmodules submodule.rebasing.update rebase &&
502 git submodule init rebasing &&
503 test "rebase" = "$(git config submodule.rebasing.update)"
507 test_expect_success
'submodule init picks up merge' '
509 git config -f .gitmodules submodule.merging.update merge &&
510 git submodule init merging &&
511 test "merge" = "$(git config submodule.merging.update)"
515 test_expect_success
'submodule update --merge - ignores --merge for new submodules' '
516 test_config -C super submodule.submodule.update checkout &&
519 git submodule update submodule &&
520 git status -s submodule >expect &&
522 git submodule update --merge submodule &&
523 git status -s submodule >actual &&
524 test_cmp expect actual
528 test_expect_success
'submodule update --rebase - ignores --rebase for new submodules' '
529 test_config -C super submodule.submodule.update checkout &&
532 git submodule update submodule &&
533 git status -s submodule >expect &&
535 git submodule update --rebase submodule &&
536 git status -s submodule >actual &&
537 test_cmp expect actual
541 test_expect_success
'submodule update ignores update=merge config for new submodules' '
544 git submodule update submodule &&
545 git status -s submodule >expect &&
547 git config submodule.submodule.update merge &&
548 git submodule update submodule &&
549 git status -s submodule >actual &&
550 git config --unset submodule.submodule.update &&
551 test_cmp expect actual
555 test_expect_success
'submodule update ignores update=rebase config for new submodules' '
558 git submodule update submodule &&
559 git status -s submodule >expect &&
561 git config submodule.submodule.update rebase &&
562 git submodule update submodule &&
563 git status -s submodule >actual &&
564 git config --unset submodule.submodule.update &&
565 test_cmp expect actual
569 test_expect_success
'submodule init picks up update=none' '
571 git config -f .gitmodules submodule.none.update none &&
572 git submodule init none &&
573 test "none" = "$(git config submodule.none.update)"
577 test_expect_success
'submodule update - update=none in .git/config' '
579 git config submodule.submodule.update none &&
581 git checkout master &&
584 git diff --name-only >out &&
585 grep ^submodule$ out &&
586 git submodule update &&
587 git diff --name-only >out &&
588 grep ^submodule$ out &&
592 git config --unset submodule.submodule.update &&
593 git submodule update submodule
597 test_expect_success
'submodule update - update=none in .git/config but --checkout given' '
599 git config submodule.submodule.update none &&
601 git checkout master &&
604 git diff --name-only >out &&
605 grep ^submodule$ out &&
606 git submodule update --checkout &&
607 git diff --name-only >out &&
608 ! grep ^submodule$ out &&
612 git config --unset submodule.submodule.update
616 test_expect_success
'submodule update --init skips submodule with update=none' '
618 git add .gitmodules &&
619 git commit -m ".gitmodules"
621 git clone super cloned &&
623 git submodule update --init &&
624 test_path_exists submodule/.git &&
625 test_path_is_missing none/.git
629 test_expect_success
'submodule update continues after checkout error' '
631 git reset --hard HEAD &&
632 git submodule add ../submodule submodule2 &&
633 git submodule init &&
634 git commit -am "new_submodule" &&
636 git rev-parse --verify HEAD >../expect
639 test_commit "update_submodule" file
642 test_commit "update_submodule2" file
645 git add submodule2 &&
646 git commit -m "two_new_submodule_commits" &&
650 git checkout HEAD^ &&
651 test_must_fail git submodule update &&
653 git rev-parse --verify HEAD >../actual
655 test_cmp expect actual
658 test_expect_success
'submodule update continues after recursive checkout error' '
660 git reset --hard HEAD &&
661 git checkout master &&
662 git submodule update &&
664 git submodule add ../submodule subsubmodule &&
665 git submodule init &&
666 git commit -m "new_subsubmodule"
669 git commit -m "update_submodule" &&
672 test_commit "update_subsubmodule" file
674 git add subsubmodule &&
675 test_commit "update_submodule_again" file &&
677 test_commit "update_subsubmodule_again" file
679 test_commit "update_submodule_again_again" file
682 git rev-parse --verify HEAD >../expect &&
683 test_commit "update_submodule2_again" file
686 git add submodule2 &&
687 git commit -m "new_commits" &&
688 git checkout HEAD^ &&
690 git checkout HEAD^ &&
695 test_must_fail git submodule update --recursive &&
697 git rev-parse --verify HEAD >../actual
699 test_cmp expect actual
703 test_expect_success
'submodule update exit immediately in case of merge conflict' '
705 git checkout master &&
706 git reset --hard HEAD &&
709 git reset --hard HEAD
712 git submodule update --recursive &&
714 test_commit "update_submodule_2" file
717 test_commit "update_submodule2_2" file
720 git add submodule2 &&
721 git commit -m "two_new_submodule_commits" &&
723 git checkout master &&
724 test_commit "conflict" file &&
725 echo "conflict" > file
727 git checkout HEAD^ &&
729 git rev-parse --verify HEAD >../expect
731 git config submodule.submodule.update merge &&
732 test_must_fail git submodule update &&
734 git rev-parse --verify HEAD >../actual
736 test_cmp expect actual
740 test_expect_success
'submodule update exit immediately after recursive rebase error' '
742 git checkout master &&
743 git reset --hard HEAD &&
745 git reset --hard HEAD &&
746 git submodule update --recursive
749 test_commit "update_submodule_3" file
752 test_commit "update_submodule2_3" file
755 git add submodule2 &&
756 git commit -m "two_new_submodule_commits" &&
758 git checkout master &&
759 test_commit "conflict2" file &&
760 echo "conflict" > file
762 git checkout HEAD^ &&
764 git rev-parse --verify HEAD >../expect
766 git config submodule.submodule.update rebase &&
767 test_must_fail git submodule update &&
769 git rev-parse --verify HEAD >../actual
771 test_cmp expect actual
775 test_expect_success
'add different submodules to the same path' '
777 git submodule add ../submodule s1 &&
778 test_must_fail git submodule add ../merging s1
782 test_expect_success
'submodule add places git-dir in superprojects git-dir' '
785 git submodule add ../submodule deeper/submodule &&
786 (cd deeper/submodule &&
787 git log > ../../expected
789 (cd .git/modules/deeper/submodule &&
790 git log > ../../../../actual
792 test_cmp expected actual
796 test_expect_success
'submodule update places git-dir in superprojects git-dir' '
798 git commit -m "added submodule"
800 git clone super super2 &&
802 git submodule init deeper/submodule &&
803 git submodule update &&
804 (cd deeper/submodule &&
805 git log > ../../expected
807 (cd .git/modules/deeper/submodule &&
808 git log > ../../../../actual
810 test_cmp expected actual
814 test_expect_success
'submodule add places git-dir in superprojects git-dir recursive' '
816 (cd deeper/submodule &&
817 git submodule add ../submodule subsubmodule &&
819 git log > ../../../expected
821 git commit -m "added subsubmodule" &&
824 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
825 git log > ../../../../../actual
827 git add deeper/submodule &&
828 git commit -m "update submodule" &&
830 test_cmp expected actual
834 test_expect_success
'submodule update places git-dir in superprojects git-dir recursive' '
835 mkdir super_update_r &&
836 (cd super_update_r &&
839 mkdir subsuper_update_r &&
840 (cd subsuper_update_r &&
843 mkdir subsubsuper_update_r &&
844 (cd subsubsuper_update_r &&
847 git clone subsubsuper_update_r subsubsuper_update_r2 &&
848 (cd subsubsuper_update_r2 &&
849 test_commit "update_subsubsuper" file &&
850 git push origin master
852 git clone subsuper_update_r subsuper_update_r2 &&
853 (cd subsuper_update_r2 &&
854 test_commit "update_subsuper" file &&
855 git submodule add ../subsubsuper_update_r subsubmodule &&
856 git commit -am "subsubmodule" &&
857 git push origin master
859 git clone super_update_r super_update_r2 &&
860 (cd super_update_r2 &&
861 test_commit "update_super" file &&
862 git submodule add ../subsuper_update_r submodule &&
863 git commit -am "submodule" &&
864 git push origin master
866 rm -rf super_update_r2 &&
867 git clone super_update_r super_update_r2 &&
868 (cd super_update_r2 &&
869 git submodule update --init --recursive >actual &&
870 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
871 (cd submodule/subsubmodule &&
872 git log > ../../expected
874 (cd .git/modules/submodule/modules/subsubmodule &&
875 git log > ../../../../../actual
877 test_cmp expected actual
881 test_expect_success
'submodule add properly re-creates deeper level submodules' '
883 git reset --hard master &&
885 git submodule add --force ../submodule deeper/submodule
889 test_expect_success
'submodule update properly revives a moved submodule' '
891 H=$(git rev-parse --short HEAD) &&
892 git commit -am "pre move" &&
893 H2=$(git rev-parse --short HEAD) &&
895 sed "s/$H/XXX/" out >expect &&
896 H=$(cd submodule2 && git rev-parse HEAD) &&
897 git rm --cached submodule2 &&
899 mkdir -p "moved/sub module" &&
900 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
901 git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
902 git commit -am "post move" &&
903 git submodule update &&
905 sed "s/$H2/XXX/" out >actual &&
906 test_cmp expect actual
910 test_expect_success SYMLINKS
'submodule update can handle symbolic links in pwd' '
911 mkdir -p linked/dir &&
912 ln -s linked/dir linkto &&
914 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
916 git submodule update --init --recursive
921 test_expect_success
'submodule update clone shallow submodule' '
922 test_when_finished "rm -rf super3" &&
923 first=$(git -C cloned rev-parse HEAD:submodule) &&
924 second=$(git -C submodule rev-parse HEAD) &&
925 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
926 git clone cloned super3 &&
930 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
931 mv -f .gitmodules.tmp .gitmodules &&
932 git submodule update --init --depth=$commit_count &&
933 git -C submodule log --oneline >out &&
934 test_line_count = 1 out
938 test_expect_success
'submodule update clone shallow submodule outside of depth' '
939 test_when_finished "rm -rf super3" &&
940 git clone cloned super3 &&
944 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
945 mv -f .gitmodules.tmp .gitmodules &&
946 test_must_fail git submodule update --init --depth=1 2>actual &&
947 test_i18ngrep "Direct fetching of that commit failed." actual &&
948 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
949 git submodule update --init --depth=1 >actual &&
950 git -C submodule log --oneline >out &&
951 test_line_count = 1 out
955 test_expect_success
'submodule update --recursive drops module name before recursing' '
957 (cd deeper/submodule/subsubmodule &&
960 git submodule update --recursive deeper/submodule >actual &&
961 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
965 test_expect_success
'submodule update can be run in parallel' '
967 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
968 grep "7 tasks" trace.out &&
969 git config submodule.fetchJobs 8 &&
970 GIT_TRACE=$(pwd)/trace.out git submodule update &&
971 grep "8 tasks" trace.out &&
972 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
973 grep "9 tasks" trace.out
977 test_expect_success
'git clone passes the parallel jobs config on to submodules' '
978 test_when_finished "rm -rf super4" &&
979 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
980 grep "7 tasks" trace.out &&
982 git config --global submodule.fetchJobs 8 &&
983 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
984 grep "8 tasks" trace.out &&
986 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
987 grep "9 tasks" trace.out &&