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 --rebase staying on master' '
139 (cd super/submodule &&
146 git submodule update --rebase submodule &&
152 test_expect_success 'submodule update --merge staying on master' '
153 (cd super/submodule &&
154 git reset --hard HEAD~1
160 git submodule update --merge submodule &&
166 test_expect_success 'submodule update - rebase in .git/config' '
168 git config submodule.submodule.update rebase
170 (cd super/submodule &&
171 git reset --hard HEAD~1
177 git submodule update submodule &&
183 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
185 git config submodule.submodule.update checkout
187 (cd super/submodule &&
188 git reset --hard HEAD~1
194 git submodule update --rebase submodule &&
200 test_expect_success 'submodule update - merge in .git/config' '
202 git config submodule.submodule.update merge
204 (cd super/submodule &&
205 git reset --hard HEAD~1
211 git submodule update submodule &&
217 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
219 git config submodule.submodule.update checkout
221 (cd super/submodule &&
222 git reset --hard HEAD~1
228 git submodule update --merge submodule &&
234 test_expect_success 'submodule update - checkout in .git/config' '
236 git config submodule.submodule.update checkout
238 (cd super/submodule &&
239 git reset --hard HEAD^
245 git submodule update submodule &&
251 test_expect_success 'submodule init picks up rebase' '
253 git config -f .gitmodules submodule.rebasing.update rebase &&
254 git submodule init rebasing &&
255 test "rebase" = "$(git config submodule.rebasing.update)"
259 test_expect_success 'submodule init picks up merge' '
261 git config -f .gitmodules submodule.merging.update merge &&
262 git submodule init merging &&
263 test "merge" = "$(git config submodule.merging.update)"
267 test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
270 git submodule update submodule &&
271 git status -s submodule >expect &&
273 git submodule update --merge submodule &&
274 git status -s submodule >actual &&
275 test_cmp expect actual
279 test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
282 git submodule update submodule &&
283 git status -s submodule >expect &&
285 git submodule update --rebase submodule &&
286 git status -s submodule >actual &&
287 test_cmp expect actual
291 test_expect_success 'submodule update ignores update=merge config for new submodules' '
294 git submodule update submodule &&
295 git status -s submodule >expect &&
297 git config submodule.submodule.update merge &&
298 git submodule update submodule &&
299 git status -s submodule >actual &&
300 git config --unset submodule.submodule.update &&
301 test_cmp expect actual
305 test_expect_success 'submodule update ignores update=rebase config for new submodules' '
308 git submodule update submodule &&
309 git status -s submodule >expect &&
311 git config submodule.submodule.update rebase &&
312 git submodule update submodule &&
313 git status -s submodule >actual &&
314 git config --unset submodule.submodule.update &&
315 test_cmp expect actual
319 test_expect_success 'submodule init picks up update=none' '
321 git config -f .gitmodules submodule.none.update none &&
322 git submodule init none &&
323 test "none" = "$(git config submodule.none.update)"
327 test_expect_success 'submodule update - update=none in .git/config' '
329 git config submodule.submodule.update none &&
331 git checkout master &&
334 git diff --raw | grep " submodule" &&
335 git submodule update &&
336 git diff --raw | grep " submodule" &&
340 git config --unset submodule.submodule.update &&
341 git submodule update submodule
345 test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
347 git config submodule.submodule.update none &&
349 git checkout master &&
352 git diff --raw | grep " submodule" &&
353 git submodule update --checkout &&
354 test_must_fail git diff --raw \| grep " submodule" &&
356 test_must_fail compare_head
358 git config --unset submodule.submodule.update
362 test_expect_success 'submodule update --init skips submodule with update=none' '
364 git add .gitmodules &&
365 git commit -m ".gitmodules"
367 git clone super cloned &&
369 git submodule update --init &&
370 test -e submodule/.git &&
371 test_must_fail test -e none/.git
375 test_expect_success 'submodule update continues after checkout error' '
377 git reset --hard HEAD &&
378 git submodule add ../submodule submodule2 &&
379 git submodule init &&
380 git commit -am "new_submodule" &&
382 git rev-parse --verify HEAD >../expect
385 test_commit "update_submodule" file
388 test_commit "update_submodule2" file
391 git add submodule2 &&
392 git commit -m "two_new_submodule_commits" &&
396 git checkout HEAD^ &&
397 test_must_fail git submodule update &&
399 git rev-parse --verify HEAD >../actual
401 test_cmp expect actual
404 test_expect_success 'submodule update continues after recursive checkout error' '
406 git reset --hard HEAD &&
407 git checkout master &&
408 git submodule update &&
410 git submodule add ../submodule subsubmodule &&
411 git submodule init &&
412 git commit -m "new_subsubmodule"
415 git commit -m "update_submodule" &&
418 test_commit "update_subsubmodule" file
420 git add subsubmodule &&
421 test_commit "update_submodule_again" file &&
423 test_commit "update_subsubmodule_again" file
425 test_commit "update_submodule_again_again" file
428 git rev-parse --verify HEAD >../expect &&
429 test_commit "update_submodule2_again" file
432 git add submodule2 &&
433 git commit -m "new_commits" &&
434 git checkout HEAD^ &&
436 git checkout HEAD^ &&
441 test_must_fail git submodule update --recursive &&
443 git rev-parse --verify HEAD >../actual
445 test_cmp expect actual
449 test_expect_success 'submodule update exit immediately in case of merge conflict' '
451 git checkout master &&
452 git reset --hard HEAD &&
455 git reset --hard HEAD
458 git submodule update --recursive &&
460 test_commit "update_submodule_2" file
463 test_commit "update_submodule2_2" file
466 git add submodule2 &&
467 git commit -m "two_new_submodule_commits" &&
469 git checkout master &&
470 test_commit "conflict" file &&
471 echo "conflict" > file
473 git checkout HEAD^ &&
475 git rev-parse --verify HEAD >../expect
477 git config submodule.submodule.update merge &&
478 test_must_fail git submodule update &&
480 git rev-parse --verify HEAD >../actual
482 test_cmp expect actual
486 test_expect_success 'submodule update exit immediately after recursive rebase error' '
488 git checkout master &&
489 git reset --hard HEAD &&
491 git reset --hard HEAD &&
492 git submodule update --recursive
495 test_commit "update_submodule_3" file
498 test_commit "update_submodule2_3" file
501 git add submodule2 &&
502 git commit -m "two_new_submodule_commits" &&
504 git checkout master &&
505 test_commit "conflict2" file &&
506 echo "conflict" > file
508 git checkout HEAD^ &&
510 git rev-parse --verify HEAD >../expect
512 git config submodule.submodule.update rebase &&
513 test_must_fail git submodule update &&
515 git rev-parse --verify HEAD >../actual
517 test_cmp expect actual
521 test_expect_success 'add different submodules to the same path' '
523 git submodule add ../submodule s1 &&
524 test_must_fail git submodule add ../merging s1
528 test_expect_success 'submodule add places git-dir in superprojects git-dir' '
531 git submodule add ../submodule deeper/submodule &&
532 (cd deeper/submodule &&
533 git log > ../../expected
535 (cd .git/modules/deeper/submodule &&
536 git log > ../../../../actual
538 test_cmp actual expected
542 test_expect_success 'submodule update places git-dir in superprojects git-dir' '
544 git commit -m "added submodule"
546 git clone super super2 &&
548 git submodule init deeper/submodule &&
549 git submodule update &&
550 (cd deeper/submodule &&
551 git log > ../../expected
553 (cd .git/modules/deeper/submodule &&
554 git log > ../../../../actual
556 test_cmp actual expected
560 test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
562 (cd deeper/submodule &&
563 git submodule add ../submodule subsubmodule &&
565 git log > ../../../expected
567 git commit -m "added subsubmodule" &&
570 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
571 git log > ../../../../../actual
573 git add deeper/submodule &&
574 git commit -m "update submodule" &&
576 test_cmp actual expected
580 test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
581 mkdir super_update_r &&
582 (cd super_update_r &&
585 mkdir subsuper_update_r &&
586 (cd subsuper_update_r &&
589 mkdir subsubsuper_update_r &&
590 (cd subsubsuper_update_r &&
593 git clone subsubsuper_update_r subsubsuper_update_r2 &&
594 (cd subsubsuper_update_r2 &&
595 test_commit "update_subsubsuper" file &&
596 git push origin master
598 git clone subsuper_update_r subsuper_update_r2 &&
599 (cd subsuper_update_r2 &&
600 test_commit "update_subsuper" file &&
601 git submodule add ../subsubsuper_update_r subsubmodule &&
602 git commit -am "subsubmodule" &&
603 git push origin master
605 git clone super_update_r super_update_r2 &&
606 (cd super_update_r2 &&
607 test_commit "update_super" file &&
608 git submodule add ../subsuper_update_r submodule &&
609 git commit -am "submodule" &&
610 git push origin master
612 rm -rf super_update_r2 &&
613 git clone super_update_r super_update_r2 &&
614 (cd super_update_r2 &&
615 git submodule update --init --recursive &&
616 (cd submodule/subsubmodule &&
617 git log > ../../expected
619 (cd .git/modules/submodule/modules/subsubmodule
620 git log > ../../../../../actual
622 test_cmp actual expected
626 test_expect_success 'submodule add properly re-creates deeper level submodules' '
628 git reset --hard master &&
630 git submodule add ../submodule deeper/submodule
634 test_expect_success 'submodule update properly revives a moved submodule' '
636 git commit -am "pre move" &&
638 H=$(cd submodule2; git rev-parse HEAD) &&
639 git rm --cached submodule2 &&
641 mkdir -p "moved/sub module" &&
642 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
643 git config -f .gitmodules submodule.submodule2.path "moved/sub module"
644 git commit -am "post move" &&
645 git submodule update &&
646 git status >actual &&
647 test_cmp expect actual
651 test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
652 mkdir -p linked/dir &&
653 ln -s linked/dir linkto &&
656 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
659 git submodule update --init --recursive