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
473 test_expect_success
'submodule update exit immediately after recursive rebase error' '
475 git checkout master &&
476 git reset --hard HEAD &&
478 git reset --hard HEAD &&
479 git submodule update --recursive
482 test_commit "update_submodule_3" file
485 test_commit "update_submodule2_3" file
488 git add submodule2 &&
489 git commit -m "two_new_submodule_commits" &&
491 git checkout master &&
492 test_commit "conflict2" file &&
493 echo "conflict" > file
495 git checkout HEAD^ &&
497 git rev-parse --max-count=1 HEAD > ../expect
499 git config submodule.submodule.update rebase &&
500 test_must_fail git submodule update &&
502 git rev-parse --max-count=1 HEAD > ../actual
504 test_cmp expect actual