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 picks up rebase' '
328 git config -f .gitmodules submodule.rebasing.update rebase &&
329 git submodule init rebasing &&
330 test "rebase" = "$(git config submodule.rebasing.update)"
334 test_expect_success 'submodule init picks up merge' '
336 git config -f .gitmodules submodule.merging.update merge &&
337 git submodule init merging &&
338 test "merge" = "$(git config submodule.merging.update)"
342 test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
345 git submodule update submodule &&
346 git status -s submodule >expect &&
348 git submodule update --merge submodule &&
349 git status -s submodule >actual &&
350 test_cmp expect actual
354 test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
357 git submodule update submodule &&
358 git status -s submodule >expect &&
360 git submodule update --rebase submodule &&
361 git status -s submodule >actual &&
362 test_cmp expect actual
366 test_expect_success 'submodule update ignores update=merge config for new submodules' '
369 git submodule update submodule &&
370 git status -s submodule >expect &&
372 git config submodule.submodule.update merge &&
373 git submodule update submodule &&
374 git status -s submodule >actual &&
375 git config --unset submodule.submodule.update &&
376 test_cmp expect actual
380 test_expect_success 'submodule update ignores update=rebase config for new submodules' '
383 git submodule update submodule &&
384 git status -s submodule >expect &&
386 git config submodule.submodule.update rebase &&
387 git submodule update submodule &&
388 git status -s submodule >actual &&
389 git config --unset submodule.submodule.update &&
390 test_cmp expect actual
394 test_expect_success 'submodule init picks up update=none' '
396 git config -f .gitmodules submodule.none.update none &&
397 git submodule init none &&
398 test "none" = "$(git config submodule.none.update)"
402 test_expect_success 'submodule update - update=none in .git/config' '
404 git config submodule.submodule.update none &&
406 git checkout master &&
409 git diff --raw | grep " submodule" &&
410 git submodule update &&
411 git diff --raw | grep " submodule" &&
415 git config --unset submodule.submodule.update &&
416 git submodule update submodule
420 test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
422 git config submodule.submodule.update none &&
424 git checkout master &&
427 git diff --raw | grep " submodule" &&
428 git submodule update --checkout &&
429 test_must_fail git diff --raw \| grep " submodule" &&
431 test_must_fail compare_head
433 git config --unset submodule.submodule.update
437 test_expect_success 'submodule update --init skips submodule with update=none' '
439 git add .gitmodules &&
440 git commit -m ".gitmodules"
442 git clone super cloned &&
444 git submodule update --init &&
445 test -e submodule/.git &&
446 test_must_fail test -e none/.git
450 test_expect_success 'submodule update continues after checkout error' '
452 git reset --hard HEAD &&
453 git submodule add ../submodule submodule2 &&
454 git submodule init &&
455 git commit -am "new_submodule" &&
457 git rev-parse --verify HEAD >../expect
460 test_commit "update_submodule" file
463 test_commit "update_submodule2" file
466 git add submodule2 &&
467 git commit -m "two_new_submodule_commits" &&
471 git checkout HEAD^ &&
472 test_must_fail git submodule update &&
474 git rev-parse --verify HEAD >../actual
476 test_cmp expect actual
479 test_expect_success 'submodule update continues after recursive checkout error' '
481 git reset --hard HEAD &&
482 git checkout master &&
483 git submodule update &&
485 git submodule add ../submodule subsubmodule &&
486 git submodule init &&
487 git commit -m "new_subsubmodule"
490 git commit -m "update_submodule" &&
493 test_commit "update_subsubmodule" file
495 git add subsubmodule &&
496 test_commit "update_submodule_again" file &&
498 test_commit "update_subsubmodule_again" file
500 test_commit "update_submodule_again_again" file
503 git rev-parse --verify HEAD >../expect &&
504 test_commit "update_submodule2_again" file
507 git add submodule2 &&
508 git commit -m "new_commits" &&
509 git checkout HEAD^ &&
511 git checkout HEAD^ &&
516 test_must_fail git submodule update --recursive &&
518 git rev-parse --verify HEAD >../actual
520 test_cmp expect actual
524 test_expect_success 'submodule update exit immediately in case of merge conflict' '
526 git checkout master &&
527 git reset --hard HEAD &&
530 git reset --hard HEAD
533 git submodule update --recursive &&
535 test_commit "update_submodule_2" file
538 test_commit "update_submodule2_2" file
541 git add submodule2 &&
542 git commit -m "two_new_submodule_commits" &&
544 git checkout master &&
545 test_commit "conflict" file &&
546 echo "conflict" > file
548 git checkout HEAD^ &&
550 git rev-parse --verify HEAD >../expect
552 git config submodule.submodule.update merge &&
553 test_must_fail git submodule update &&
555 git rev-parse --verify HEAD >../actual
557 test_cmp expect actual
561 test_expect_success 'submodule update exit immediately after recursive rebase error' '
563 git checkout master &&
564 git reset --hard HEAD &&
566 git reset --hard HEAD &&
567 git submodule update --recursive
570 test_commit "update_submodule_3" file
573 test_commit "update_submodule2_3" file
576 git add submodule2 &&
577 git commit -m "two_new_submodule_commits" &&
579 git checkout master &&
580 test_commit "conflict2" file &&
581 echo "conflict" > file
583 git checkout HEAD^ &&
585 git rev-parse --verify HEAD >../expect
587 git config submodule.submodule.update rebase &&
588 test_must_fail git submodule update &&
590 git rev-parse --verify HEAD >../actual
592 test_cmp expect actual
596 test_expect_success 'add different submodules to the same path' '
598 git submodule add ../submodule s1 &&
599 test_must_fail git submodule add ../merging s1
603 test_expect_success 'submodule add places git-dir in superprojects git-dir' '
606 git submodule add ../submodule deeper/submodule &&
607 (cd deeper/submodule &&
608 git log > ../../expected
610 (cd .git/modules/deeper/submodule &&
611 git log > ../../../../actual
613 test_cmp actual expected
617 test_expect_success 'submodule update places git-dir in superprojects git-dir' '
619 git commit -m "added submodule"
621 git clone super super2 &&
623 git submodule init deeper/submodule &&
624 git submodule update &&
625 (cd deeper/submodule &&
626 git log > ../../expected
628 (cd .git/modules/deeper/submodule &&
629 git log > ../../../../actual
631 test_cmp actual expected
635 test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
637 (cd deeper/submodule &&
638 git submodule add ../submodule subsubmodule &&
640 git log > ../../../expected
642 git commit -m "added subsubmodule" &&
645 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
646 git log > ../../../../../actual
648 git add deeper/submodule &&
649 git commit -m "update submodule" &&
651 test_cmp actual expected
655 test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
656 mkdir super_update_r &&
657 (cd super_update_r &&
660 mkdir subsuper_update_r &&
661 (cd subsuper_update_r &&
664 mkdir subsubsuper_update_r &&
665 (cd subsubsuper_update_r &&
668 git clone subsubsuper_update_r subsubsuper_update_r2 &&
669 (cd subsubsuper_update_r2 &&
670 test_commit "update_subsubsuper" file &&
671 git push origin master
673 git clone subsuper_update_r subsuper_update_r2 &&
674 (cd subsuper_update_r2 &&
675 test_commit "update_subsuper" file &&
676 git submodule add ../subsubsuper_update_r subsubmodule &&
677 git commit -am "subsubmodule" &&
678 git push origin master
680 git clone super_update_r super_update_r2 &&
681 (cd super_update_r2 &&
682 test_commit "update_super" file &&
683 git submodule add ../subsuper_update_r submodule &&
684 git commit -am "submodule" &&
685 git push origin master
687 rm -rf super_update_r2 &&
688 git clone super_update_r super_update_r2 &&
689 (cd super_update_r2 &&
690 git submodule update --init --recursive >actual &&
691 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
692 (cd submodule/subsubmodule &&
693 git log > ../../expected
695 (cd .git/modules/submodule/modules/subsubmodule
696 git log > ../../../../../actual
698 test_cmp actual expected
702 test_expect_success 'submodule add properly re-creates deeper level submodules' '
704 git reset --hard master &&
706 git submodule add --force ../submodule deeper/submodule
710 test_expect_success 'submodule update properly revives a moved submodule' '
712 H=$(git rev-parse --short HEAD) &&
713 git commit -am "pre move" &&
714 H2=$(git rev-parse --short HEAD) &&
715 git status | sed "s/$H/XXX/" >expect &&
716 H=$(cd submodule2; git rev-parse HEAD) &&
717 git rm --cached submodule2 &&
719 mkdir -p "moved/sub module" &&
720 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
721 git config -f .gitmodules submodule.submodule2.path "moved/sub module"
722 git commit -am "post move" &&
723 git submodule update &&
724 git status | sed "s/$H2/XXX/" >actual &&
725 test_cmp expect actual
729 test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
730 mkdir -p linked/dir &&
731 ln -s linked/dir linkto &&
733 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
735 git submodule update --init --recursive
740 test_expect_success 'submodule update clone shallow submodule' '
741 git clone cloned super3 &&
744 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
745 mv -f .gitmodules.tmp .gitmodules &&
746 git submodule update --init --depth=3
748 test 1 = $(git log --oneline | wc -l)