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 --rebase staying on master' '
127 (cd super/submodule &&
134 git submodule update --rebase submodule &&
140 test_expect_success 'submodule update --merge staying on master' '
141 (cd super/submodule &&
142 git reset --hard HEAD~1
148 git submodule update --merge submodule &&
154 test_expect_success 'submodule update - rebase in .git/config' '
156 git config submodule.submodule.update rebase
158 (cd super/submodule &&
159 git reset --hard HEAD~1
165 git submodule update submodule &&
171 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
173 git config submodule.submodule.update checkout
175 (cd super/submodule &&
176 git reset --hard HEAD~1
182 git submodule update --rebase submodule &&
188 test_expect_success 'submodule update - merge in .git/config' '
190 git config submodule.submodule.update merge
192 (cd super/submodule &&
193 git reset --hard HEAD~1
199 git submodule update submodule &&
205 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
207 git config submodule.submodule.update checkout
209 (cd super/submodule &&
210 git reset --hard HEAD~1
216 git submodule update --merge submodule &&
222 test_expect_success 'submodule update - checkout in .git/config' '
224 git config submodule.submodule.update checkout
226 (cd super/submodule &&
227 git reset --hard HEAD^
233 git submodule update submodule &&
239 test_expect_success 'submodule init picks up rebase' '
241 git config -f .gitmodules submodule.rebasing.update rebase &&
242 git submodule init rebasing &&
243 test "rebase" = "$(git config submodule.rebasing.update)"
247 test_expect_success 'submodule init picks up merge' '
249 git config -f .gitmodules submodule.merging.update merge &&
250 git submodule init merging &&
251 test "merge" = "$(git config submodule.merging.update)"
255 test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
258 git submodule update submodule &&
259 git status -s submodule >expect &&
261 git submodule update --merge submodule &&
262 git status -s submodule >actual &&
263 test_cmp expect actual
267 test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
270 git submodule update submodule &&
271 git status -s submodule >expect &&
273 git submodule update --rebase submodule &&
274 git status -s submodule >actual &&
275 test_cmp expect actual
279 test_expect_success 'submodule update ignores update=merge config for new submodules' '
282 git submodule update submodule &&
283 git status -s submodule >expect &&
285 git config submodule.submodule.update merge &&
286 git submodule update submodule &&
287 git status -s submodule >actual &&
288 git config --unset submodule.submodule.update &&
289 test_cmp expect actual
293 test_expect_success 'submodule update ignores update=rebase config for new submodules' '
296 git submodule update submodule &&
297 git status -s submodule >expect &&
299 git config submodule.submodule.update rebase &&
300 git submodule update submodule &&
301 git status -s submodule >actual &&
302 git config --unset submodule.submodule.update &&
303 test_cmp expect actual
307 test_expect_success 'submodule init picks up update=none' '
309 git config -f .gitmodules submodule.none.update none &&
310 git submodule init none &&
311 test "none" = "$(git config submodule.none.update)"
315 test_expect_success 'submodule update - update=none in .git/config' '
317 git config submodule.submodule.update none &&
319 git checkout master &&
322 git diff --raw | grep " submodule" &&
323 git submodule update &&
324 git diff --raw | grep " submodule" &&
328 git config --unset submodule.submodule.update &&
329 git submodule update submodule
333 test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
335 git config submodule.submodule.update none &&
337 git checkout master &&
340 git diff --raw | grep " submodule" &&
341 git submodule update --checkout &&
342 test_must_fail git diff --raw \| grep " submodule" &&
344 test_must_fail compare_head
346 git config --unset submodule.submodule.update
350 test_expect_success 'submodule update --init skips submodule with update=none' '
352 git add .gitmodules &&
353 git commit -m ".gitmodules"
355 git clone super cloned &&
357 git submodule update --init &&
358 test -e submodule/.git &&
359 test_must_fail test -e none/.git
363 test_expect_success 'submodule update continues after checkout error' '
365 git reset --hard HEAD &&
366 git submodule add ../submodule submodule2 &&
367 git submodule init &&
368 git commit -am "new_submodule" &&
370 git rev-parse --max-count=1 HEAD > ../expect
373 test_commit "update_submodule" file
376 test_commit "update_submodule2" file
379 git add submodule2 &&
380 git commit -m "two_new_submodule_commits" &&
384 git checkout HEAD^ &&
385 test_must_fail git submodule update &&
387 git rev-parse --max-count=1 HEAD > ../actual
389 test_cmp expect actual
392 test_expect_success 'submodule update continues after recursive checkout error' '
394 git reset --hard HEAD &&
395 git checkout master &&
396 git submodule update &&
398 git submodule add ../submodule subsubmodule &&
399 git submodule init &&
400 git commit -m "new_subsubmodule"
403 git commit -m "update_submodule" &&
406 test_commit "update_subsubmodule" file
408 git add subsubmodule &&
409 test_commit "update_submodule_again" file &&
411 test_commit "update_subsubmodule_again" file
413 test_commit "update_submodule_again_again" file
416 git rev-parse --max-count=1 HEAD > ../expect &&
417 test_commit "update_submodule2_again" file
420 git add submodule2 &&
421 git commit -m "new_commits" &&
422 git checkout HEAD^ &&
424 git checkout HEAD^ &&
429 test_must_fail git submodule update --recursive &&
431 git rev-parse --max-count=1 HEAD > ../actual
433 test_cmp expect actual
437 test_expect_success 'submodule update exit immediately in case of merge conflict' '
439 git checkout master &&
440 git reset --hard HEAD &&
443 git reset --hard HEAD
446 git submodule update --recursive &&
448 test_commit "update_submodule_2" file
451 test_commit "update_submodule2_2" file
454 git add submodule2 &&
455 git commit -m "two_new_submodule_commits" &&
457 git checkout master &&
458 test_commit "conflict" file &&
459 echo "conflict" > file
461 git checkout HEAD^ &&
463 git rev-parse --max-count=1 HEAD > ../expect
465 git config submodule.submodule.update merge &&
466 test_must_fail git submodule update &&
468 git rev-parse --max-count=1 HEAD > ../actual
470 test_cmp expect actual
474 test_expect_success 'submodule update exit immediately after recursive rebase error' '
476 git checkout master &&
477 git reset --hard HEAD &&
479 git reset --hard HEAD &&
480 git submodule update --recursive
483 test_commit "update_submodule_3" file
486 test_commit "update_submodule2_3" file
489 git add submodule2 &&
490 git commit -m "two_new_submodule_commits" &&
492 git checkout master &&
493 test_commit "conflict2" file &&
494 echo "conflict" > file
496 git checkout HEAD^ &&
498 git rev-parse --max-count=1 HEAD > ../expect
500 git config submodule.submodule.update rebase &&
501 test_must_fail git submodule update &&
503 git rev-parse --max-count=1 HEAD > ../actual
505 test_cmp expect actual
509 test_expect_success 'add different submodules to the same path' '
511 git submodule add ../submodule s1 &&
512 test_must_fail git submodule add ../merging s1
516 test_expect_success 'submodule add places git-dir in superprojects git-dir' '
519 git submodule add ../submodule deeper/submodule &&
520 (cd deeper/submodule &&
521 git log > ../../expected
523 (cd .git/modules/deeper/submodule &&
524 git log > ../../../../actual
526 test_cmp actual expected
530 test_expect_success 'submodule update places git-dir in superprojects git-dir' '
532 git commit -m "added submodule"
534 git clone super super2 &&
536 git submodule init deeper/submodule &&
537 git submodule update &&
538 (cd deeper/submodule &&
539 git log > ../../expected
541 (cd .git/modules/deeper/submodule &&
542 git log > ../../../../actual
544 test_cmp actual expected
548 test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
550 (cd deeper/submodule &&
551 git submodule add ../submodule subsubmodule &&
553 git log > ../../../expected
555 git commit -m "added subsubmodule" &&
558 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
559 git log > ../../../../../actual
561 git add deeper/submodule &&
562 git commit -m "update submodule" &&
564 test_cmp actual expected
568 test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
569 mkdir super_update_r &&
570 (cd super_update_r &&
573 mkdir subsuper_update_r &&
574 (cd subsuper_update_r &&
577 mkdir subsubsuper_update_r &&
578 (cd subsubsuper_update_r &&
581 git clone subsubsuper_update_r subsubsuper_update_r2 &&
582 (cd subsubsuper_update_r2 &&
583 test_commit "update_subsubsuper" file &&
584 git push origin master
586 git clone subsuper_update_r subsuper_update_r2 &&
587 (cd subsuper_update_r2 &&
588 test_commit "update_subsuper" file &&
589 git submodule add ../subsubsuper_update_r subsubmodule &&
590 git commit -am "subsubmodule" &&
591 git push origin master
593 git clone super_update_r super_update_r2 &&
594 (cd super_update_r2 &&
595 test_commit "update_super" file &&
596 git submodule add ../subsuper_update_r submodule &&
597 git commit -am "submodule" &&
598 git push origin master
600 rm -rf super_update_r2 &&
601 git clone super_update_r super_update_r2 &&
602 (cd super_update_r2 &&
603 git submodule update --init --recursive &&
604 (cd submodule/subsubmodule &&
605 git log > ../../expected
607 (cd .git/modules/submodule/modules/subsubmodule
608 git log > ../../../../../actual
610 test_cmp actual expected