add update 'none' flag to disable update of submodule by default
[git/debian.git] / t / t7406-submodule-update.sh
blob58877d3b38786a6811e7ddbd78d54318c5abdece
1 #!/bin/sh
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.
12 . ./test-lib.sh
15 compare_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' '
25 echo file > file &&
26 git add file &&
27 test_tick &&
28 git commit -m upstream &&
29 git clone . super &&
30 git clone super submodule &&
31 git clone super rebasing &&
32 git clone super merging &&
33 git clone super none &&
34 (cd super &&
35 git submodule add ../submodule submodule &&
36 test_tick &&
37 git commit -m "submodule" &&
38 git submodule init submodule
39 ) &&
40 (cd submodule &&
41 echo "line2" > file &&
42 git add file &&
43 git commit -m "Commit 2"
44 ) &&
45 (cd super &&
46 (cd submodule &&
47 git pull --rebase origin
48 ) &&
49 git add submodule &&
50 git commit -m "submodule update"
51 ) &&
52 (cd super &&
53 git submodule add ../rebasing rebasing &&
54 test_tick &&
55 git commit -m "rebasing"
56 ) &&
57 (cd super &&
58 git submodule add ../merging merging &&
59 test_tick &&
60 git commit -m "rebasing"
62 (cd super &&
63 git submodule add ../none none &&
64 test_tick &&
65 git commit -m "none"
69 test_expect_success 'submodule update detaching the HEAD ' '
70 (cd super/submodule &&
71 git reset --hard HEAD~1
72 ) &&
73 (cd super &&
74 (cd submodule &&
75 compare_head
76 ) &&
77 git submodule update submodule &&
78 cd submodule &&
79 ! compare_head
83 apos="'";
84 test_expect_success 'submodule update does not fetch already present commits' '
85 (cd submodule &&
86 echo line3 >> file &&
87 git add file &&
88 test_tick &&
89 git commit -m "upstream line3"
90 ) &&
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
95 ) &&
96 (cd super &&
97 git submodule update > ../actual 2> ../actual.err
98 ) &&
99 test_i18ncmp expected actual &&
100 ! test -s actual.err
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
107 ) &&
108 (cd super &&
109 (cd submodule &&
110 compare_head
111 ) &&
112 test_must_fail git submodule update submodule
115 test_expect_success 'submodule update should throw away changes with --force ' '
116 (cd super &&
117 (cd submodule &&
118 compare_head
119 ) &&
120 git submodule update --force submodule &&
121 cd submodule &&
122 ! compare_head
126 test_expect_success 'submodule update --rebase staying on master' '
127 (cd super/submodule &&
128 git checkout master
129 ) &&
130 (cd super &&
131 (cd submodule &&
132 compare_head
133 ) &&
134 git submodule update --rebase submodule &&
135 cd submodule &&
136 compare_head
140 test_expect_success 'submodule update --merge staying on master' '
141 (cd super/submodule &&
142 git reset --hard HEAD~1
143 ) &&
144 (cd super &&
145 (cd submodule &&
146 compare_head
147 ) &&
148 git submodule update --merge submodule &&
149 cd submodule &&
150 compare_head
154 test_expect_success 'submodule update - rebase in .git/config' '
155 (cd super &&
156 git config submodule.submodule.update rebase
157 ) &&
158 (cd super/submodule &&
159 git reset --hard HEAD~1
160 ) &&
161 (cd super &&
162 (cd submodule &&
163 compare_head
164 ) &&
165 git submodule update submodule &&
166 cd submodule &&
167 compare_head
171 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
172 (cd super &&
173 git config submodule.submodule.update checkout
174 ) &&
175 (cd super/submodule &&
176 git reset --hard HEAD~1
177 ) &&
178 (cd super &&
179 (cd submodule &&
180 compare_head
181 ) &&
182 git submodule update --rebase submodule &&
183 cd submodule &&
184 compare_head
188 test_expect_success 'submodule update - merge in .git/config' '
189 (cd super &&
190 git config submodule.submodule.update merge
191 ) &&
192 (cd super/submodule &&
193 git reset --hard HEAD~1
194 ) &&
195 (cd super &&
196 (cd submodule &&
197 compare_head
198 ) &&
199 git submodule update submodule &&
200 cd submodule &&
201 compare_head
205 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
206 (cd super &&
207 git config submodule.submodule.update checkout
208 ) &&
209 (cd super/submodule &&
210 git reset --hard HEAD~1
211 ) &&
212 (cd super &&
213 (cd submodule &&
214 compare_head
215 ) &&
216 git submodule update --merge submodule &&
217 cd submodule &&
218 compare_head
222 test_expect_success 'submodule update - checkout in .git/config' '
223 (cd super &&
224 git config submodule.submodule.update checkout
225 ) &&
226 (cd super/submodule &&
227 git reset --hard HEAD^
228 ) &&
229 (cd super &&
230 (cd submodule &&
231 compare_head
232 ) &&
233 git submodule update submodule &&
234 cd submodule &&
235 ! compare_head
239 test_expect_success 'submodule init picks up rebase' '
240 (cd super &&
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' '
248 (cd super &&
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' '
256 (cd super &&
257 rm -rf submodule &&
258 git submodule update submodule &&
259 git status -s submodule >expect &&
260 rm -rf submodule &&
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' '
268 (cd super &&
269 rm -rf submodule &&
270 git submodule update submodule &&
271 git status -s submodule >expect &&
272 rm -rf submodule &&
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' '
280 (cd super &&
281 rm -rf submodule &&
282 git submodule update submodule &&
283 git status -s submodule >expect &&
284 rm -rf submodule &&
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' '
294 (cd super &&
295 rm -rf submodule &&
296 git submodule update submodule &&
297 git status -s submodule >expect &&
298 rm -rf submodule &&
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' '
308 (cd super &&
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' '
316 (cd super &&
317 git config submodule.submodule.update none &&
318 (cd submodule &&
319 git checkout master &&
320 compare_head
321 ) &&
322 git diff --raw | grep " submodule" &&
323 git submodule update &&
324 git diff --raw | grep " submodule" &&
325 (cd submodule &&
326 compare_head
327 ) &&
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' '
334 (cd super &&
335 git config submodule.submodule.update none &&
336 (cd submodule &&
337 git checkout master &&
338 compare_head
339 ) &&
340 git diff --raw | grep " submodule" &&
341 git submodule update --checkout &&
342 test_must_fail git diff --raw \| grep " submodule" &&
343 (cd submodule &&
344 test_must_fail compare_head
345 ) &&
346 git config --unset submodule.submodule.update
350 test_expect_success 'submodule update --init skips submodule with update=none' '
351 (cd super &&
352 git add .gitmodules &&
353 git commit -m ".gitmodules"
354 ) &&
355 git clone super cloned &&
356 (cd 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' '
364 (cd super &&
365 git reset --hard HEAD &&
366 git submodule add ../submodule submodule2 &&
367 git submodule init &&
368 git commit -am "new_submodule" &&
369 (cd submodule2 &&
370 git rev-parse --max-count=1 HEAD > ../expect
371 ) &&
372 (cd submodule &&
373 test_commit "update_submodule" file
374 ) &&
375 (cd submodule2 &&
376 test_commit "update_submodule2" file
377 ) &&
378 git add submodule &&
379 git add submodule2 &&
380 git commit -m "two_new_submodule_commits" &&
381 (cd submodule &&
382 echo "" > file
383 ) &&
384 git checkout HEAD^ &&
385 test_must_fail git submodule update &&
386 (cd submodule2 &&
387 git rev-parse --max-count=1 HEAD > ../actual
388 ) &&
389 test_cmp expect actual
392 test_expect_success 'submodule update continues after recursive checkout error' '
393 (cd super &&
394 git reset --hard HEAD &&
395 git checkout master &&
396 git submodule update &&
397 (cd submodule &&
398 git submodule add ../submodule subsubmodule &&
399 git submodule init &&
400 git commit -m "new_subsubmodule"
401 ) &&
402 git add submodule &&
403 git commit -m "update_submodule" &&
404 (cd submodule &&
405 (cd subsubmodule &&
406 test_commit "update_subsubmodule" file
407 ) &&
408 git add subsubmodule &&
409 test_commit "update_submodule_again" file &&
410 (cd subsubmodule &&
411 test_commit "update_subsubmodule_again" file
412 ) &&
413 test_commit "update_submodule_again_again" file
414 ) &&
415 (cd submodule2 &&
416 git rev-parse --max-count=1 HEAD > ../expect &&
417 test_commit "update_submodule2_again" file
418 ) &&
419 git add submodule &&
420 git add submodule2 &&
421 git commit -m "new_commits" &&
422 git checkout HEAD^ &&
423 (cd submodule &&
424 git checkout HEAD^ &&
425 (cd subsubmodule &&
426 echo "" > file
428 ) &&
429 test_must_fail git submodule update --recursive &&
430 (cd submodule2 &&
431 git rev-parse --max-count=1 HEAD > ../actual
432 ) &&
433 test_cmp expect actual
437 test_expect_success 'submodule update exit immediately in case of merge conflict' '
438 (cd super &&
439 git checkout master &&
440 git reset --hard HEAD &&
441 (cd submodule &&
442 (cd subsubmodule &&
443 git reset --hard HEAD
445 ) &&
446 git submodule update --recursive &&
447 (cd submodule &&
448 test_commit "update_submodule_2" file
449 ) &&
450 (cd submodule2 &&
451 test_commit "update_submodule2_2" file
452 ) &&
453 git add submodule &&
454 git add submodule2 &&
455 git commit -m "two_new_submodule_commits" &&
456 (cd submodule &&
457 git checkout master &&
458 test_commit "conflict" file &&
459 echo "conflict" > file
460 ) &&
461 git checkout HEAD^ &&
462 (cd submodule2 &&
463 git rev-parse --max-count=1 HEAD > ../expect
464 ) &&
465 git config submodule.submodule.update merge &&
466 test_must_fail git submodule update &&
467 (cd submodule2 &&
468 git rev-parse --max-count=1 HEAD > ../actual
469 ) &&
470 test_cmp expect actual
473 test_expect_success 'submodule update exit immediately after recursive rebase error' '
474 (cd super &&
475 git checkout master &&
476 git reset --hard HEAD &&
477 (cd submodule &&
478 git reset --hard HEAD &&
479 git submodule update --recursive
480 ) &&
481 (cd submodule &&
482 test_commit "update_submodule_3" file
483 ) &&
484 (cd submodule2 &&
485 test_commit "update_submodule2_3" file
486 ) &&
487 git add submodule &&
488 git add submodule2 &&
489 git commit -m "two_new_submodule_commits" &&
490 (cd submodule &&
491 git checkout master &&
492 test_commit "conflict2" file &&
493 echo "conflict" > file
494 ) &&
495 git checkout HEAD^ &&
496 (cd submodule2 &&
497 git rev-parse --max-count=1 HEAD > ../expect
498 ) &&
499 git config submodule.submodule.update rebase &&
500 test_must_fail git submodule update &&
501 (cd submodule2 &&
502 git rev-parse --max-count=1 HEAD > ../actual
503 ) &&
504 test_cmp expect actual
507 test_done