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 &&
347 test_expect_success
'submodule update - command in .git/config catches failure' '
349 git config submodule.submodule.update "!false"
351 (cd super/submodule &&
352 git reset --hard HEAD^
355 test_must_fail git submodule update submodule
359 test_expect_success
'submodule init does not copy command into .git/config' '
361 H=$(git ls-files -s submodule | cut -d" " -f2) &&
363 git update-index --add --cacheinfo 160000 $H submodule1 &&
364 git config -f .gitmodules submodule.submodule1.path submodule1 &&
365 git config -f .gitmodules submodule.submodule1.url ../submodule &&
366 git config -f .gitmodules submodule.submodule1.update !false &&
367 git submodule init submodule1 &&
368 echo "none" >expect &&
369 git config submodule.submodule1.update >actual &&
370 test_cmp expect actual
374 test_expect_success
'submodule init picks up rebase' '
376 git config -f .gitmodules submodule.rebasing.update rebase &&
377 git submodule init rebasing &&
378 test "rebase" = "$(git config submodule.rebasing.update)"
382 test_expect_success
'submodule init picks up merge' '
384 git config -f .gitmodules submodule.merging.update merge &&
385 git submodule init merging &&
386 test "merge" = "$(git config submodule.merging.update)"
390 test_expect_success
'submodule update --merge - ignores --merge for new submodules' '
393 git submodule update submodule &&
394 git status -s submodule >expect &&
396 git submodule update --merge submodule &&
397 git status -s submodule >actual &&
398 test_cmp expect actual
402 test_expect_success
'submodule update --rebase - ignores --rebase for new submodules' '
405 git submodule update submodule &&
406 git status -s submodule >expect &&
408 git submodule update --rebase submodule &&
409 git status -s submodule >actual &&
410 test_cmp expect actual
414 test_expect_success
'submodule update ignores update=merge config for new submodules' '
417 git submodule update submodule &&
418 git status -s submodule >expect &&
420 git config submodule.submodule.update merge &&
421 git submodule update submodule &&
422 git status -s submodule >actual &&
423 git config --unset submodule.submodule.update &&
424 test_cmp expect actual
428 test_expect_success
'submodule update ignores update=rebase config for new submodules' '
431 git submodule update submodule &&
432 git status -s submodule >expect &&
434 git config submodule.submodule.update rebase &&
435 git submodule update submodule &&
436 git status -s submodule >actual &&
437 git config --unset submodule.submodule.update &&
438 test_cmp expect actual
442 test_expect_success
'submodule init picks up update=none' '
444 git config -f .gitmodules submodule.none.update none &&
445 git submodule init none &&
446 test "none" = "$(git config submodule.none.update)"
450 test_expect_success
'submodule update - update=none in .git/config' '
452 git config submodule.submodule.update none &&
454 git checkout master &&
457 git diff --raw | grep " submodule" &&
458 git submodule update &&
459 git diff --raw | grep " submodule" &&
463 git config --unset submodule.submodule.update &&
464 git submodule update submodule
468 test_expect_success
'submodule update - update=none in .git/config but --checkout given' '
470 git config submodule.submodule.update none &&
472 git checkout master &&
475 git diff --raw | grep " submodule" &&
476 git submodule update --checkout &&
477 test_must_fail git diff --raw \| grep " submodule" &&
479 test_must_fail compare_head
481 git config --unset submodule.submodule.update
485 test_expect_success
'submodule update --init skips submodule with update=none' '
487 git add .gitmodules &&
488 git commit -m ".gitmodules"
490 git clone super cloned &&
492 git submodule update --init &&
493 test -e submodule/.git &&
494 test_must_fail test -e none/.git
498 test_expect_success
'submodule update continues after checkout error' '
500 git reset --hard HEAD &&
501 git submodule add ../submodule submodule2 &&
502 git submodule init &&
503 git commit -am "new_submodule" &&
505 git rev-parse --verify HEAD >../expect
508 test_commit "update_submodule" file
511 test_commit "update_submodule2" file
514 git add submodule2 &&
515 git commit -m "two_new_submodule_commits" &&
519 git checkout HEAD^ &&
520 test_must_fail git submodule update &&
522 git rev-parse --verify HEAD >../actual
524 test_cmp expect actual
527 test_expect_success
'submodule update continues after recursive checkout error' '
529 git reset --hard HEAD &&
530 git checkout master &&
531 git submodule update &&
533 git submodule add ../submodule subsubmodule &&
534 git submodule init &&
535 git commit -m "new_subsubmodule"
538 git commit -m "update_submodule" &&
541 test_commit "update_subsubmodule" file
543 git add subsubmodule &&
544 test_commit "update_submodule_again" file &&
546 test_commit "update_subsubmodule_again" file
548 test_commit "update_submodule_again_again" file
551 git rev-parse --verify HEAD >../expect &&
552 test_commit "update_submodule2_again" file
555 git add submodule2 &&
556 git commit -m "new_commits" &&
557 git checkout HEAD^ &&
559 git checkout HEAD^ &&
564 test_must_fail git submodule update --recursive &&
566 git rev-parse --verify HEAD >../actual
568 test_cmp expect actual
572 test_expect_success
'submodule update exit immediately in case of merge conflict' '
574 git checkout master &&
575 git reset --hard HEAD &&
578 git reset --hard HEAD
581 git submodule update --recursive &&
583 test_commit "update_submodule_2" file
586 test_commit "update_submodule2_2" file
589 git add submodule2 &&
590 git commit -m "two_new_submodule_commits" &&
592 git checkout master &&
593 test_commit "conflict" file &&
594 echo "conflict" > file
596 git checkout HEAD^ &&
598 git rev-parse --verify HEAD >../expect
600 git config submodule.submodule.update merge &&
601 test_must_fail git submodule update &&
603 git rev-parse --verify HEAD >../actual
605 test_cmp expect actual
609 test_expect_success
'submodule update exit immediately after recursive rebase error' '
611 git checkout master &&
612 git reset --hard HEAD &&
614 git reset --hard HEAD &&
615 git submodule update --recursive
618 test_commit "update_submodule_3" file
621 test_commit "update_submodule2_3" file
624 git add submodule2 &&
625 git commit -m "two_new_submodule_commits" &&
627 git checkout master &&
628 test_commit "conflict2" file &&
629 echo "conflict" > file
631 git checkout HEAD^ &&
633 git rev-parse --verify HEAD >../expect
635 git config submodule.submodule.update rebase &&
636 test_must_fail git submodule update &&
638 git rev-parse --verify HEAD >../actual
640 test_cmp expect actual
644 test_expect_success
'add different submodules to the same path' '
646 git submodule add ../submodule s1 &&
647 test_must_fail git submodule add ../merging s1
651 test_expect_success
'submodule add places git-dir in superprojects git-dir' '
654 git submodule add ../submodule deeper/submodule &&
655 (cd deeper/submodule &&
656 git log > ../../expected
658 (cd .git/modules/deeper/submodule &&
659 git log > ../../../../actual
661 test_cmp actual expected
665 test_expect_success
'submodule update places git-dir in superprojects git-dir' '
667 git commit -m "added submodule"
669 git clone super super2 &&
671 git submodule init deeper/submodule &&
672 git submodule update &&
673 (cd deeper/submodule &&
674 git log > ../../expected
676 (cd .git/modules/deeper/submodule &&
677 git log > ../../../../actual
679 test_cmp actual expected
683 test_expect_success
'submodule add places git-dir in superprojects git-dir recursive' '
685 (cd deeper/submodule &&
686 git submodule add ../submodule subsubmodule &&
688 git log > ../../../expected
690 git commit -m "added subsubmodule" &&
693 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
694 git log > ../../../../../actual
696 git add deeper/submodule &&
697 git commit -m "update submodule" &&
699 test_cmp actual expected
703 test_expect_success
'submodule update places git-dir in superprojects git-dir recursive' '
704 mkdir super_update_r &&
705 (cd super_update_r &&
708 mkdir subsuper_update_r &&
709 (cd subsuper_update_r &&
712 mkdir subsubsuper_update_r &&
713 (cd subsubsuper_update_r &&
716 git clone subsubsuper_update_r subsubsuper_update_r2 &&
717 (cd subsubsuper_update_r2 &&
718 test_commit "update_subsubsuper" file &&
719 git push origin master
721 git clone subsuper_update_r subsuper_update_r2 &&
722 (cd subsuper_update_r2 &&
723 test_commit "update_subsuper" file &&
724 git submodule add ../subsubsuper_update_r subsubmodule &&
725 git commit -am "subsubmodule" &&
726 git push origin master
728 git clone super_update_r super_update_r2 &&
729 (cd super_update_r2 &&
730 test_commit "update_super" file &&
731 git submodule add ../subsuper_update_r submodule &&
732 git commit -am "submodule" &&
733 git push origin master
735 rm -rf super_update_r2 &&
736 git clone super_update_r super_update_r2 &&
737 (cd super_update_r2 &&
738 git submodule update --init --recursive >actual &&
739 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
740 (cd submodule/subsubmodule &&
741 git log > ../../expected
743 (cd .git/modules/submodule/modules/subsubmodule
744 git log > ../../../../../actual
746 test_cmp actual expected
750 test_expect_success
'submodule add properly re-creates deeper level submodules' '
752 git reset --hard master &&
754 git submodule add --force ../submodule deeper/submodule
758 test_expect_success
'submodule update properly revives a moved submodule' '
760 H=$(git rev-parse --short HEAD) &&
761 git commit -am "pre move" &&
762 H2=$(git rev-parse --short HEAD) &&
763 git status | sed "s/$H/XXX/" >expect &&
764 H=$(cd submodule2; git rev-parse HEAD) &&
765 git rm --cached submodule2 &&
767 mkdir -p "moved/sub module" &&
768 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
769 git config -f .gitmodules submodule.submodule2.path "moved/sub module"
770 git commit -am "post move" &&
771 git submodule update &&
772 git status | sed "s/$H2/XXX/" >actual &&
773 test_cmp expect actual
777 test_expect_success SYMLINKS
'submodule update can handle symbolic links in pwd' '
778 mkdir -p linked/dir &&
779 ln -s linked/dir linkto &&
781 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
783 git submodule update --init --recursive
788 test_expect_success
'submodule update clone shallow submodule' '
789 git clone cloned super3 &&
792 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
793 mv -f .gitmodules.tmp .gitmodules &&
794 git submodule update --init --depth=3
796 test 1 = $(git log --oneline | wc -l)
801 test_expect_success
'submodule update --recursive drops module name before recursing' '
803 (cd deeper/submodule/subsubmodule &&
806 git submodule update --recursive deeper/submodule >actual &&
807 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual