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 &&
69 test_expect_success
'submodule update detaching the HEAD ' '
70 (cd super/submodule &&
71 git reset --hard HEAD~1
77 git submodule update submodule &&
83 test_expect_success
'submodule update from subdirectory' '
84 (cd super/submodule &&
85 git reset --hard HEAD~1
92 git submodule update ../submodule &&
99 test_expect_success
'submodule update does not fetch already present commits' '
101 echo line3 >> file &&
104 git commit -m "upstream line3"
106 (cd super/submodule &&
107 head=$(git rev-parse --verify HEAD) &&
108 echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
109 git reset --hard HEAD~1
112 git submodule update > ../actual 2> ../actual.err
114 test_i18ncmp expected actual &&
118 test_expect_success
'submodule update should fail due to local changes' '
119 (cd super/submodule &&
120 git reset --hard HEAD~1 &&
121 echo "local change" > file
127 test_must_fail git submodule update submodule
130 test_expect_success
'submodule update should throw away changes with --force ' '
135 git submodule update --force submodule &&
141 test_expect_success
'submodule update --force forcibly checks out submodules' '
146 git submodule update --force submodule &&
148 test "$(git status -s file)" = ""
153 test_expect_success
'submodule update --remote should fetch upstream changes' '
155 echo line4 >> file &&
158 git commit -m "upstream line4"
161 git submodule update --remote --force submodule &&
163 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
167 test_expect_success
'local config should override .gitmodules branch' '
169 git checkout -b test-branch &&
170 echo line5 >> file &&
173 git commit -m "upstream line5" &&
177 git config submodule.submodule.branch test-branch &&
178 git submodule update --remote --force submodule &&
180 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
184 test_expect_success
'submodule update --rebase staying on master' '
185 (cd super/submodule &&
192 git submodule update --rebase submodule &&
198 test_expect_success
'submodule update --merge staying on master' '
199 (cd super/submodule &&
200 git reset --hard HEAD~1
206 git submodule update --merge submodule &&
212 test_expect_success
'submodule update - rebase in .git/config' '
214 git config submodule.submodule.update rebase
216 (cd super/submodule &&
217 git reset --hard HEAD~1
223 git submodule update submodule &&
229 test_expect_success
'submodule update - checkout in .git/config but --rebase given' '
231 git config submodule.submodule.update checkout
233 (cd super/submodule &&
234 git reset --hard HEAD~1
240 git submodule update --rebase submodule &&
246 test_expect_success
'submodule update - merge in .git/config' '
248 git config submodule.submodule.update merge
250 (cd super/submodule &&
251 git reset --hard HEAD~1
257 git submodule update submodule &&
263 test_expect_success
'submodule update - checkout in .git/config but --merge given' '
265 git config submodule.submodule.update checkout
267 (cd super/submodule &&
268 git reset --hard HEAD~1
274 git submodule update --merge submodule &&
280 test_expect_success
'submodule update - checkout in .git/config' '
282 git config submodule.submodule.update checkout
284 (cd super/submodule &&
285 git reset --hard HEAD^
291 git submodule update submodule &&
297 test_expect_success
'submodule update - command in .git/config' '
299 git config submodule.submodule.update "!git checkout"
301 (cd super/submodule &&
302 git reset --hard HEAD^
308 git submodule update submodule &&
314 test_expect_success
'submodule update - command in .git/config catches failure' '
316 git config submodule.submodule.update "!false"
318 (cd super/submodule &&
319 git reset --hard HEAD^
322 test_must_fail git submodule update submodule
326 test_expect_success
'submodule init does not copy command into .git/config' '
328 H=$(git ls-files -s submodule | cut -d" " -f2) &&
330 git update-index --add --cacheinfo 160000 $H submodule1 &&
331 git config -f .gitmodules submodule.submodule1.path submodule1 &&
332 git config -f .gitmodules submodule.submodule1.url ../submodule &&
333 git config -f .gitmodules submodule.submodule1.update !false &&
334 git submodule init submodule1 &&
335 echo "none" >expect &&
336 git config submodule.submodule1.update >actual &&
337 test_cmp expect actual
341 test_expect_success
'submodule init picks up rebase' '
343 git config -f .gitmodules submodule.rebasing.update rebase &&
344 git submodule init rebasing &&
345 test "rebase" = "$(git config submodule.rebasing.update)"
349 test_expect_success
'submodule init picks up merge' '
351 git config -f .gitmodules submodule.merging.update merge &&
352 git submodule init merging &&
353 test "merge" = "$(git config submodule.merging.update)"
357 test_expect_success
'submodule update --merge - ignores --merge for new submodules' '
360 git submodule update submodule &&
361 git status -s submodule >expect &&
363 git submodule update --merge submodule &&
364 git status -s submodule >actual &&
365 test_cmp expect actual
369 test_expect_success
'submodule update --rebase - ignores --rebase for new submodules' '
372 git submodule update submodule &&
373 git status -s submodule >expect &&
375 git submodule update --rebase submodule &&
376 git status -s submodule >actual &&
377 test_cmp expect actual
381 test_expect_success
'submodule update ignores update=merge config for new submodules' '
384 git submodule update submodule &&
385 git status -s submodule >expect &&
387 git config submodule.submodule.update merge &&
388 git submodule update submodule &&
389 git status -s submodule >actual &&
390 git config --unset submodule.submodule.update &&
391 test_cmp expect actual
395 test_expect_success
'submodule update ignores update=rebase config for new submodules' '
398 git submodule update submodule &&
399 git status -s submodule >expect &&
401 git config submodule.submodule.update rebase &&
402 git submodule update submodule &&
403 git status -s submodule >actual &&
404 git config --unset submodule.submodule.update &&
405 test_cmp expect actual
409 test_expect_success
'submodule init picks up update=none' '
411 git config -f .gitmodules submodule.none.update none &&
412 git submodule init none &&
413 test "none" = "$(git config submodule.none.update)"
417 test_expect_success
'submodule update - update=none in .git/config' '
419 git config submodule.submodule.update none &&
421 git checkout master &&
424 git diff --raw | grep " submodule" &&
425 git submodule update &&
426 git diff --raw | grep " submodule" &&
430 git config --unset submodule.submodule.update &&
431 git submodule update submodule
435 test_expect_success
'submodule update - update=none in .git/config but --checkout given' '
437 git config submodule.submodule.update none &&
439 git checkout master &&
442 git diff --raw | grep " submodule" &&
443 git submodule update --checkout &&
444 test_must_fail git diff --raw \| grep " submodule" &&
446 test_must_fail compare_head
448 git config --unset submodule.submodule.update
452 test_expect_success
'submodule update --init skips submodule with update=none' '
454 git add .gitmodules &&
455 git commit -m ".gitmodules"
457 git clone super cloned &&
459 git submodule update --init &&
460 test -e submodule/.git &&
461 test_must_fail test -e none/.git
465 test_expect_success
'submodule update continues after checkout error' '
467 git reset --hard HEAD &&
468 git submodule add ../submodule submodule2 &&
469 git submodule init &&
470 git commit -am "new_submodule" &&
472 git rev-parse --verify HEAD >../expect
475 test_commit "update_submodule" file
478 test_commit "update_submodule2" file
481 git add submodule2 &&
482 git commit -m "two_new_submodule_commits" &&
486 git checkout HEAD^ &&
487 test_must_fail git submodule update &&
489 git rev-parse --verify HEAD >../actual
491 test_cmp expect actual
494 test_expect_success
'submodule update continues after recursive checkout error' '
496 git reset --hard HEAD &&
497 git checkout master &&
498 git submodule update &&
500 git submodule add ../submodule subsubmodule &&
501 git submodule init &&
502 git commit -m "new_subsubmodule"
505 git commit -m "update_submodule" &&
508 test_commit "update_subsubmodule" file
510 git add subsubmodule &&
511 test_commit "update_submodule_again" file &&
513 test_commit "update_subsubmodule_again" file
515 test_commit "update_submodule_again_again" file
518 git rev-parse --verify HEAD >../expect &&
519 test_commit "update_submodule2_again" file
522 git add submodule2 &&
523 git commit -m "new_commits" &&
524 git checkout HEAD^ &&
526 git checkout HEAD^ &&
531 test_must_fail git submodule update --recursive &&
533 git rev-parse --verify HEAD >../actual
535 test_cmp expect actual
539 test_expect_success
'submodule update exit immediately in case of merge conflict' '
541 git checkout master &&
542 git reset --hard HEAD &&
545 git reset --hard HEAD
548 git submodule update --recursive &&
550 test_commit "update_submodule_2" file
553 test_commit "update_submodule2_2" file
556 git add submodule2 &&
557 git commit -m "two_new_submodule_commits" &&
559 git checkout master &&
560 test_commit "conflict" file &&
561 echo "conflict" > file
563 git checkout HEAD^ &&
565 git rev-parse --verify HEAD >../expect
567 git config submodule.submodule.update merge &&
568 test_must_fail git submodule update &&
570 git rev-parse --verify HEAD >../actual
572 test_cmp expect actual
576 test_expect_success
'submodule update exit immediately after recursive rebase error' '
578 git checkout master &&
579 git reset --hard HEAD &&
581 git reset --hard HEAD &&
582 git submodule update --recursive
585 test_commit "update_submodule_3" file
588 test_commit "update_submodule2_3" file
591 git add submodule2 &&
592 git commit -m "two_new_submodule_commits" &&
594 git checkout master &&
595 test_commit "conflict2" file &&
596 echo "conflict" > file
598 git checkout HEAD^ &&
600 git rev-parse --verify HEAD >../expect
602 git config submodule.submodule.update rebase &&
603 test_must_fail git submodule update &&
605 git rev-parse --verify HEAD >../actual
607 test_cmp expect actual
611 test_expect_success
'add different submodules to the same path' '
613 git submodule add ../submodule s1 &&
614 test_must_fail git submodule add ../merging s1
618 test_expect_success
'submodule add places git-dir in superprojects git-dir' '
621 git submodule add ../submodule deeper/submodule &&
622 (cd deeper/submodule &&
623 git log > ../../expected
625 (cd .git/modules/deeper/submodule &&
626 git log > ../../../../actual
628 test_cmp actual expected
632 test_expect_success
'submodule update places git-dir in superprojects git-dir' '
634 git commit -m "added submodule"
636 git clone super super2 &&
638 git submodule init deeper/submodule &&
639 git submodule update &&
640 (cd deeper/submodule &&
641 git log > ../../expected
643 (cd .git/modules/deeper/submodule &&
644 git log > ../../../../actual
646 test_cmp actual expected
650 test_expect_success
'submodule add places git-dir in superprojects git-dir recursive' '
652 (cd deeper/submodule &&
653 git submodule add ../submodule subsubmodule &&
655 git log > ../../../expected
657 git commit -m "added subsubmodule" &&
660 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
661 git log > ../../../../../actual
663 git add deeper/submodule &&
664 git commit -m "update submodule" &&
666 test_cmp actual expected
670 test_expect_success
'submodule update places git-dir in superprojects git-dir recursive' '
671 mkdir super_update_r &&
672 (cd super_update_r &&
675 mkdir subsuper_update_r &&
676 (cd subsuper_update_r &&
679 mkdir subsubsuper_update_r &&
680 (cd subsubsuper_update_r &&
683 git clone subsubsuper_update_r subsubsuper_update_r2 &&
684 (cd subsubsuper_update_r2 &&
685 test_commit "update_subsubsuper" file &&
686 git push origin master
688 git clone subsuper_update_r subsuper_update_r2 &&
689 (cd subsuper_update_r2 &&
690 test_commit "update_subsuper" file &&
691 git submodule add ../subsubsuper_update_r subsubmodule &&
692 git commit -am "subsubmodule" &&
693 git push origin master
695 git clone super_update_r super_update_r2 &&
696 (cd super_update_r2 &&
697 test_commit "update_super" file &&
698 git submodule add ../subsuper_update_r submodule &&
699 git commit -am "submodule" &&
700 git push origin master
702 rm -rf super_update_r2 &&
703 git clone super_update_r super_update_r2 &&
704 (cd super_update_r2 &&
705 git submodule update --init --recursive >actual &&
706 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
707 (cd submodule/subsubmodule &&
708 git log > ../../expected
710 (cd .git/modules/submodule/modules/subsubmodule
711 git log > ../../../../../actual
713 test_cmp actual expected
717 test_expect_success
'submodule add properly re-creates deeper level submodules' '
719 git reset --hard master &&
721 git submodule add --force ../submodule deeper/submodule
725 test_expect_success
'submodule update properly revives a moved submodule' '
727 H=$(git rev-parse --short HEAD) &&
728 git commit -am "pre move" &&
729 H2=$(git rev-parse --short HEAD) &&
730 git status | sed "s/$H/XXX/" >expect &&
731 H=$(cd submodule2; git rev-parse HEAD) &&
732 git rm --cached submodule2 &&
734 mkdir -p "moved/sub module" &&
735 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
736 git config -f .gitmodules submodule.submodule2.path "moved/sub module"
737 git commit -am "post move" &&
738 git submodule update &&
739 git status | sed "s/$H2/XXX/" >actual &&
740 test_cmp expect actual
744 test_expect_success SYMLINKS
'submodule update can handle symbolic links in pwd' '
745 mkdir -p linked/dir &&
746 ln -s linked/dir linkto &&
748 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
750 git submodule update --init --recursive
755 test_expect_success
'submodule update clone shallow submodule' '
756 git clone cloned super3 &&
759 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
760 mv -f .gitmodules.tmp .gitmodules &&
761 git submodule update --init --depth=3
763 test 1 = $(git log --oneline | wc -l)
768 test_expect_success
'submodule update --recursive drops module name before recursing' '
770 (cd deeper/submodule/subsubmodule &&
773 git submodule update --recursive deeper/submodule >actual &&
774 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual