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 &&
34 git submodule add ../submodule submodule &&
36 git commit -m "submodule" &&
37 git submodule init submodule
40 echo "line2" > file &&
42 git commit -m "Commit 2"
46 git pull --rebase origin
49 git commit -m "submodule update"
52 git submodule add ../rebasing rebasing &&
54 git commit -m "rebasing"
57 git submodule add ../merging merging &&
59 git commit -m "rebasing"
63 test_expect_success 'submodule update detaching the HEAD ' '
64 (cd super/submodule &&
65 git reset --hard HEAD~1
71 git submodule update submodule &&
78 test_expect_success 'submodule update does not fetch already present commits' '
83 git commit -m "upstream line3"
85 (cd super/submodule &&
86 head=$(git rev-parse --verify HEAD) &&
87 echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
88 git reset --hard HEAD~1
91 git submodule update > ../actual 2> ../actual.err
93 test_i18ncmp expected actual &&
97 test_expect_success 'submodule update should fail due to local changes' '
98 (cd super/submodule &&
99 git reset --hard HEAD~1 &&
100 echo "local change" > file
106 test_must_fail git submodule update submodule
109 test_expect_success 'submodule update should throw away changes with --force ' '
114 git submodule update --force submodule &&
120 test_expect_success 'submodule update --rebase staying on master' '
121 (cd super/submodule &&
128 git submodule update --rebase submodule &&
134 test_expect_success 'submodule update --merge staying on master' '
135 (cd super/submodule &&
136 git reset --hard HEAD~1
142 git submodule update --merge submodule &&
148 test_expect_success 'submodule update - rebase in .git/config' '
150 git config submodule.submodule.update rebase
152 (cd super/submodule &&
153 git reset --hard HEAD~1
159 git submodule update submodule &&
165 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
167 git config submodule.submodule.update checkout
169 (cd super/submodule &&
170 git reset --hard HEAD~1
176 git submodule update --rebase submodule &&
182 test_expect_success 'submodule update - merge in .git/config' '
184 git config submodule.submodule.update merge
186 (cd super/submodule &&
187 git reset --hard HEAD~1
193 git submodule update submodule &&
199 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
201 git config submodule.submodule.update checkout
203 (cd super/submodule &&
204 git reset --hard HEAD~1
210 git submodule update --merge submodule &&
216 test_expect_success 'submodule update - checkout in .git/config' '
218 git config submodule.submodule.update checkout
220 (cd super/submodule &&
221 git reset --hard HEAD^
227 git submodule update submodule &&
233 test_expect_success 'submodule init picks up rebase' '
235 git config -f .gitmodules submodule.rebasing.update rebase &&
236 git submodule init rebasing &&
237 test "rebase" = "$(git config submodule.rebasing.update)"
241 test_expect_success 'submodule init picks up merge' '
243 git config -f .gitmodules submodule.merging.update merge &&
244 git submodule init merging &&
245 test "merge" = "$(git config submodule.merging.update)"
249 test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
252 git submodule update submodule &&
253 git status -s submodule >expect &&
255 git submodule update --merge submodule &&
256 git status -s submodule >actual &&
257 test_cmp expect actual
261 test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
264 git submodule update submodule &&
265 git status -s submodule >expect &&
267 git submodule update --rebase submodule &&
268 git status -s submodule >actual &&
269 test_cmp expect actual
273 test_expect_success 'submodule update ignores update=merge config for new submodules' '
276 git submodule update submodule &&
277 git status -s submodule >expect &&
279 git config submodule.submodule.update merge &&
280 git submodule update submodule &&
281 git status -s submodule >actual &&
282 git config --unset submodule.submodule.update &&
283 test_cmp expect actual
287 test_expect_success 'submodule update ignores update=rebase config for new submodules' '
290 git submodule update submodule &&
291 git status -s submodule >expect &&
293 git config submodule.submodule.update rebase &&
294 git submodule update submodule &&
295 git status -s submodule >actual &&
296 git config --unset submodule.submodule.update &&
297 test_cmp expect actual
301 test_expect_success 'submodule update continues after checkout error' '
303 git reset --hard HEAD &&
304 git submodule add ../submodule submodule2 &&
305 git submodule init &&
306 git commit -am "new_submodule" &&
308 git rev-parse --max-count=1 HEAD > ../expect
311 test_commit "update_submodule" file
314 test_commit "update_submodule2" file
317 git add submodule2 &&
318 git commit -m "two_new_submodule_commits" &&
322 git checkout HEAD^ &&
323 test_must_fail git submodule update &&
325 git rev-parse --max-count=1 HEAD > ../actual
327 test_cmp expect actual
330 test_expect_success 'submodule update continues after recursive checkout error' '
332 git reset --hard HEAD &&
333 git checkout master &&
334 git submodule update &&
336 git submodule add ../submodule subsubmodule &&
337 git submodule init &&
338 git commit -m "new_subsubmodule"
341 git commit -m "update_submodule" &&
344 test_commit "update_subsubmodule" file
346 git add subsubmodule &&
347 test_commit "update_submodule_again" file &&
349 test_commit "update_subsubmodule_again" file
351 test_commit "update_submodule_again_again" file
354 git rev-parse --max-count=1 HEAD > ../expect &&
355 test_commit "update_submodule2_again" file
358 git add submodule2 &&
359 git commit -m "new_commits" &&
360 git checkout HEAD^ &&
362 git checkout HEAD^ &&
367 test_must_fail git submodule update --recursive &&
369 git rev-parse --max-count=1 HEAD > ../actual
371 test_cmp expect actual
375 test_expect_success 'submodule update exit immediately in case of merge conflict' '
377 git checkout master &&
378 git reset --hard HEAD &&
381 git reset --hard HEAD
384 git submodule update --recursive &&
386 test_commit "update_submodule_2" file
389 test_commit "update_submodule2_2" file
392 git add submodule2 &&
393 git commit -m "two_new_submodule_commits" &&
395 git checkout master &&
396 test_commit "conflict" file &&
397 echo "conflict" > file
399 git checkout HEAD^ &&
401 git rev-parse --max-count=1 HEAD > ../expect
403 git config submodule.submodule.update merge &&
404 test_must_fail git submodule update &&
406 git rev-parse --max-count=1 HEAD > ../actual
408 test_cmp expect actual
412 test_expect_success 'submodule update exit immediately after recursive rebase error' '
414 git checkout master &&
415 git reset --hard HEAD &&
417 git reset --hard HEAD &&
418 git submodule update --recursive
421 test_commit "update_submodule_3" file
424 test_commit "update_submodule2_3" file
427 git add submodule2 &&
428 git commit -m "two_new_submodule_commits" &&
430 git checkout master &&
431 test_commit "conflict2" file &&
432 echo "conflict" > file
434 git checkout HEAD^ &&
436 git rev-parse --max-count=1 HEAD > ../expect
438 git config submodule.submodule.update rebase &&
439 test_must_fail git submodule update &&
441 git rev-parse --max-count=1 HEAD > ../actual
443 test_cmp expect actual
447 test_expect_success 'add different submodules to the same path' '
449 git submodule add ../submodule s1 &&
450 test_must_fail git submodule add ../merging s1
454 test_expect_success 'submodule add places git-dir in superprojects git-dir' '
457 git submodule add ../submodule deeper/submodule &&
458 (cd deeper/submodule &&
459 git log > ../../expected
461 (cd .git/modules/deeper/submodule &&
462 git log > ../../../../actual
464 test_cmp actual expected
468 test_expect_success 'submodule update places git-dir in superprojects git-dir' '
470 git commit -m "added submodule"
472 git clone super super2 &&
474 git submodule init deeper/submodule &&
475 git submodule update &&
476 (cd deeper/submodule &&
477 git log > ../../expected
479 (cd .git/modules/deeper/submodule &&
480 git log > ../../../../actual
482 test_cmp actual expected
486 test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
488 (cd deeper/submodule &&
489 git submodule add ../submodule subsubmodule &&
491 git log > ../../../expected
493 git commit -m "added subsubmodule" &&
496 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
497 git log > ../../../../../actual
499 git add deeper/submodule &&
500 git commit -m "update submodule" &&
502 test_cmp actual expected
506 test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
507 mkdir super_update_r &&
508 (cd super_update_r &&
511 mkdir subsuper_update_r &&
512 (cd subsuper_update_r &&
515 mkdir subsubsuper_update_r &&
516 (cd subsubsuper_update_r &&
519 git clone subsubsuper_update_r subsubsuper_update_r2 &&
520 (cd subsubsuper_update_r2 &&
521 test_commit "update_subsubsuper" file &&
522 git push origin master
524 git clone subsuper_update_r subsuper_update_r2 &&
525 (cd subsuper_update_r2 &&
526 test_commit "update_subsuper" file &&
527 git submodule add ../subsubsuper_update_r subsubmodule &&
528 git commit -am "subsubmodule" &&
529 git push origin master
531 git clone super_update_r super_update_r2 &&
532 (cd super_update_r2 &&
533 test_commit "update_super" file &&
534 git submodule add ../subsuper_update_r submodule &&
535 git commit -am "submodule" &&
536 git push origin master
538 rm -rf super_update_r2 &&
539 git clone super_update_r super_update_r2 &&
540 (cd super_update_r2 &&
541 git submodule update --init --recursive &&
542 (cd submodule/subsubmodule &&
543 git log > ../../expected
545 (cd .git/modules/submodule/modules/subsubmodule
546 git log > ../../../../../actual
548 test_cmp actual expected