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 &&
84 test_expect_success 'submodule update does not fetch already present commits' '
89 git commit -m "upstream line3"
91 (cd super/submodule &&
92 head=$(git rev-parse --verify HEAD) &&
93 echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
94 git reset --hard HEAD~1
97 git submodule update > ../actual 2> ../actual.err
99 test_i18ncmp expected actual &&
103 test_expect_success 'submodule update should fail due to local changes' '
104 (cd super/submodule &&
105 git reset --hard HEAD~1 &&
106 echo "local change" > file
112 test_must_fail git submodule update submodule
115 test_expect_success 'submodule update should throw away changes with --force ' '
120 git submodule update --force submodule &&
126 test_expect_success 'submodule update --force forcibly checks out submodules' '
131 git submodule update --force submodule &&
133 test "$(git status -s file)" = ""
138 test_expect_success 'submodule update --remote should fetch upstream changes' '
140 echo line4 >> file &&
143 git commit -m "upstream line4"
146 git submodule update --remote --force submodule &&
148 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
152 test_expect_success 'local config should override .gitmodules branch' '
154 git checkout -b test-branch &&
155 echo line5 >> file &&
158 git commit -m "upstream line5" &&
162 git config submodule.submodule.branch test-branch &&
163 git submodule update --remote --force submodule &&
165 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
169 test_expect_success 'submodule update --rebase staying on master' '
170 (cd super/submodule &&
177 git submodule update --rebase submodule &&
183 test_expect_success 'submodule update --merge staying on master' '
184 (cd super/submodule &&
185 git reset --hard HEAD~1
191 git submodule update --merge submodule &&
197 test_expect_success 'submodule update - rebase in .git/config' '
199 git config submodule.submodule.update rebase
201 (cd super/submodule &&
202 git reset --hard HEAD~1
208 git submodule update submodule &&
214 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
216 git config submodule.submodule.update checkout
218 (cd super/submodule &&
219 git reset --hard HEAD~1
225 git submodule update --rebase submodule &&
231 test_expect_success 'submodule update - merge in .git/config' '
233 git config submodule.submodule.update merge
235 (cd super/submodule &&
236 git reset --hard HEAD~1
242 git submodule update submodule &&
248 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
250 git config submodule.submodule.update checkout
252 (cd super/submodule &&
253 git reset --hard HEAD~1
259 git submodule update --merge submodule &&
265 test_expect_success 'submodule update - checkout in .git/config' '
267 git config submodule.submodule.update checkout
269 (cd super/submodule &&
270 git reset --hard HEAD^
276 git submodule update submodule &&
282 test_expect_success 'submodule init picks up rebase' '
284 git config -f .gitmodules submodule.rebasing.update rebase &&
285 git submodule init rebasing &&
286 test "rebase" = "$(git config submodule.rebasing.update)"
290 test_expect_success 'submodule init picks up merge' '
292 git config -f .gitmodules submodule.merging.update merge &&
293 git submodule init merging &&
294 test "merge" = "$(git config submodule.merging.update)"
298 test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
301 git submodule update submodule &&
302 git status -s submodule >expect &&
304 git submodule update --merge submodule &&
305 git status -s submodule >actual &&
306 test_cmp expect actual
310 test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
313 git submodule update submodule &&
314 git status -s submodule >expect &&
316 git submodule update --rebase submodule &&
317 git status -s submodule >actual &&
318 test_cmp expect actual
322 test_expect_success 'submodule update ignores update=merge config for new submodules' '
325 git submodule update submodule &&
326 git status -s submodule >expect &&
328 git config submodule.submodule.update merge &&
329 git submodule update submodule &&
330 git status -s submodule >actual &&
331 git config --unset submodule.submodule.update &&
332 test_cmp expect actual
336 test_expect_success 'submodule update ignores update=rebase config for new submodules' '
339 git submodule update submodule &&
340 git status -s submodule >expect &&
342 git config submodule.submodule.update rebase &&
343 git submodule update submodule &&
344 git status -s submodule >actual &&
345 git config --unset submodule.submodule.update &&
346 test_cmp expect actual
350 test_expect_success 'submodule init picks up update=none' '
352 git config -f .gitmodules submodule.none.update none &&
353 git submodule init none &&
354 test "none" = "$(git config submodule.none.update)"
358 test_expect_success 'submodule update - update=none in .git/config' '
360 git config submodule.submodule.update none &&
362 git checkout master &&
365 git diff --raw | grep " submodule" &&
366 git submodule update &&
367 git diff --raw | grep " submodule" &&
371 git config --unset submodule.submodule.update &&
372 git submodule update submodule
376 test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
378 git config submodule.submodule.update none &&
380 git checkout master &&
383 git diff --raw | grep " submodule" &&
384 git submodule update --checkout &&
385 test_must_fail git diff --raw \| grep " submodule" &&
387 test_must_fail compare_head
389 git config --unset submodule.submodule.update
393 test_expect_success 'submodule update --init skips submodule with update=none' '
395 git add .gitmodules &&
396 git commit -m ".gitmodules"
398 git clone super cloned &&
400 git submodule update --init &&
401 test -e submodule/.git &&
402 test_must_fail test -e none/.git
406 test_expect_success 'submodule update continues after checkout error' '
408 git reset --hard HEAD &&
409 git submodule add ../submodule submodule2 &&
410 git submodule init &&
411 git commit -am "new_submodule" &&
413 git rev-parse --verify HEAD >../expect
416 test_commit "update_submodule" file
419 test_commit "update_submodule2" file
422 git add submodule2 &&
423 git commit -m "two_new_submodule_commits" &&
427 git checkout HEAD^ &&
428 test_must_fail git submodule update &&
430 git rev-parse --verify HEAD >../actual
432 test_cmp expect actual
435 test_expect_success 'submodule update continues after recursive checkout error' '
437 git reset --hard HEAD &&
438 git checkout master &&
439 git submodule update &&
441 git submodule add ../submodule subsubmodule &&
442 git submodule init &&
443 git commit -m "new_subsubmodule"
446 git commit -m "update_submodule" &&
449 test_commit "update_subsubmodule" file
451 git add subsubmodule &&
452 test_commit "update_submodule_again" file &&
454 test_commit "update_subsubmodule_again" file
456 test_commit "update_submodule_again_again" file
459 git rev-parse --verify HEAD >../expect &&
460 test_commit "update_submodule2_again" file
463 git add submodule2 &&
464 git commit -m "new_commits" &&
465 git checkout HEAD^ &&
467 git checkout HEAD^ &&
472 test_must_fail git submodule update --recursive &&
474 git rev-parse --verify HEAD >../actual
476 test_cmp expect actual
480 test_expect_success 'submodule update exit immediately in case of merge conflict' '
482 git checkout master &&
483 git reset --hard HEAD &&
486 git reset --hard HEAD
489 git submodule update --recursive &&
491 test_commit "update_submodule_2" file
494 test_commit "update_submodule2_2" file
497 git add submodule2 &&
498 git commit -m "two_new_submodule_commits" &&
500 git checkout master &&
501 test_commit "conflict" file &&
502 echo "conflict" > file
504 git checkout HEAD^ &&
506 git rev-parse --verify HEAD >../expect
508 git config submodule.submodule.update merge &&
509 test_must_fail git submodule update &&
511 git rev-parse --verify HEAD >../actual
513 test_cmp expect actual
517 test_expect_success 'submodule update exit immediately after recursive rebase error' '
519 git checkout master &&
520 git reset --hard HEAD &&
522 git reset --hard HEAD &&
523 git submodule update --recursive
526 test_commit "update_submodule_3" file
529 test_commit "update_submodule2_3" file
532 git add submodule2 &&
533 git commit -m "two_new_submodule_commits" &&
535 git checkout master &&
536 test_commit "conflict2" file &&
537 echo "conflict" > file
539 git checkout HEAD^ &&
541 git rev-parse --verify HEAD >../expect
543 git config submodule.submodule.update rebase &&
544 test_must_fail git submodule update &&
546 git rev-parse --verify HEAD >../actual
548 test_cmp expect actual
552 test_expect_success 'add different submodules to the same path' '
554 git submodule add ../submodule s1 &&
555 test_must_fail git submodule add ../merging s1
559 test_expect_success 'submodule add places git-dir in superprojects git-dir' '
562 git submodule add ../submodule deeper/submodule &&
563 (cd deeper/submodule &&
564 git log > ../../expected
566 (cd .git/modules/deeper/submodule &&
567 git log > ../../../../actual
569 test_cmp actual expected
573 test_expect_success 'submodule update places git-dir in superprojects git-dir' '
575 git commit -m "added submodule"
577 git clone super super2 &&
579 git submodule init deeper/submodule &&
580 git submodule update &&
581 (cd deeper/submodule &&
582 git log > ../../expected
584 (cd .git/modules/deeper/submodule &&
585 git log > ../../../../actual
587 test_cmp actual expected
591 test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
593 (cd deeper/submodule &&
594 git submodule add ../submodule subsubmodule &&
596 git log > ../../../expected
598 git commit -m "added subsubmodule" &&
601 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
602 git log > ../../../../../actual
604 git add deeper/submodule &&
605 git commit -m "update submodule" &&
607 test_cmp actual expected
611 test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
612 mkdir super_update_r &&
613 (cd super_update_r &&
616 mkdir subsuper_update_r &&
617 (cd subsuper_update_r &&
620 mkdir subsubsuper_update_r &&
621 (cd subsubsuper_update_r &&
624 git clone subsubsuper_update_r subsubsuper_update_r2 &&
625 (cd subsubsuper_update_r2 &&
626 test_commit "update_subsubsuper" file &&
627 git push origin master
629 git clone subsuper_update_r subsuper_update_r2 &&
630 (cd subsuper_update_r2 &&
631 test_commit "update_subsuper" file &&
632 git submodule add ../subsubsuper_update_r subsubmodule &&
633 git commit -am "subsubmodule" &&
634 git push origin master
636 git clone super_update_r super_update_r2 &&
637 (cd super_update_r2 &&
638 test_commit "update_super" file &&
639 git submodule add ../subsuper_update_r submodule &&
640 git commit -am "submodule" &&
641 git push origin master
643 rm -rf super_update_r2 &&
644 git clone super_update_r super_update_r2 &&
645 (cd super_update_r2 &&
646 git submodule update --init --recursive &&
647 (cd submodule/subsubmodule &&
648 git log > ../../expected
650 (cd .git/modules/submodule/modules/subsubmodule
651 git log > ../../../../../actual
653 test_cmp actual expected
657 test_expect_success 'submodule add properly re-creates deeper level submodules' '
659 git reset --hard master &&
661 git submodule add --force ../submodule deeper/submodule
665 test_expect_success 'submodule update properly revives a moved submodule' '
667 git commit -am "pre move" &&
669 H=$(cd submodule2; git rev-parse HEAD) &&
670 git rm --cached submodule2 &&
672 mkdir -p "moved/sub module" &&
673 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
674 git config -f .gitmodules submodule.submodule2.path "moved/sub module"
675 git commit -am "post move" &&
676 git submodule update &&
677 git status >actual &&
678 test_cmp expect actual
682 test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
683 mkdir -p linked/dir &&
684 ln -s linked/dir linkto &&
687 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
690 git submodule update --init --recursive