]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7406-submodule-update.sh
Merge branch 'js/doc-patch-text'
[thirdparty/git.git] / t / t7406-submodule-update.sh
CommitLineData
ca2cedba
PH
1#!/bin/sh
2#
3# Copyright (c) 2009 Red Hat, Inc.
4#
5
6test_description='Test updating submodules
7
8This test verifies that "git submodule update" detaches the HEAD of the
42b49178 9submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
ca2cedba
PH
10'
11
12. ./test-lib.sh
13
14
15compare_head()
16{
848351b2
EP
17 sha_master=$(git rev-list --max-count=1 master)
18 sha_head=$(git rev-list --max-count=1 HEAD)
ca2cedba
PH
19
20 test "$sha_master" = "$sha_head"
21}
22
23
24test_expect_success 'setup a submodule tree' '
25 echo file > file &&
26 git add file &&
27 test_tick &&
4bf9dd97 28 git commit -m upstream &&
ca2cedba
PH
29 git clone . super &&
30 git clone super submodule &&
c9c8c56e
SB
31 git clone super rebasing &&
32 git clone super merging &&
322bb6e1 33 git clone super none &&
ca2cedba
PH
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"
c9c8c56e
SB
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"
d5b99f35 61 ) &&
322bb6e1
HV
62 (cd super &&
63 git submodule add ../none none &&
64 test_tick &&
65 git commit -m "none"
c1ab00fb
SB
66 ) &&
67 git clone . recursivesuper &&
8de19d6b 68 ( cd recursivesuper &&
c1ab00fb 69 git submodule add ../super super
322bb6e1 70 )
ca2cedba
PH
71'
72
73test_expect_success 'submodule update detaching the HEAD ' '
74 (cd super/submodule &&
75 git reset --hard HEAD~1
76 ) &&
77 (cd super &&
78 (cd submodule &&
79 compare_head
80 ) &&
81 git submodule update submodule &&
82 cd submodule &&
091a6eb0
JK
83 ! compare_head
84 )
85'
86
87test_expect_success 'submodule update from subdirectory' '
88 (cd super/submodule &&
89 git reset --hard HEAD~1
90 ) &&
91 mkdir super/sub &&
92 (cd super/sub &&
93 (cd ../submodule &&
94 compare_head
95 ) &&
96 git submodule update ../submodule &&
97 cd ../submodule &&
ca2cedba
PH
98 ! compare_head
99 )
100'
101
c1ab00fb
SB
102supersha1=$(git -C super rev-parse HEAD)
103mergingsha1=$(git -C super/merging rev-parse HEAD)
104nonesha1=$(git -C super/none rev-parse HEAD)
105rebasingsha1=$(git -C super/rebasing rev-parse HEAD)
106submodulesha1=$(git -C super/submodule rev-parse HEAD)
107pwd=$(pwd)
108
109cat <<EOF >expect
110Submodule path '../super': checked out '$supersha1'
c1ab00fb
SB
111Submodule path '../super/merging': checked out '$mergingsha1'
112Submodule path '../super/none': checked out '$nonesha1'
113Submodule path '../super/rebasing': checked out '$rebasingsha1'
114Submodule path '../super/submodule': checked out '$submodulesha1'
115EOF
116
c66410ed 117cat <<EOF >expect2
0b7d324e
JS
118Cloning into '$pwd/recursivesuper/super/merging'...
119Cloning into '$pwd/recursivesuper/super/none'...
120Cloning into '$pwd/recursivesuper/super/rebasing'...
121Cloning into '$pwd/recursivesuper/super/submodule'...
c66410ed
SB
122Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
123Submodule 'none' ($pwd/none) registered for path '../super/none'
124Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
125Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
c66410ed 126done.
c66410ed 127done.
c66410ed 128done.
c66410ed
SB
129done.
130EOF
131
c1ab00fb
SB
132test_expect_success 'submodule update --init --recursive from subdirectory' '
133 git -C recursivesuper/super reset --hard HEAD^ &&
134 (cd recursivesuper &&
135 mkdir tmp &&
136 cd tmp &&
c66410ed 137 git submodule update --init --recursive ../super >../../actual 2>../../actual2
c1ab00fb 138 ) &&
1edbaac3 139 test_i18ncmp expect actual &&
0b7d324e
JS
140 sort actual2 >actual2.sorted &&
141 test_i18ncmp expect2 actual2.sorted
c1ab00fb
SB
142'
143
6e7c14e6
SB
144cat <<EOF >expect2
145Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
146EOF
147
148test_expect_success 'submodule update --init from and of subdirectory' '
149 git init withsubs &&
150 (cd withsubs &&
151 mkdir foo &&
152 git submodule add "$(pwd)/../rebasing" foo/sub &&
153 (cd foo &&
154 git submodule deinit -f sub &&
155 git submodule update --init sub 2>../../actual2
156 )
157 ) &&
158 test_i18ncmp expect2 actual2
159'
160
e5f522d6
JL
161test_expect_success 'submodule update does not fetch already present commits' '
162 (cd submodule &&
163 echo line3 >> file &&
164 git add file &&
165 test_tick &&
166 git commit -m "upstream line3"
167 ) &&
168 (cd super/submodule &&
169 head=$(git rev-parse --verify HEAD) &&
bd482d6e 170 echo "Submodule path ${SQ}submodule$SQ: checked out $SQ$head$SQ" > ../../expected &&
e5f522d6
JL
171 git reset --hard HEAD~1
172 ) &&
173 (cd super &&
174 git submodule update > ../actual 2> ../actual.err
175 ) &&
ee653c89 176 test_i18ncmp expected actual &&
7e9055bb 177 test_must_be_empty actual.err
e5f522d6
JL
178'
179
9db31bdf
NMC
180test_expect_success 'submodule update should fail due to local changes' '
181 (cd super/submodule &&
182 git reset --hard HEAD~1 &&
183 echo "local change" > file
184 ) &&
185 (cd super &&
186 (cd submodule &&
187 compare_head
188 ) &&
189 test_must_fail git submodule update submodule
190 )
191'
192test_expect_success 'submodule update should throw away changes with --force ' '
193 (cd super &&
194 (cd submodule &&
195 compare_head
196 ) &&
197 git submodule update --force submodule &&
198 cd submodule &&
199 ! compare_head
200 )
201'
202
01d47215
SZ
203test_expect_success 'submodule update --force forcibly checks out submodules' '
204 (cd super &&
205 (cd submodule &&
206 rm -f file
207 ) &&
208 git submodule update --force submodule &&
209 (cd submodule &&
210 test "$(git status -s file)" = ""
211 )
212 )
213'
214
06b1abb5
TK
215test_expect_success 'submodule update --remote should fetch upstream changes' '
216 (cd submodule &&
217 echo line4 >> file &&
218 git add file &&
219 test_tick &&
220 git commit -m "upstream line4"
221 ) &&
222 (cd super &&
223 git submodule update --remote --force submodule &&
224 cd submodule &&
225 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
226 )
227'
228
4d7bc52b
SB
229test_expect_success 'submodule update --remote should fetch upstream changes with .' '
230 (
231 cd super &&
232 git config -f .gitmodules submodule."submodule".branch "." &&
233 git add .gitmodules &&
234 git commit -m "submodules: update from the respective superproject branch"
235 ) &&
236 (
237 cd submodule &&
238 echo line4a >> file &&
239 git add file &&
240 test_tick &&
241 git commit -m "upstream line4a" &&
242 git checkout -b test-branch &&
243 test_commit on-test-branch
244 ) &&
245 (
246 cd super &&
247 git submodule update --remote --force submodule &&
8de19d6b
SG
248 git -C submodule log -1 --oneline >actual &&
249 git -C ../submodule log -1 --oneline master >expect &&
4d7bc52b
SB
250 test_cmp expect actual &&
251 git checkout -b test-branch &&
252 git submodule update --remote --force submodule &&
8de19d6b
SG
253 git -C submodule log -1 --oneline >actual &&
254 git -C ../submodule log -1 --oneline test-branch >expect &&
4d7bc52b
SB
255 test_cmp expect actual &&
256 git checkout master &&
257 git branch -d test-branch &&
258 git reset --hard HEAD^
259 )
260'
261
06b1abb5
TK
262test_expect_success 'local config should override .gitmodules branch' '
263 (cd submodule &&
4d7bc52b 264 git checkout test-branch &&
06b1abb5
TK
265 echo line5 >> file &&
266 git add file &&
267 test_tick &&
268 git commit -m "upstream line5" &&
269 git checkout master
270 ) &&
271 (cd super &&
272 git config submodule.submodule.branch test-branch &&
273 git submodule update --remote --force submodule &&
274 cd submodule &&
275 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
276 )
277'
278
ca2cedba
PH
279test_expect_success 'submodule update --rebase staying on master' '
280 (cd super/submodule &&
281 git checkout master
282 ) &&
283 (cd super &&
284 (cd submodule &&
285 compare_head
286 ) &&
287 git submodule update --rebase submodule &&
288 cd submodule &&
289 compare_head
290 )
291'
292
42b49178
JH
293test_expect_success 'submodule update --merge staying on master' '
294 (cd super/submodule &&
295 git reset --hard HEAD~1
296 ) &&
297 (cd super &&
298 (cd submodule &&
299 compare_head
300 ) &&
301 git submodule update --merge submodule &&
302 cd submodule &&
303 compare_head
304 )
305'
306
32948425 307test_expect_success 'submodule update - rebase in .git/config' '
ca2cedba 308 (cd super &&
32948425 309 git config submodule.submodule.update rebase
ca2cedba
PH
310 ) &&
311 (cd super/submodule &&
312 git reset --hard HEAD~1
313 ) &&
314 (cd super &&
315 (cd submodule &&
316 compare_head
317 ) &&
318 git submodule update submodule &&
319 cd submodule &&
320 compare_head
321 )
322'
323
32948425 324test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
ca2cedba 325 (cd super &&
32948425 326 git config submodule.submodule.update checkout
ca2cedba
PH
327 ) &&
328 (cd super/submodule &&
329 git reset --hard HEAD~1
330 ) &&
331 (cd super &&
332 (cd submodule &&
333 compare_head
334 ) &&
335 git submodule update --rebase submodule &&
336 cd submodule &&
337 compare_head
338 )
339'
340
42b49178
JH
341test_expect_success 'submodule update - merge in .git/config' '
342 (cd super &&
343 git config submodule.submodule.update merge
344 ) &&
345 (cd super/submodule &&
346 git reset --hard HEAD~1
347 ) &&
348 (cd super &&
349 (cd submodule &&
350 compare_head
351 ) &&
352 git submodule update submodule &&
353 cd submodule &&
354 compare_head
355 )
356'
357
358test_expect_success 'submodule update - checkout in .git/config but --merge given' '
359 (cd super &&
360 git config submodule.submodule.update checkout
361 ) &&
362 (cd super/submodule &&
363 git reset --hard HEAD~1
364 ) &&
365 (cd super &&
366 (cd submodule &&
367 compare_head
368 ) &&
369 git submodule update --merge submodule &&
370 cd submodule &&
371 compare_head
372 )
373'
374
32948425 375test_expect_success 'submodule update - checkout in .git/config' '
ca2cedba 376 (cd super &&
32948425 377 git config submodule.submodule.update checkout
ca2cedba
PH
378 ) &&
379 (cd super/submodule &&
380 git reset --hard HEAD^
381 ) &&
382 (cd super &&
383 (cd submodule &&
384 compare_head
385 ) &&
386 git submodule update submodule &&
387 cd submodule &&
388 ! compare_head
389 )
390'
391
6cb5728c
CP
392test_expect_success 'submodule update - command in .git/config' '
393 (cd super &&
394 git config submodule.submodule.update "!git checkout"
395 ) &&
396 (cd super/submodule &&
397 git reset --hard HEAD^
398 ) &&
399 (cd super &&
400 (cd submodule &&
401 compare_head
402 ) &&
403 git submodule update submodule &&
404 cd submodule &&
405 ! compare_head
406 )
407'
408
83a17fa8
SB
409test_expect_success 'submodule update - command in .gitmodules is ignored' '
410 test_when_finished "git -C super reset --hard HEAD^" &&
411 git -C super config -f .gitmodules submodule.submodule.update "!false" &&
412 git -C super commit -a -m "add command to .gitmodules file" &&
413 git -C super/submodule reset --hard $submodulesha1^ &&
414 git -C super submodule update submodule
415'
416
b08238ac
SB
417cat << EOF >expect
418Execution of 'false $submodulesha1' failed in submodule path 'submodule'
419EOF
420
6cb5728c
CP
421test_expect_success 'submodule update - command in .git/config catches failure' '
422 (cd super &&
423 git config submodule.submodule.update "!false"
424 ) &&
425 (cd super/submodule &&
b08238ac 426 git reset --hard $submodulesha1^
6cb5728c
CP
427 ) &&
428 (cd super &&
b08238ac
SB
429 test_must_fail git submodule update submodule 2>../actual
430 ) &&
1edbaac3 431 test_i18ncmp actual expect
b08238ac
SB
432'
433
434cat << EOF >expect
435Execution of 'false $submodulesha1' failed in submodule path '../submodule'
436EOF
437
438test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' '
439 (cd super &&
440 git config submodule.submodule.update "!false"
441 ) &&
442 (cd super/submodule &&
443 git reset --hard $submodulesha1^
444 ) &&
445 (cd super &&
446 mkdir tmp && cd tmp &&
447 test_must_fail git submodule update ../submodule 2>../../actual
c1e06d11 448 ) &&
1edbaac3 449 test_i18ncmp actual expect
c1e06d11
SB
450'
451
e7b37caf 452test_expect_success 'submodule update - command run for initial population of submodule' '
a4dded01 453 cat >expect <<-EOF &&
e7b37caf 454 Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
a4dded01 455 EOF
e7b37caf 456 rm -rf super/submodule &&
a4dded01 457 test_must_fail git -C super submodule update 2>actual &&
0d75bfe6 458 test_i18ncmp expect actual &&
e7b37caf
SB
459 git -C super submodule update --checkout
460'
461
c1e06d11
SB
462cat << EOF >expect
463Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
464Failed to recurse into submodule path '../super'
465EOF
466
467test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '
468 (cd recursivesuper &&
469 git submodule update --remote super &&
470 git add super &&
471 git commit -m "update to latest to have more than one commit in submodules"
472 ) &&
473 git -C recursivesuper/super config submodule.submodule.update "!false" &&
474 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
475 (cd recursivesuper &&
476 mkdir -p tmp && cd tmp &&
477 test_must_fail git submodule update --recursive ../super 2>../../actual
b08238ac 478 ) &&
1edbaac3 479 test_i18ncmp actual expect
6cb5728c
CP
480'
481
ac1fbbda
JH
482test_expect_success 'submodule init does not copy command into .git/config' '
483 (cd super &&
65799fbc
EN
484 git ls-files -s submodule >out &&
485 H=$(cut -d" " -f2 out) &&
ac1fbbda
JH
486 mkdir submodule1 &&
487 git update-index --add --cacheinfo 160000 $H submodule1 &&
488 git config -f .gitmodules submodule.submodule1.path submodule1 &&
489 git config -f .gitmodules submodule.submodule1.url ../submodule &&
490 git config -f .gitmodules submodule.submodule1.update !false &&
491 git submodule init submodule1 &&
492 echo "none" >expect &&
493 git config submodule.submodule1.update >actual &&
494 test_cmp expect actual
495 )
496'
497
ca2cedba
PH
498test_expect_success 'submodule init picks up rebase' '
499 (cd super &&
c9c8c56e 500 git config -f .gitmodules submodule.rebasing.update rebase &&
ca2cedba 501 git submodule init rebasing &&
c9c8c56e 502 test "rebase" = "$(git config submodule.rebasing.update)"
ca2cedba
PH
503 )
504'
505
42b49178
JH
506test_expect_success 'submodule init picks up merge' '
507 (cd super &&
c9c8c56e 508 git config -f .gitmodules submodule.merging.update merge &&
42b49178 509 git submodule init merging &&
c9c8c56e 510 test "merge" = "$(git config submodule.merging.update)"
42b49178
JH
511 )
512'
513
b200021e 514test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
e7b37caf 515 test_config -C super submodule.submodule.update checkout &&
b200021e
SO
516 (cd super &&
517 rm -rf submodule &&
518 git submodule update submodule &&
519 git status -s submodule >expect &&
520 rm -rf submodule &&
521 git submodule update --merge submodule &&
522 git status -s submodule >actual &&
523 test_cmp expect actual
524 )
525'
526
527test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
e7b37caf 528 test_config -C super submodule.submodule.update checkout &&
b200021e
SO
529 (cd super &&
530 rm -rf submodule &&
531 git submodule update submodule &&
532 git status -s submodule >expect &&
533 rm -rf submodule &&
534 git submodule update --rebase submodule &&
535 git status -s submodule >actual &&
536 test_cmp expect actual
537 )
538'
539
540test_expect_success 'submodule update ignores update=merge config for new submodules' '
541 (cd super &&
542 rm -rf submodule &&
543 git submodule update submodule &&
544 git status -s submodule >expect &&
545 rm -rf submodule &&
546 git config submodule.submodule.update merge &&
547 git submodule update submodule &&
548 git status -s submodule >actual &&
549 git config --unset submodule.submodule.update &&
550 test_cmp expect actual
551 )
552'
553
554test_expect_success 'submodule update ignores update=rebase config for new submodules' '
555 (cd super &&
556 rm -rf submodule &&
557 git submodule update submodule &&
558 git status -s submodule >expect &&
559 rm -rf submodule &&
560 git config submodule.submodule.update rebase &&
561 git submodule update submodule &&
562 git status -s submodule >actual &&
563 git config --unset submodule.submodule.update &&
564 test_cmp expect actual
565 )
566'
567
322bb6e1
HV
568test_expect_success 'submodule init picks up update=none' '
569 (cd super &&
570 git config -f .gitmodules submodule.none.update none &&
571 git submodule init none &&
572 test "none" = "$(git config submodule.none.update)"
573 )
574'
575
576test_expect_success 'submodule update - update=none in .git/config' '
577 (cd super &&
578 git config submodule.submodule.update none &&
579 (cd submodule &&
580 git checkout master &&
581 compare_head
582 ) &&
65799fbc
EN
583 git diff --name-only >out &&
584 grep ^submodule$ out &&
322bb6e1 585 git submodule update &&
65799fbc
EN
586 git diff --name-only >out &&
587 grep ^submodule$ out &&
322bb6e1
HV
588 (cd submodule &&
589 compare_head
590 ) &&
591 git config --unset submodule.submodule.update &&
592 git submodule update submodule
593 )
594'
595
596test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
597 (cd super &&
598 git config submodule.submodule.update none &&
599 (cd submodule &&
600 git checkout master &&
601 compare_head
602 ) &&
65799fbc
EN
603 git diff --name-only >out &&
604 grep ^submodule$ out &&
322bb6e1 605 git submodule update --checkout &&
602813cf
EN
606 git diff --name-only >out &&
607 ! grep ^submodule$ out &&
322bb6e1 608 (cd submodule &&
9fd1080a 609 ! compare_head
322bb6e1
HV
610 ) &&
611 git config --unset submodule.submodule.update
612 )
613'
614
615test_expect_success 'submodule update --init skips submodule with update=none' '
616 (cd super &&
617 git add .gitmodules &&
618 git commit -m ".gitmodules"
619 ) &&
620 git clone super cloned &&
621 (cd cloned &&
622 git submodule update --init &&
7e9055bb
EN
623 test_path_exists submodule/.git &&
624 test_path_is_missing none/.git
322bb6e1
HV
625 )
626'
627
15ffb7cd
FG
628test_expect_success 'submodule update continues after checkout error' '
629 (cd super &&
630 git reset --hard HEAD &&
631 git submodule add ../submodule submodule2 &&
632 git submodule init &&
633 git commit -am "new_submodule" &&
634 (cd submodule2 &&
ad6a599c 635 git rev-parse --verify HEAD >../expect
15ffb7cd
FG
636 ) &&
637 (cd submodule &&
638 test_commit "update_submodule" file
639 ) &&
640 (cd submodule2 &&
641 test_commit "update_submodule2" file
642 ) &&
643 git add submodule &&
644 git add submodule2 &&
645 git commit -m "two_new_submodule_commits" &&
646 (cd submodule &&
647 echo "" > file
648 ) &&
649 git checkout HEAD^ &&
650 test_must_fail git submodule update &&
651 (cd submodule2 &&
ad6a599c 652 git rev-parse --verify HEAD >../actual
15ffb7cd
FG
653 ) &&
654 test_cmp expect actual
655 )
656'
657test_expect_success 'submodule update continues after recursive checkout error' '
658 (cd super &&
659 git reset --hard HEAD &&
660 git checkout master &&
661 git submodule update &&
662 (cd submodule &&
663 git submodule add ../submodule subsubmodule &&
664 git submodule init &&
665 git commit -m "new_subsubmodule"
666 ) &&
667 git add submodule &&
668 git commit -m "update_submodule" &&
669 (cd submodule &&
670 (cd subsubmodule &&
671 test_commit "update_subsubmodule" file
672 ) &&
673 git add subsubmodule &&
674 test_commit "update_submodule_again" file &&
675 (cd subsubmodule &&
676 test_commit "update_subsubmodule_again" file
677 ) &&
678 test_commit "update_submodule_again_again" file
679 ) &&
680 (cd submodule2 &&
ad6a599c 681 git rev-parse --verify HEAD >../expect &&
15ffb7cd
FG
682 test_commit "update_submodule2_again" file
683 ) &&
684 git add submodule &&
685 git add submodule2 &&
686 git commit -m "new_commits" &&
687 git checkout HEAD^ &&
688 (cd submodule &&
689 git checkout HEAD^ &&
690 (cd subsubmodule &&
691 echo "" > file
692 )
693 ) &&
694 test_must_fail git submodule update --recursive &&
695 (cd submodule2 &&
ad6a599c 696 git rev-parse --verify HEAD >../actual
15ffb7cd
FG
697 ) &&
698 test_cmp expect actual
699 )
700'
701
702test_expect_success 'submodule update exit immediately in case of merge conflict' '
703 (cd super &&
704 git checkout master &&
705 git reset --hard HEAD &&
706 (cd submodule &&
707 (cd subsubmodule &&
708 git reset --hard HEAD
709 )
710 ) &&
711 git submodule update --recursive &&
712 (cd submodule &&
713 test_commit "update_submodule_2" file
714 ) &&
715 (cd submodule2 &&
716 test_commit "update_submodule2_2" file
717 ) &&
718 git add submodule &&
719 git add submodule2 &&
720 git commit -m "two_new_submodule_commits" &&
721 (cd submodule &&
722 git checkout master &&
723 test_commit "conflict" file &&
724 echo "conflict" > file
725 ) &&
726 git checkout HEAD^ &&
727 (cd submodule2 &&
ad6a599c 728 git rev-parse --verify HEAD >../expect
15ffb7cd
FG
729 ) &&
730 git config submodule.submodule.update merge &&
731 test_must_fail git submodule update &&
732 (cd submodule2 &&
ad6a599c 733 git rev-parse --verify HEAD >../actual
15ffb7cd
FG
734 ) &&
735 test_cmp expect actual
736 )
737'
501770e1 738
15ffb7cd
FG
739test_expect_success 'submodule update exit immediately after recursive rebase error' '
740 (cd super &&
741 git checkout master &&
742 git reset --hard HEAD &&
743 (cd submodule &&
744 git reset --hard HEAD &&
745 git submodule update --recursive
746 ) &&
747 (cd submodule &&
748 test_commit "update_submodule_3" file
749 ) &&
750 (cd submodule2 &&
751 test_commit "update_submodule2_3" file
752 ) &&
753 git add submodule &&
754 git add submodule2 &&
755 git commit -m "two_new_submodule_commits" &&
756 (cd submodule &&
757 git checkout master &&
758 test_commit "conflict2" file &&
759 echo "conflict" > file
760 ) &&
761 git checkout HEAD^ &&
762 (cd submodule2 &&
ad6a599c 763 git rev-parse --verify HEAD >../expect
15ffb7cd
FG
764 ) &&
765 git config submodule.submodule.update rebase &&
766 test_must_fail git submodule update &&
767 (cd submodule2 &&
ad6a599c 768 git rev-parse --verify HEAD >../actual
15ffb7cd
FG
769 ) &&
770 test_cmp expect actual
771 )
772'
501770e1
FG
773
774test_expect_success 'add different submodules to the same path' '
775 (cd super &&
776 git submodule add ../submodule s1 &&
777 test_must_fail git submodule add ../merging s1
778 )
779'
780
781test_expect_success 'submodule add places git-dir in superprojects git-dir' '
782 (cd super &&
783 mkdir deeper &&
784 git submodule add ../submodule deeper/submodule &&
785 (cd deeper/submodule &&
786 git log > ../../expected
787 ) &&
788 (cd .git/modules/deeper/submodule &&
789 git log > ../../../../actual
790 ) &&
dcbaa0b3 791 test_cmp expected actual
501770e1
FG
792 )
793'
794
795test_expect_success 'submodule update places git-dir in superprojects git-dir' '
796 (cd super &&
797 git commit -m "added submodule"
798 ) &&
799 git clone super super2 &&
800 (cd super2 &&
801 git submodule init deeper/submodule &&
802 git submodule update &&
803 (cd deeper/submodule &&
804 git log > ../../expected
805 ) &&
806 (cd .git/modules/deeper/submodule &&
807 git log > ../../../../actual
808 ) &&
dcbaa0b3 809 test_cmp expected actual
501770e1
FG
810 )
811'
812
813test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
814 (cd super2 &&
815 (cd deeper/submodule &&
816 git submodule add ../submodule subsubmodule &&
817 (cd subsubmodule &&
818 git log > ../../../expected
819 ) &&
820 git commit -m "added subsubmodule" &&
ae74f7d2 821 git push origin :
501770e1
FG
822 ) &&
823 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
824 git log > ../../../../../actual
825 ) &&
826 git add deeper/submodule &&
827 git commit -m "update submodule" &&
ae74f7d2 828 git push origin : &&
dcbaa0b3 829 test_cmp expected actual
501770e1
FG
830 )
831'
832
833test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
834 mkdir super_update_r &&
835 (cd super_update_r &&
836 git init --bare
837 ) &&
838 mkdir subsuper_update_r &&
839 (cd subsuper_update_r &&
840 git init --bare
841 ) &&
842 mkdir subsubsuper_update_r &&
843 (cd subsubsuper_update_r &&
844 git init --bare
845 ) &&
846 git clone subsubsuper_update_r subsubsuper_update_r2 &&
847 (cd subsubsuper_update_r2 &&
848 test_commit "update_subsubsuper" file &&
849 git push origin master
850 ) &&
851 git clone subsuper_update_r subsuper_update_r2 &&
852 (cd subsuper_update_r2 &&
853 test_commit "update_subsuper" file &&
854 git submodule add ../subsubsuper_update_r subsubmodule &&
855 git commit -am "subsubmodule" &&
856 git push origin master
857 ) &&
858 git clone super_update_r super_update_r2 &&
859 (cd super_update_r2 &&
860 test_commit "update_super" file &&
861 git submodule add ../subsuper_update_r submodule &&
862 git commit -am "submodule" &&
863 git push origin master
864 ) &&
865 rm -rf super_update_r2 &&
866 git clone super_update_r super_update_r2 &&
867 (cd super_update_r2 &&
75bf5e60 868 git submodule update --init --recursive >actual &&
d851ffb9 869 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
501770e1
FG
870 (cd submodule/subsubmodule &&
871 git log > ../../expected
872 ) &&
e974e06d 873 (cd .git/modules/submodule/modules/subsubmodule &&
501770e1 874 git log > ../../../../../actual
e974e06d 875 ) &&
dcbaa0b3 876 test_cmp expected actual
501770e1
FG
877 )
878'
879
1017c1ab
JL
880test_expect_success 'submodule add properly re-creates deeper level submodules' '
881 (cd super &&
882 git reset --hard master &&
883 rm -rf deeper/ &&
4b7c286e 884 git submodule add --force ../submodule deeper/submodule
1017c1ab
JL
885 )
886'
887
69c30517
JL
888test_expect_success 'submodule update properly revives a moved submodule' '
889 (cd super &&
b397ea48 890 H=$(git rev-parse --short HEAD) &&
69c30517 891 git commit -am "pre move" &&
b397ea48 892 H2=$(git rev-parse --short HEAD) &&
65799fbc
EN
893 git status >out &&
894 sed "s/$H/XXX/" out >expect &&
e974e06d 895 H=$(cd submodule2 && git rev-parse HEAD) &&
69c30517
JL
896 git rm --cached submodule2 &&
897 rm -rf submodule2 &&
898 mkdir -p "moved/sub module" &&
899 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
8de19d6b 900 git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
69c30517
JL
901 git commit -am "post move" &&
902 git submodule update &&
65799fbc
EN
903 git status > out &&
904 sed "s/$H2/XXX/" out >actual &&
69c30517
JL
905 test_cmp expect actual
906 )
907'
908
6eafa6d0
JL
909test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
910 mkdir -p linked/dir &&
911 ln -s linked/dir linkto &&
275cd184
FG
912 (cd linkto &&
913 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
914 (cd super &&
915 git submodule update --init --recursive
916 )
6eafa6d0
JL
917 )
918'
919
275cd184 920test_expect_success 'submodule update clone shallow submodule' '
d4470c5a 921 test_when_finished "rm -rf super3" &&
65799fbc 922 first=$(git -C cloned rev-parse HEAD:submodule) &&
d4470c5a 923 second=$(git -C submodule rev-parse HEAD) &&
967d7f89 924 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
275cd184 925 git clone cloned super3 &&
99094a7a 926 pwd=$(pwd) &&
d4470c5a
SB
927 (
928 cd super3 &&
929 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
930 mv -f .gitmodules.tmp .gitmodules &&
931 git submodule update --init --depth=$commit_count &&
65799fbc
EN
932 git -C submodule log --oneline >out &&
933 test_line_count = 1 out
d4470c5a 934 )
36141282
JL
935'
936
6cbf454a
SB
937test_expect_success 'submodule update clone shallow submodule outside of depth' '
938 test_when_finished "rm -rf super3" &&
939 git clone cloned super3 &&
940 pwd=$(pwd) &&
941 (
942 cd super3 &&
943 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
944 mv -f .gitmodules.tmp .gitmodules &&
ab0c5f50
JT
945 # Some protocol versions (e.g. 2) support fetching
946 # unadvertised objects, so restrict this test to v0.
947 test_must_fail env GIT_TEST_PROTOCOL_VERSION= \
948 git submodule update --init --depth=1 2>actual &&
6cbf454a
SB
949 test_i18ngrep "Direct fetching of that commit failed." actual &&
950 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
951 git submodule update --init --depth=1 >actual &&
65799fbc
EN
952 git -C submodule log --oneline >out &&
953 test_line_count = 1 out
6cbf454a
SB
954 )
955'
956
36141282
JL
957test_expect_success 'submodule update --recursive drops module name before recursing' '
958 (cd super2 &&
959 (cd deeper/submodule/subsubmodule &&
960 git checkout HEAD^
961 ) &&
962 git submodule update --recursive deeper/submodule >actual &&
963 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
275cd184
FG
964 )
965'
2335b870
SB
966
967test_expect_success 'submodule update can be run in parallel' '
968 (cd super2 &&
969 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
970 grep "7 tasks" trace.out &&
971 git config submodule.fetchJobs 8 &&
972 GIT_TRACE=$(pwd)/trace.out git submodule update &&
973 grep "8 tasks" trace.out &&
974 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
975 grep "9 tasks" trace.out
976 )
977'
72290d6a
SB
978
979test_expect_success 'git clone passes the parallel jobs config on to submodules' '
980 test_when_finished "rm -rf super4" &&
981 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
982 grep "7 tasks" trace.out &&
983 rm -rf super4 &&
984 git config --global submodule.fetchJobs 8 &&
985 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
986 grep "8 tasks" trace.out &&
987 rm -rf super4 &&
988 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
989 grep "9 tasks" trace.out &&
990 rm -rf super4
991'
992
ca2cedba 993test_done