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 &&
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 Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
119 Submodule 'none' ($pwd/none) registered for path '../super/none'
120 Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
121 Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
122 Cloning into '$pwd/recursivesuper/super/merging'...
124 Cloning into '$pwd/recursivesuper/super/none'...
126 Cloning into '$pwd/recursivesuper/super/rebasing'...
128 Cloning into '$pwd/recursivesuper/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 test_i18ncmp expect2 actual2
144 test_expect_success
'submodule update does not fetch already present commits' '
146 echo line3 >> file &&
149 git commit -m "upstream line3"
151 (cd super/submodule &&
152 head=$(git rev-parse --verify HEAD) &&
153 echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
154 git reset --hard HEAD~1
157 git submodule update > ../actual 2> ../actual.err
159 test_i18ncmp expected actual &&
163 test_expect_success
'submodule update should fail due to local changes' '
164 (cd super/submodule &&
165 git reset --hard HEAD~1 &&
166 echo "local change" > file
172 test_must_fail git submodule update submodule
175 test_expect_success
'submodule update should throw away changes with --force ' '
180 git submodule update --force submodule &&
186 test_expect_success
'submodule update --force forcibly checks out submodules' '
191 git submodule update --force submodule &&
193 test "$(git status -s file)" = ""
198 test_expect_success
'submodule update --remote should fetch upstream changes' '
200 echo line4 >> file &&
203 git commit -m "upstream line4"
206 git submodule update --remote --force submodule &&
208 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
212 test_expect_success
'submodule update --remote should fetch upstream changes with .' '
215 git config -f .gitmodules submodule."submodule".branch "." &&
216 git add .gitmodules &&
217 git commit -m "submodules: update from the respective superproject branch"
221 echo line4a >> file &&
224 git commit -m "upstream line4a" &&
225 git checkout -b test-branch &&
226 test_commit on-test-branch
230 git submodule update --remote --force submodule &&
231 git -C submodule log -1 --oneline >actual
232 git -C ../submodule log -1 --oneline master >expect
233 test_cmp expect actual &&
234 git checkout -b test-branch &&
235 git submodule update --remote --force submodule &&
236 git -C submodule log -1 --oneline >actual
237 git -C ../submodule log -1 --oneline test-branch >expect
238 test_cmp expect actual &&
239 git checkout master &&
240 git branch -d test-branch &&
241 git reset --hard HEAD^
245 test_expect_success
'local config should override .gitmodules branch' '
247 git checkout test-branch &&
248 echo line5 >> file &&
251 git commit -m "upstream line5" &&
255 git config submodule.submodule.branch test-branch &&
256 git submodule update --remote --force submodule &&
258 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
262 test_expect_success
'submodule update --rebase staying on master' '
263 (cd super/submodule &&
270 git submodule update --rebase submodule &&
276 test_expect_success
'submodule update --merge staying on master' '
277 (cd super/submodule &&
278 git reset --hard HEAD~1
284 git submodule update --merge submodule &&
290 test_expect_success
'submodule update - rebase in .git/config' '
292 git config submodule.submodule.update rebase
294 (cd super/submodule &&
295 git reset --hard HEAD~1
301 git submodule update submodule &&
307 test_expect_success
'submodule update - checkout in .git/config but --rebase given' '
309 git config submodule.submodule.update checkout
311 (cd super/submodule &&
312 git reset --hard HEAD~1
318 git submodule update --rebase submodule &&
324 test_expect_success
'submodule update - merge in .git/config' '
326 git config submodule.submodule.update merge
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 --merge given' '
343 git config submodule.submodule.update checkout
345 (cd super/submodule &&
346 git reset --hard HEAD~1
352 git submodule update --merge submodule &&
358 test_expect_success
'submodule update - checkout in .git/config' '
360 git config submodule.submodule.update checkout
362 (cd super/submodule &&
363 git reset --hard HEAD^
369 git submodule update submodule &&
375 test_expect_success
'submodule update - command in .git/config' '
377 git config submodule.submodule.update "!git checkout"
379 (cd super/submodule &&
380 git reset --hard HEAD^
386 git submodule update submodule &&
393 Execution of 'false $submodulesha1' failed in submodule path 'submodule'
396 test_expect_success
'submodule update - command in .git/config catches failure' '
398 git config submodule.submodule.update "!false"
400 (cd super/submodule &&
401 git reset --hard $submodulesha1^
404 test_must_fail git submodule update submodule 2>../actual
406 test_i18ncmp actual expect
410 Execution of 'false $submodulesha1' failed in submodule path '../submodule'
413 test_expect_success
'submodule update - command in .git/config catches failure -- subdirectory' '
415 git config submodule.submodule.update "!false"
417 (cd super/submodule &&
418 git reset --hard $submodulesha1^
421 mkdir tmp && cd tmp &&
422 test_must_fail git submodule update ../submodule 2>../../actual
424 test_i18ncmp actual expect
428 Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
429 Failed to recurse into submodule path '../super'
432 test_expect_success
'recursive submodule update - command in .git/config catches failure -- subdirectory' '
433 (cd recursivesuper &&
434 git submodule update --remote super &&
436 git commit -m "update to latest to have more than one commit in submodules"
438 git -C recursivesuper/super config submodule.submodule.update "!false" &&
439 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
440 (cd recursivesuper &&
441 mkdir -p tmp && cd tmp &&
442 test_must_fail git submodule update --recursive ../super 2>../../actual
444 test_i18ncmp actual expect
447 test_expect_success
'submodule init does not copy command into .git/config' '
449 H=$(git ls-files -s submodule | cut -d" " -f2) &&
451 git update-index --add --cacheinfo 160000 $H submodule1 &&
452 git config -f .gitmodules submodule.submodule1.path submodule1 &&
453 git config -f .gitmodules submodule.submodule1.url ../submodule &&
454 git config -f .gitmodules submodule.submodule1.update !false &&
455 git submodule init submodule1 &&
456 echo "none" >expect &&
457 git config submodule.submodule1.update >actual &&
458 test_cmp expect actual
462 test_expect_success
'submodule init picks up rebase' '
464 git config -f .gitmodules submodule.rebasing.update rebase &&
465 git submodule init rebasing &&
466 test "rebase" = "$(git config submodule.rebasing.update)"
470 test_expect_success
'submodule init picks up merge' '
472 git config -f .gitmodules submodule.merging.update merge &&
473 git submodule init merging &&
474 test "merge" = "$(git config submodule.merging.update)"
478 test_expect_success
'submodule update --merge - ignores --merge for new submodules' '
481 git submodule update submodule &&
482 git status -s submodule >expect &&
484 git submodule update --merge submodule &&
485 git status -s submodule >actual &&
486 test_cmp expect actual
490 test_expect_success
'submodule update --rebase - ignores --rebase for new submodules' '
493 git submodule update submodule &&
494 git status -s submodule >expect &&
496 git submodule update --rebase submodule &&
497 git status -s submodule >actual &&
498 test_cmp expect actual
502 test_expect_success
'submodule update ignores update=merge config for new submodules' '
505 git submodule update submodule &&
506 git status -s submodule >expect &&
508 git config submodule.submodule.update merge &&
509 git submodule update submodule &&
510 git status -s submodule >actual &&
511 git config --unset submodule.submodule.update &&
512 test_cmp expect actual
516 test_expect_success
'submodule update ignores update=rebase config for new submodules' '
519 git submodule update submodule &&
520 git status -s submodule >expect &&
522 git config submodule.submodule.update rebase &&
523 git submodule update submodule &&
524 git status -s submodule >actual &&
525 git config --unset submodule.submodule.update &&
526 test_cmp expect actual
530 test_expect_success
'submodule init picks up update=none' '
532 git config -f .gitmodules submodule.none.update none &&
533 git submodule init none &&
534 test "none" = "$(git config submodule.none.update)"
538 test_expect_success
'submodule update - update=none in .git/config' '
540 git config submodule.submodule.update none &&
542 git checkout master &&
545 git diff --raw | grep " submodule" &&
546 git submodule update &&
547 git diff --raw | grep " submodule" &&
551 git config --unset submodule.submodule.update &&
552 git submodule update submodule
556 test_expect_success
'submodule update - update=none in .git/config but --checkout given' '
558 git config submodule.submodule.update none &&
560 git checkout master &&
563 git diff --raw | grep " submodule" &&
564 git submodule update --checkout &&
565 test_must_fail git diff --raw \| grep " submodule" &&
567 test_must_fail compare_head
569 git config --unset submodule.submodule.update
573 test_expect_success
'submodule update --init skips submodule with update=none' '
575 git add .gitmodules &&
576 git commit -m ".gitmodules"
578 git clone super cloned &&
580 git submodule update --init &&
581 test -e submodule/.git &&
582 test_must_fail test -e none/.git
586 test_expect_success
'submodule update continues after checkout error' '
588 git reset --hard HEAD &&
589 git submodule add ../submodule submodule2 &&
590 git submodule init &&
591 git commit -am "new_submodule" &&
593 git rev-parse --verify HEAD >../expect
596 test_commit "update_submodule" file
599 test_commit "update_submodule2" file
602 git add submodule2 &&
603 git commit -m "two_new_submodule_commits" &&
607 git checkout HEAD^ &&
608 test_must_fail git submodule update &&
610 git rev-parse --verify HEAD >../actual
612 test_cmp expect actual
615 test_expect_success
'submodule update continues after recursive checkout error' '
617 git reset --hard HEAD &&
618 git checkout master &&
619 git submodule update &&
621 git submodule add ../submodule subsubmodule &&
622 git submodule init &&
623 git commit -m "new_subsubmodule"
626 git commit -m "update_submodule" &&
629 test_commit "update_subsubmodule" file
631 git add subsubmodule &&
632 test_commit "update_submodule_again" file &&
634 test_commit "update_subsubmodule_again" file
636 test_commit "update_submodule_again_again" file
639 git rev-parse --verify HEAD >../expect &&
640 test_commit "update_submodule2_again" file
643 git add submodule2 &&
644 git commit -m "new_commits" &&
645 git checkout HEAD^ &&
647 git checkout HEAD^ &&
652 test_must_fail git submodule update --recursive &&
654 git rev-parse --verify HEAD >../actual
656 test_cmp expect actual
660 test_expect_success
'submodule update exit immediately in case of merge conflict' '
662 git checkout master &&
663 git reset --hard HEAD &&
666 git reset --hard HEAD
669 git submodule update --recursive &&
671 test_commit "update_submodule_2" file
674 test_commit "update_submodule2_2" file
677 git add submodule2 &&
678 git commit -m "two_new_submodule_commits" &&
680 git checkout master &&
681 test_commit "conflict" file &&
682 echo "conflict" > file
684 git checkout HEAD^ &&
686 git rev-parse --verify HEAD >../expect
688 git config submodule.submodule.update merge &&
689 test_must_fail git submodule update &&
691 git rev-parse --verify HEAD >../actual
693 test_cmp expect actual
697 test_expect_success
'submodule update exit immediately after recursive rebase error' '
699 git checkout master &&
700 git reset --hard HEAD &&
702 git reset --hard HEAD &&
703 git submodule update --recursive
706 test_commit "update_submodule_3" file
709 test_commit "update_submodule2_3" file
712 git add submodule2 &&
713 git commit -m "two_new_submodule_commits" &&
715 git checkout master &&
716 test_commit "conflict2" file &&
717 echo "conflict" > file
719 git checkout HEAD^ &&
721 git rev-parse --verify HEAD >../expect
723 git config submodule.submodule.update rebase &&
724 test_must_fail git submodule update &&
726 git rev-parse --verify HEAD >../actual
728 test_cmp expect actual
732 test_expect_success
'add different submodules to the same path' '
734 git submodule add ../submodule s1 &&
735 test_must_fail git submodule add ../merging s1
739 test_expect_success
'submodule add places git-dir in superprojects git-dir' '
742 git submodule add ../submodule deeper/submodule &&
743 (cd deeper/submodule &&
744 git log > ../../expected
746 (cd .git/modules/deeper/submodule &&
747 git log > ../../../../actual
749 test_cmp actual expected
753 test_expect_success
'submodule update places git-dir in superprojects git-dir' '
755 git commit -m "added submodule"
757 git clone super super2 &&
759 git submodule init deeper/submodule &&
760 git submodule update &&
761 (cd deeper/submodule &&
762 git log > ../../expected
764 (cd .git/modules/deeper/submodule &&
765 git log > ../../../../actual
767 test_cmp actual expected
771 test_expect_success
'submodule add places git-dir in superprojects git-dir recursive' '
773 (cd deeper/submodule &&
774 git submodule add ../submodule subsubmodule &&
776 git log > ../../../expected
778 git commit -m "added subsubmodule" &&
781 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
782 git log > ../../../../../actual
784 git add deeper/submodule &&
785 git commit -m "update submodule" &&
787 test_cmp actual expected
791 test_expect_success
'submodule update places git-dir in superprojects git-dir recursive' '
792 mkdir super_update_r &&
793 (cd super_update_r &&
796 mkdir subsuper_update_r &&
797 (cd subsuper_update_r &&
800 mkdir subsubsuper_update_r &&
801 (cd subsubsuper_update_r &&
804 git clone subsubsuper_update_r subsubsuper_update_r2 &&
805 (cd subsubsuper_update_r2 &&
806 test_commit "update_subsubsuper" file &&
807 git push origin master
809 git clone subsuper_update_r subsuper_update_r2 &&
810 (cd subsuper_update_r2 &&
811 test_commit "update_subsuper" file &&
812 git submodule add ../subsubsuper_update_r subsubmodule &&
813 git commit -am "subsubmodule" &&
814 git push origin master
816 git clone super_update_r super_update_r2 &&
817 (cd super_update_r2 &&
818 test_commit "update_super" file &&
819 git submodule add ../subsuper_update_r submodule &&
820 git commit -am "submodule" &&
821 git push origin master
823 rm -rf super_update_r2 &&
824 git clone super_update_r super_update_r2 &&
825 (cd super_update_r2 &&
826 git submodule update --init --recursive >actual &&
827 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
828 (cd submodule/subsubmodule &&
829 git log > ../../expected
831 (cd .git/modules/submodule/modules/subsubmodule
832 git log > ../../../../../actual
834 test_cmp actual expected
838 test_expect_success
'submodule add properly re-creates deeper level submodules' '
840 git reset --hard master &&
842 git submodule add --force ../submodule deeper/submodule
846 test_expect_success
'submodule update properly revives a moved submodule' '
848 H=$(git rev-parse --short HEAD) &&
849 git commit -am "pre move" &&
850 H2=$(git rev-parse --short HEAD) &&
851 git status | sed "s/$H/XXX/" >expect &&
852 H=$(cd submodule2; git rev-parse HEAD) &&
853 git rm --cached submodule2 &&
855 mkdir -p "moved/sub module" &&
856 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
857 git config -f .gitmodules submodule.submodule2.path "moved/sub module"
858 git commit -am "post move" &&
859 git submodule update &&
860 git status | sed "s/$H2/XXX/" >actual &&
861 test_cmp expect actual
865 test_expect_success SYMLINKS
'submodule update can handle symbolic links in pwd' '
866 mkdir -p linked/dir &&
867 ln -s linked/dir linkto &&
869 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
871 git submodule update --init --recursive
876 test_expect_success
'submodule update clone shallow submodule' '
877 test_when_finished "rm -rf super3" &&
878 first=$(git -C cloned submodule status submodule |cut -c2-41) &&
879 second=$(git -C submodule rev-parse HEAD) &&
880 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
881 git clone cloned super3 &&
885 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
886 mv -f .gitmodules.tmp .gitmodules &&
887 git submodule update --init --depth=$commit_count &&
888 test 1 = $(git -C submodule log --oneline | wc -l)
892 test_expect_success
'submodule update clone shallow submodule outside of depth' '
893 test_when_finished "rm -rf super3" &&
894 git clone cloned super3 &&
898 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
899 mv -f .gitmodules.tmp .gitmodules &&
900 test_must_fail git submodule update --init --depth=1 2>actual &&
901 test_i18ngrep "Direct fetching of that commit failed." actual &&
902 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
903 git submodule update --init --depth=1 >actual &&
904 test 1 = $(git -C submodule log --oneline | wc -l)
908 test_expect_success
'submodule update --recursive drops module name before recursing' '
910 (cd deeper/submodule/subsubmodule &&
913 git submodule update --recursive deeper/submodule >actual &&
914 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
918 test_expect_success
'submodule update can be run in parallel' '
920 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
921 grep "7 tasks" trace.out &&
922 git config submodule.fetchJobs 8 &&
923 GIT_TRACE=$(pwd)/trace.out git submodule update &&
924 grep "8 tasks" trace.out &&
925 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
926 grep "9 tasks" trace.out
930 test_expect_success
'git clone passes the parallel jobs config on to submodules' '
931 test_when_finished "rm -rf super4" &&
932 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
933 grep "7 tasks" trace.out &&
935 git config --global submodule.fetchJobs 8 &&
936 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
937 grep "8 tasks" trace.out &&
939 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
940 grep "9 tasks" trace.out &&