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 'merging' ($pwd/merging) registered for path '../super/merging'
112 Submodule 'none' ($pwd/none) registered for path '../super/none'
113 Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
114 Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
115 Submodule path '../super/merging': checked out '$mergingsha1'
116 Submodule path '../super/none': checked out '$nonesha1'
117 Submodule path '../super/rebasing': checked out '$rebasingsha1'
118 Submodule path '../super/submodule': checked out '$submodulesha1'
121 test_expect_success
'submodule update --init --recursive from subdirectory' '
122 git -C recursivesuper/super reset --hard HEAD^ &&
123 (cd recursivesuper &&
126 git submodule update --init --recursive ../super >../../actual
128 test_cmp expect actual
132 test_expect_success
'submodule update does not fetch already present commits' '
134 echo line3 >> file &&
137 git commit -m "upstream line3"
139 (cd super/submodule &&
140 head=$(git rev-parse --verify HEAD) &&
141 echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
142 git reset --hard HEAD~1
145 git submodule update > ../actual 2> ../actual.err
147 test_i18ncmp expected actual &&
151 test_expect_success
'submodule update should fail due to local changes' '
152 (cd super/submodule &&
153 git reset --hard HEAD~1 &&
154 echo "local change" > file
160 test_must_fail git submodule update submodule
163 test_expect_success
'submodule update should throw away changes with --force ' '
168 git submodule update --force submodule &&
174 test_expect_success
'submodule update --force forcibly checks out submodules' '
179 git submodule update --force submodule &&
181 test "$(git status -s file)" = ""
186 test_expect_success
'submodule update --remote should fetch upstream changes' '
188 echo line4 >> file &&
191 git commit -m "upstream line4"
194 git submodule update --remote --force submodule &&
196 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
200 test_expect_success
'local config should override .gitmodules branch' '
202 git checkout -b test-branch &&
203 echo line5 >> file &&
206 git commit -m "upstream line5" &&
210 git config submodule.submodule.branch test-branch &&
211 git submodule update --remote --force submodule &&
213 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
217 test_expect_success
'submodule update --rebase staying on master' '
218 (cd super/submodule &&
225 git submodule update --rebase submodule &&
231 test_expect_success
'submodule update --merge staying on master' '
232 (cd super/submodule &&
233 git reset --hard HEAD~1
239 git submodule update --merge submodule &&
245 test_expect_success
'submodule update - rebase in .git/config' '
247 git config submodule.submodule.update rebase
249 (cd super/submodule &&
250 git reset --hard HEAD~1
256 git submodule update submodule &&
262 test_expect_success
'submodule update - checkout in .git/config but --rebase given' '
264 git config submodule.submodule.update checkout
266 (cd super/submodule &&
267 git reset --hard HEAD~1
273 git submodule update --rebase submodule &&
279 test_expect_success
'submodule update - merge in .git/config' '
281 git config submodule.submodule.update merge
283 (cd super/submodule &&
284 git reset --hard HEAD~1
290 git submodule update submodule &&
296 test_expect_success
'submodule update - checkout in .git/config but --merge given' '
298 git config submodule.submodule.update checkout
300 (cd super/submodule &&
301 git reset --hard HEAD~1
307 git submodule update --merge submodule &&
313 test_expect_success
'submodule update - checkout in .git/config' '
315 git config submodule.submodule.update checkout
317 (cd super/submodule &&
318 git reset --hard HEAD^
324 git submodule update submodule &&
330 test_expect_success
'submodule update - command in .git/config' '
332 git config submodule.submodule.update "!git checkout"
334 (cd super/submodule &&
335 git reset --hard HEAD^
341 git submodule update submodule &&
348 Execution of 'false $submodulesha1' failed in submodule path 'submodule'
351 test_expect_success
'submodule update - command in .git/config catches failure' '
353 git config submodule.submodule.update "!false"
355 (cd super/submodule &&
356 git reset --hard $submodulesha1^
359 test_must_fail git submodule update submodule 2>../actual
361 test_cmp actual expect
365 Execution of 'false $submodulesha1' failed in submodule path '../submodule'
368 test_expect_success
'submodule update - command in .git/config catches failure -- subdirectory' '
370 git config submodule.submodule.update "!false"
372 (cd super/submodule &&
373 git reset --hard $submodulesha1^
376 mkdir tmp && cd tmp &&
377 test_must_fail git submodule update ../submodule 2>../../actual
379 test_cmp actual expect
383 Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
384 Failed to recurse into submodule path '../super'
387 test_expect_success
'recursive submodule update - command in .git/config catches failure -- subdirectory' '
388 (cd recursivesuper &&
389 git submodule update --remote super &&
391 git commit -m "update to latest to have more than one commit in submodules"
393 git -C recursivesuper/super config submodule.submodule.update "!false" &&
394 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
395 (cd recursivesuper &&
396 mkdir -p tmp && cd tmp &&
397 test_must_fail git submodule update --recursive ../super 2>../../actual
399 test_cmp actual expect
402 test_expect_success
'submodule init does not copy command into .git/config' '
404 H=$(git ls-files -s submodule | cut -d" " -f2) &&
406 git update-index --add --cacheinfo 160000 $H submodule1 &&
407 git config -f .gitmodules submodule.submodule1.path submodule1 &&
408 git config -f .gitmodules submodule.submodule1.url ../submodule &&
409 git config -f .gitmodules submodule.submodule1.update !false &&
410 git submodule init submodule1 &&
411 echo "none" >expect &&
412 git config submodule.submodule1.update >actual &&
413 test_cmp expect actual
417 test_expect_success
'submodule init picks up rebase' '
419 git config -f .gitmodules submodule.rebasing.update rebase &&
420 git submodule init rebasing &&
421 test "rebase" = "$(git config submodule.rebasing.update)"
425 test_expect_success
'submodule init picks up merge' '
427 git config -f .gitmodules submodule.merging.update merge &&
428 git submodule init merging &&
429 test "merge" = "$(git config submodule.merging.update)"
433 test_expect_success
'submodule update --merge - ignores --merge for new submodules' '
436 git submodule update submodule &&
437 git status -s submodule >expect &&
439 git submodule update --merge submodule &&
440 git status -s submodule >actual &&
441 test_cmp expect actual
445 test_expect_success
'submodule update --rebase - ignores --rebase for new submodules' '
448 git submodule update submodule &&
449 git status -s submodule >expect &&
451 git submodule update --rebase submodule &&
452 git status -s submodule >actual &&
453 test_cmp expect actual
457 test_expect_success
'submodule update ignores update=merge config for new submodules' '
460 git submodule update submodule &&
461 git status -s submodule >expect &&
463 git config submodule.submodule.update merge &&
464 git submodule update submodule &&
465 git status -s submodule >actual &&
466 git config --unset submodule.submodule.update &&
467 test_cmp expect actual
471 test_expect_success
'submodule update ignores update=rebase config for new submodules' '
474 git submodule update submodule &&
475 git status -s submodule >expect &&
477 git config submodule.submodule.update rebase &&
478 git submodule update submodule &&
479 git status -s submodule >actual &&
480 git config --unset submodule.submodule.update &&
481 test_cmp expect actual
485 test_expect_success
'submodule init picks up update=none' '
487 git config -f .gitmodules submodule.none.update none &&
488 git submodule init none &&
489 test "none" = "$(git config submodule.none.update)"
493 test_expect_success
'submodule update - update=none in .git/config' '
495 git config submodule.submodule.update none &&
497 git checkout master &&
500 git diff --raw | grep " submodule" &&
501 git submodule update &&
502 git diff --raw | grep " submodule" &&
506 git config --unset submodule.submodule.update &&
507 git submodule update submodule
511 test_expect_success
'submodule update - update=none in .git/config but --checkout given' '
513 git config submodule.submodule.update none &&
515 git checkout master &&
518 git diff --raw | grep " submodule" &&
519 git submodule update --checkout &&
520 test_must_fail git diff --raw \| grep " submodule" &&
522 test_must_fail compare_head
524 git config --unset submodule.submodule.update
528 test_expect_success
'submodule update --init skips submodule with update=none' '
530 git add .gitmodules &&
531 git commit -m ".gitmodules"
533 git clone super cloned &&
535 git submodule update --init &&
536 test -e submodule/.git &&
537 test_must_fail test -e none/.git
541 test_expect_success
'submodule update continues after checkout error' '
543 git reset --hard HEAD &&
544 git submodule add ../submodule submodule2 &&
545 git submodule init &&
546 git commit -am "new_submodule" &&
548 git rev-parse --verify HEAD >../expect
551 test_commit "update_submodule" file
554 test_commit "update_submodule2" file
557 git add submodule2 &&
558 git commit -m "two_new_submodule_commits" &&
562 git checkout HEAD^ &&
563 test_must_fail git submodule update &&
565 git rev-parse --verify HEAD >../actual
567 test_cmp expect actual
570 test_expect_success
'submodule update continues after recursive checkout error' '
572 git reset --hard HEAD &&
573 git checkout master &&
574 git submodule update &&
576 git submodule add ../submodule subsubmodule &&
577 git submodule init &&
578 git commit -m "new_subsubmodule"
581 git commit -m "update_submodule" &&
584 test_commit "update_subsubmodule" file
586 git add subsubmodule &&
587 test_commit "update_submodule_again" file &&
589 test_commit "update_subsubmodule_again" file
591 test_commit "update_submodule_again_again" file
594 git rev-parse --verify HEAD >../expect &&
595 test_commit "update_submodule2_again" file
598 git add submodule2 &&
599 git commit -m "new_commits" &&
600 git checkout HEAD^ &&
602 git checkout HEAD^ &&
607 test_must_fail git submodule update --recursive &&
609 git rev-parse --verify HEAD >../actual
611 test_cmp expect actual
615 test_expect_success
'submodule update exit immediately in case of merge conflict' '
617 git checkout master &&
618 git reset --hard HEAD &&
621 git reset --hard HEAD
624 git submodule update --recursive &&
626 test_commit "update_submodule_2" file
629 test_commit "update_submodule2_2" file
632 git add submodule2 &&
633 git commit -m "two_new_submodule_commits" &&
635 git checkout master &&
636 test_commit "conflict" file &&
637 echo "conflict" > file
639 git checkout HEAD^ &&
641 git rev-parse --verify HEAD >../expect
643 git config submodule.submodule.update merge &&
644 test_must_fail git submodule update &&
646 git rev-parse --verify HEAD >../actual
648 test_cmp expect actual
652 test_expect_success
'submodule update exit immediately after recursive rebase error' '
654 git checkout master &&
655 git reset --hard HEAD &&
657 git reset --hard HEAD &&
658 git submodule update --recursive
661 test_commit "update_submodule_3" file
664 test_commit "update_submodule2_3" file
667 git add submodule2 &&
668 git commit -m "two_new_submodule_commits" &&
670 git checkout master &&
671 test_commit "conflict2" file &&
672 echo "conflict" > file
674 git checkout HEAD^ &&
676 git rev-parse --verify HEAD >../expect
678 git config submodule.submodule.update rebase &&
679 test_must_fail git submodule update &&
681 git rev-parse --verify HEAD >../actual
683 test_cmp expect actual
687 test_expect_success
'add different submodules to the same path' '
689 git submodule add ../submodule s1 &&
690 test_must_fail git submodule add ../merging s1
694 test_expect_success
'submodule add places git-dir in superprojects git-dir' '
697 git submodule add ../submodule deeper/submodule &&
698 (cd deeper/submodule &&
699 git log > ../../expected
701 (cd .git/modules/deeper/submodule &&
702 git log > ../../../../actual
704 test_cmp actual expected
708 test_expect_success
'submodule update places git-dir in superprojects git-dir' '
710 git commit -m "added submodule"
712 git clone super super2 &&
714 git submodule init deeper/submodule &&
715 git submodule update &&
716 (cd deeper/submodule &&
717 git log > ../../expected
719 (cd .git/modules/deeper/submodule &&
720 git log > ../../../../actual
722 test_cmp actual expected
726 test_expect_success
'submodule add places git-dir in superprojects git-dir recursive' '
728 (cd deeper/submodule &&
729 git submodule add ../submodule subsubmodule &&
731 git log > ../../../expected
733 git commit -m "added subsubmodule" &&
736 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
737 git log > ../../../../../actual
739 git add deeper/submodule &&
740 git commit -m "update submodule" &&
742 test_cmp actual expected
746 test_expect_success
'submodule update places git-dir in superprojects git-dir recursive' '
747 mkdir super_update_r &&
748 (cd super_update_r &&
751 mkdir subsuper_update_r &&
752 (cd subsuper_update_r &&
755 mkdir subsubsuper_update_r &&
756 (cd subsubsuper_update_r &&
759 git clone subsubsuper_update_r subsubsuper_update_r2 &&
760 (cd subsubsuper_update_r2 &&
761 test_commit "update_subsubsuper" file &&
762 git push origin master
764 git clone subsuper_update_r subsuper_update_r2 &&
765 (cd subsuper_update_r2 &&
766 test_commit "update_subsuper" file &&
767 git submodule add ../subsubsuper_update_r subsubmodule &&
768 git commit -am "subsubmodule" &&
769 git push origin master
771 git clone super_update_r super_update_r2 &&
772 (cd super_update_r2 &&
773 test_commit "update_super" file &&
774 git submodule add ../subsuper_update_r submodule &&
775 git commit -am "submodule" &&
776 git push origin master
778 rm -rf super_update_r2 &&
779 git clone super_update_r super_update_r2 &&
780 (cd super_update_r2 &&
781 git submodule update --init --recursive >actual &&
782 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
783 (cd submodule/subsubmodule &&
784 git log > ../../expected
786 (cd .git/modules/submodule/modules/subsubmodule
787 git log > ../../../../../actual
789 test_cmp actual expected
793 test_expect_success
'submodule add properly re-creates deeper level submodules' '
795 git reset --hard master &&
797 git submodule add --force ../submodule deeper/submodule
801 test_expect_success
'submodule update properly revives a moved submodule' '
803 H=$(git rev-parse --short HEAD) &&
804 git commit -am "pre move" &&
805 H2=$(git rev-parse --short HEAD) &&
806 git status | sed "s/$H/XXX/" >expect &&
807 H=$(cd submodule2; git rev-parse HEAD) &&
808 git rm --cached submodule2 &&
810 mkdir -p "moved/sub module" &&
811 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
812 git config -f .gitmodules submodule.submodule2.path "moved/sub module"
813 git commit -am "post move" &&
814 git submodule update &&
815 git status | sed "s/$H2/XXX/" >actual &&
816 test_cmp expect actual
820 test_expect_success SYMLINKS
'submodule update can handle symbolic links in pwd' '
821 mkdir -p linked/dir &&
822 ln -s linked/dir linkto &&
824 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
826 git submodule update --init --recursive
831 test_expect_success
'submodule update clone shallow submodule' '
832 git clone cloned super3 &&
835 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
836 mv -f .gitmodules.tmp .gitmodules &&
837 git submodule update --init --depth=3
839 test 1 = $(git log --oneline | wc -l)
844 test_expect_success
'submodule update --recursive drops module name before recursing' '
846 (cd deeper/submodule/subsubmodule &&
849 git submodule update --recursive deeper/submodule >actual &&
850 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
854 test_expect_success
'submodule update can be run in parallel' '
856 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
857 grep "7 tasks" trace.out &&
858 git config submodule.fetchJobs 8 &&
859 GIT_TRACE=$(pwd)/trace.out git submodule update &&
860 grep "8 tasks" trace.out &&
861 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
862 grep "9 tasks" trace.out
866 test_expect_success
'git clone passes the parallel jobs config on to submodules' '
867 test_when_finished "rm -rf super4" &&
868 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
869 grep "7 tasks" trace.out &&
871 git config --global submodule.fetchJobs 8 &&
872 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
873 grep "8 tasks" trace.out &&
875 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
876 grep "9 tasks" trace.out &&