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 init picks up rebase' '
299 git config -f .gitmodules submodule.rebasing.update rebase &&
300 git submodule init rebasing &&
301 test "rebase" = "$(git config submodule.rebasing.update)"
305 test_expect_success
'submodule init picks up merge' '
307 git config -f .gitmodules submodule.merging.update merge &&
308 git submodule init merging &&
309 test "merge" = "$(git config submodule.merging.update)"
313 test_expect_success
'submodule update --merge - ignores --merge for new submodules' '
316 git submodule update submodule &&
317 git status -s submodule >expect &&
319 git submodule update --merge submodule &&
320 git status -s submodule >actual &&
321 test_cmp expect actual
325 test_expect_success
'submodule update --rebase - ignores --rebase for new submodules' '
328 git submodule update submodule &&
329 git status -s submodule >expect &&
331 git submodule update --rebase submodule &&
332 git status -s submodule >actual &&
333 test_cmp expect actual
337 test_expect_success
'submodule update ignores update=merge config for new submodules' '
340 git submodule update submodule &&
341 git status -s submodule >expect &&
343 git config submodule.submodule.update merge &&
344 git submodule update submodule &&
345 git status -s submodule >actual &&
346 git config --unset submodule.submodule.update &&
347 test_cmp expect actual
351 test_expect_success
'submodule update ignores update=rebase config for new submodules' '
354 git submodule update submodule &&
355 git status -s submodule >expect &&
357 git config submodule.submodule.update rebase &&
358 git submodule update submodule &&
359 git status -s submodule >actual &&
360 git config --unset submodule.submodule.update &&
361 test_cmp expect actual
365 test_expect_success
'submodule init picks up update=none' '
367 git config -f .gitmodules submodule.none.update none &&
368 git submodule init none &&
369 test "none" = "$(git config submodule.none.update)"
373 test_expect_success
'submodule update - update=none in .git/config' '
375 git config submodule.submodule.update none &&
377 git checkout master &&
380 git diff --raw | grep " submodule" &&
381 git submodule update &&
382 git diff --raw | grep " submodule" &&
386 git config --unset submodule.submodule.update &&
387 git submodule update submodule
391 test_expect_success
'submodule update - update=none in .git/config but --checkout given' '
393 git config submodule.submodule.update none &&
395 git checkout master &&
398 git diff --raw | grep " submodule" &&
399 git submodule update --checkout &&
400 test_must_fail git diff --raw \| grep " submodule" &&
402 test_must_fail compare_head
404 git config --unset submodule.submodule.update
408 test_expect_success
'submodule update --init skips submodule with update=none' '
410 git add .gitmodules &&
411 git commit -m ".gitmodules"
413 git clone super cloned &&
415 git submodule update --init &&
416 test -e submodule/.git &&
417 test_must_fail test -e none/.git
421 test_expect_success
'submodule update continues after checkout error' '
423 git reset --hard HEAD &&
424 git submodule add ../submodule submodule2 &&
425 git submodule init &&
426 git commit -am "new_submodule" &&
428 git rev-parse --verify HEAD >../expect
431 test_commit "update_submodule" file
434 test_commit "update_submodule2" file
437 git add submodule2 &&
438 git commit -m "two_new_submodule_commits" &&
442 git checkout HEAD^ &&
443 test_must_fail git submodule update &&
445 git rev-parse --verify HEAD >../actual
447 test_cmp expect actual
450 test_expect_success
'submodule update continues after recursive checkout error' '
452 git reset --hard HEAD &&
453 git checkout master &&
454 git submodule update &&
456 git submodule add ../submodule subsubmodule &&
457 git submodule init &&
458 git commit -m "new_subsubmodule"
461 git commit -m "update_submodule" &&
464 test_commit "update_subsubmodule" file
466 git add subsubmodule &&
467 test_commit "update_submodule_again" file &&
469 test_commit "update_subsubmodule_again" file
471 test_commit "update_submodule_again_again" file
474 git rev-parse --verify HEAD >../expect &&
475 test_commit "update_submodule2_again" file
478 git add submodule2 &&
479 git commit -m "new_commits" &&
480 git checkout HEAD^ &&
482 git checkout HEAD^ &&
487 test_must_fail git submodule update --recursive &&
489 git rev-parse --verify HEAD >../actual
491 test_cmp expect actual
495 test_expect_success
'submodule update exit immediately in case of merge conflict' '
497 git checkout master &&
498 git reset --hard HEAD &&
501 git reset --hard HEAD
504 git submodule update --recursive &&
506 test_commit "update_submodule_2" file
509 test_commit "update_submodule2_2" file
512 git add submodule2 &&
513 git commit -m "two_new_submodule_commits" &&
515 git checkout master &&
516 test_commit "conflict" file &&
517 echo "conflict" > file
519 git checkout HEAD^ &&
521 git rev-parse --verify HEAD >../expect
523 git config submodule.submodule.update merge &&
524 test_must_fail git submodule update &&
526 git rev-parse --verify HEAD >../actual
528 test_cmp expect actual
532 test_expect_success
'submodule update exit immediately after recursive rebase error' '
534 git checkout master &&
535 git reset --hard HEAD &&
537 git reset --hard HEAD &&
538 git submodule update --recursive
541 test_commit "update_submodule_3" file
544 test_commit "update_submodule2_3" file
547 git add submodule2 &&
548 git commit -m "two_new_submodule_commits" &&
550 git checkout master &&
551 test_commit "conflict2" file &&
552 echo "conflict" > file
554 git checkout HEAD^ &&
556 git rev-parse --verify HEAD >../expect
558 git config submodule.submodule.update rebase &&
559 test_must_fail git submodule update &&
561 git rev-parse --verify HEAD >../actual
563 test_cmp expect actual
567 test_expect_success
'add different submodules to the same path' '
569 git submodule add ../submodule s1 &&
570 test_must_fail git submodule add ../merging s1
574 test_expect_success
'submodule add places git-dir in superprojects git-dir' '
577 git submodule add ../submodule deeper/submodule &&
578 (cd deeper/submodule &&
579 git log > ../../expected
581 (cd .git/modules/deeper/submodule &&
582 git log > ../../../../actual
584 test_cmp actual expected
588 test_expect_success
'submodule update places git-dir in superprojects git-dir' '
590 git commit -m "added submodule"
592 git clone super super2 &&
594 git submodule init deeper/submodule &&
595 git submodule update &&
596 (cd deeper/submodule &&
597 git log > ../../expected
599 (cd .git/modules/deeper/submodule &&
600 git log > ../../../../actual
602 test_cmp actual expected
606 test_expect_success
'submodule add places git-dir in superprojects git-dir recursive' '
608 (cd deeper/submodule &&
609 git submodule add ../submodule subsubmodule &&
611 git log > ../../../expected
613 git commit -m "added subsubmodule" &&
616 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
617 git log > ../../../../../actual
619 git add deeper/submodule &&
620 git commit -m "update submodule" &&
622 test_cmp actual expected
626 test_expect_success
'submodule update places git-dir in superprojects git-dir recursive' '
627 mkdir super_update_r &&
628 (cd super_update_r &&
631 mkdir subsuper_update_r &&
632 (cd subsuper_update_r &&
635 mkdir subsubsuper_update_r &&
636 (cd subsubsuper_update_r &&
639 git clone subsubsuper_update_r subsubsuper_update_r2 &&
640 (cd subsubsuper_update_r2 &&
641 test_commit "update_subsubsuper" file &&
642 git push origin master
644 git clone subsuper_update_r subsuper_update_r2 &&
645 (cd subsuper_update_r2 &&
646 test_commit "update_subsuper" file &&
647 git submodule add ../subsubsuper_update_r subsubmodule &&
648 git commit -am "subsubmodule" &&
649 git push origin master
651 git clone super_update_r super_update_r2 &&
652 (cd super_update_r2 &&
653 test_commit "update_super" file &&
654 git submodule add ../subsuper_update_r submodule &&
655 git commit -am "submodule" &&
656 git push origin master
658 rm -rf super_update_r2 &&
659 git clone super_update_r super_update_r2 &&
660 (cd super_update_r2 &&
661 git submodule update --init --recursive >actual &&
662 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
663 (cd submodule/subsubmodule &&
664 git log > ../../expected
666 (cd .git/modules/submodule/modules/subsubmodule
667 git log > ../../../../../actual
669 test_cmp actual expected
673 test_expect_success
'submodule add properly re-creates deeper level submodules' '
675 git reset --hard master &&
677 git submodule add --force ../submodule deeper/submodule
681 test_expect_success
'submodule update properly revives a moved submodule' '
683 H=$(git rev-parse --short HEAD) &&
684 git commit -am "pre move" &&
685 H2=$(git rev-parse --short HEAD) &&
686 git status | sed "s/$H/XXX/" >expect &&
687 H=$(cd submodule2; git rev-parse HEAD) &&
688 git rm --cached submodule2 &&
690 mkdir -p "moved/sub module" &&
691 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
692 git config -f .gitmodules submodule.submodule2.path "moved/sub module"
693 git commit -am "post move" &&
694 git submodule update &&
695 git status | sed "s/$H2/XXX/" >actual &&
696 test_cmp expect actual
700 test_expect_success SYMLINKS
'submodule update can handle symbolic links in pwd' '
701 mkdir -p linked/dir &&
702 ln -s linked/dir linkto &&
705 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
708 git submodule update --init --recursive