]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7406-submodule-update.sh
Merge branch 'bc/sha-256-part-2'
[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
e904deb8 409test_expect_success 'submodule update - command in .gitmodules is rejected' '
83a17fa8
SB
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^ &&
e904deb8 414 test_must_fail git -C super submodule update submodule
83a17fa8
SB
415'
416
bb92255e
JN
417test_expect_success 'fsck detects command in .gitmodules' '
418 git init command-in-gitmodules &&
419 (
420 cd command-in-gitmodules &&
421 git submodule add ../submodule submodule &&
422 test_commit adding-submodule &&
423
424 git config -f .gitmodules submodule.submodule.update "!false" &&
425 git add .gitmodules &&
426 test_commit configuring-update &&
427 test_must_fail git fsck
428 )
83a17fa8
SB
429'
430
b08238ac
SB
431cat << EOF >expect
432Execution of 'false $submodulesha1' failed in submodule path 'submodule'
433EOF
434
6cb5728c
CP
435test_expect_success 'submodule update - command in .git/config catches failure' '
436 (cd super &&
437 git config submodule.submodule.update "!false"
438 ) &&
439 (cd super/submodule &&
b08238ac 440 git reset --hard $submodulesha1^
6cb5728c
CP
441 ) &&
442 (cd super &&
b08238ac
SB
443 test_must_fail git submodule update submodule 2>../actual
444 ) &&
1edbaac3 445 test_i18ncmp actual expect
b08238ac
SB
446'
447
448cat << EOF >expect
449Execution of 'false $submodulesha1' failed in submodule path '../submodule'
450EOF
451
452test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' '
453 (cd super &&
454 git config submodule.submodule.update "!false"
455 ) &&
456 (cd super/submodule &&
457 git reset --hard $submodulesha1^
458 ) &&
459 (cd super &&
460 mkdir tmp && cd tmp &&
461 test_must_fail git submodule update ../submodule 2>../../actual
c1e06d11 462 ) &&
1edbaac3 463 test_i18ncmp actual expect
c1e06d11
SB
464'
465
e7b37caf 466test_expect_success 'submodule update - command run for initial population of submodule' '
a4dded01 467 cat >expect <<-EOF &&
e7b37caf 468 Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
a4dded01 469 EOF
e7b37caf 470 rm -rf super/submodule &&
a4dded01 471 test_must_fail git -C super submodule update 2>actual &&
0d75bfe6 472 test_i18ncmp expect actual &&
e7b37caf
SB
473 git -C super submodule update --checkout
474'
475
c1e06d11
SB
476cat << EOF >expect
477Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
478Failed to recurse into submodule path '../super'
479EOF
480
481test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '
482 (cd recursivesuper &&
483 git submodule update --remote super &&
484 git add super &&
485 git commit -m "update to latest to have more than one commit in submodules"
486 ) &&
487 git -C recursivesuper/super config submodule.submodule.update "!false" &&
488 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
489 (cd recursivesuper &&
490 mkdir -p tmp && cd tmp &&
491 test_must_fail git submodule update --recursive ../super 2>../../actual
b08238ac 492 ) &&
1edbaac3 493 test_i18ncmp actual expect
6cb5728c
CP
494'
495
ac1fbbda 496test_expect_success 'submodule init does not copy command into .git/config' '
e904deb8
JN
497 test_when_finished "git -C super update-index --force-remove submodule1" &&
498 test_when_finished git config -f super/.gitmodules \
499 --remove-section submodule.submodule1 &&
ac1fbbda 500 (cd super &&
65799fbc
EN
501 git ls-files -s submodule >out &&
502 H=$(cut -d" " -f2 out) &&
ac1fbbda
JH
503 mkdir submodule1 &&
504 git update-index --add --cacheinfo 160000 $H submodule1 &&
505 git config -f .gitmodules submodule.submodule1.path submodule1 &&
506 git config -f .gitmodules submodule.submodule1.url ../submodule &&
507 git config -f .gitmodules submodule.submodule1.update !false &&
e904deb8
JN
508 test_must_fail git submodule init submodule1 &&
509 test_expect_code 1 git config submodule.submodule1.update >actual &&
510 test_must_be_empty actual
ac1fbbda
JH
511 )
512'
513
ca2cedba
PH
514test_expect_success 'submodule init picks up rebase' '
515 (cd super &&
c9c8c56e 516 git config -f .gitmodules submodule.rebasing.update rebase &&
ca2cedba 517 git submodule init rebasing &&
c9c8c56e 518 test "rebase" = "$(git config submodule.rebasing.update)"
ca2cedba
PH
519 )
520'
521
42b49178
JH
522test_expect_success 'submodule init picks up merge' '
523 (cd super &&
c9c8c56e 524 git config -f .gitmodules submodule.merging.update merge &&
42b49178 525 git submodule init merging &&
c9c8c56e 526 test "merge" = "$(git config submodule.merging.update)"
42b49178
JH
527 )
528'
529
b200021e 530test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
e7b37caf 531 test_config -C super submodule.submodule.update checkout &&
b200021e
SO
532 (cd super &&
533 rm -rf submodule &&
534 git submodule update submodule &&
535 git status -s submodule >expect &&
536 rm -rf submodule &&
537 git submodule update --merge submodule &&
538 git status -s submodule >actual &&
539 test_cmp expect actual
540 )
541'
542
543test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
e7b37caf 544 test_config -C super submodule.submodule.update checkout &&
b200021e
SO
545 (cd super &&
546 rm -rf submodule &&
547 git submodule update submodule &&
548 git status -s submodule >expect &&
549 rm -rf submodule &&
550 git submodule update --rebase submodule &&
551 git status -s submodule >actual &&
552 test_cmp expect actual
553 )
554'
555
556test_expect_success 'submodule update ignores update=merge config for new submodules' '
557 (cd super &&
558 rm -rf submodule &&
559 git submodule update submodule &&
560 git status -s submodule >expect &&
561 rm -rf submodule &&
562 git config submodule.submodule.update merge &&
563 git submodule update submodule &&
564 git status -s submodule >actual &&
565 git config --unset submodule.submodule.update &&
566 test_cmp expect actual
567 )
568'
569
570test_expect_success 'submodule update ignores update=rebase config for new submodules' '
571 (cd super &&
572 rm -rf submodule &&
573 git submodule update submodule &&
574 git status -s submodule >expect &&
575 rm -rf submodule &&
576 git config submodule.submodule.update rebase &&
577 git submodule update submodule &&
578 git status -s submodule >actual &&
579 git config --unset submodule.submodule.update &&
580 test_cmp expect actual
581 )
582'
583
322bb6e1
HV
584test_expect_success 'submodule init picks up update=none' '
585 (cd super &&
586 git config -f .gitmodules submodule.none.update none &&
587 git submodule init none &&
588 test "none" = "$(git config submodule.none.update)"
589 )
590'
591
592test_expect_success 'submodule update - update=none in .git/config' '
593 (cd super &&
594 git config submodule.submodule.update none &&
595 (cd submodule &&
596 git checkout master &&
597 compare_head
598 ) &&
65799fbc
EN
599 git diff --name-only >out &&
600 grep ^submodule$ out &&
322bb6e1 601 git submodule update &&
65799fbc
EN
602 git diff --name-only >out &&
603 grep ^submodule$ out &&
322bb6e1
HV
604 (cd submodule &&
605 compare_head
606 ) &&
607 git config --unset submodule.submodule.update &&
608 git submodule update submodule
609 )
610'
611
612test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
613 (cd super &&
614 git config submodule.submodule.update none &&
615 (cd submodule &&
616 git checkout master &&
617 compare_head
618 ) &&
65799fbc
EN
619 git diff --name-only >out &&
620 grep ^submodule$ out &&
322bb6e1 621 git submodule update --checkout &&
602813cf
EN
622 git diff --name-only >out &&
623 ! grep ^submodule$ out &&
322bb6e1 624 (cd submodule &&
9fd1080a 625 ! compare_head
322bb6e1
HV
626 ) &&
627 git config --unset submodule.submodule.update
628 )
629'
630
631test_expect_success 'submodule update --init skips submodule with update=none' '
632 (cd super &&
633 git add .gitmodules &&
634 git commit -m ".gitmodules"
635 ) &&
636 git clone super cloned &&
637 (cd cloned &&
638 git submodule update --init &&
7e9055bb
EN
639 test_path_exists submodule/.git &&
640 test_path_is_missing none/.git
322bb6e1
HV
641 )
642'
643
15ffb7cd
FG
644test_expect_success 'submodule update continues after checkout error' '
645 (cd super &&
646 git reset --hard HEAD &&
647 git submodule add ../submodule submodule2 &&
648 git submodule init &&
649 git commit -am "new_submodule" &&
650 (cd submodule2 &&
ad6a599c 651 git rev-parse --verify HEAD >../expect
15ffb7cd
FG
652 ) &&
653 (cd submodule &&
654 test_commit "update_submodule" file
655 ) &&
656 (cd submodule2 &&
657 test_commit "update_submodule2" file
658 ) &&
659 git add submodule &&
660 git add submodule2 &&
661 git commit -m "two_new_submodule_commits" &&
662 (cd submodule &&
663 echo "" > file
664 ) &&
665 git checkout HEAD^ &&
666 test_must_fail git submodule update &&
667 (cd submodule2 &&
ad6a599c 668 git rev-parse --verify HEAD >../actual
15ffb7cd
FG
669 ) &&
670 test_cmp expect actual
671 )
672'
673test_expect_success 'submodule update continues after recursive checkout error' '
674 (cd super &&
675 git reset --hard HEAD &&
676 git checkout master &&
677 git submodule update &&
678 (cd submodule &&
679 git submodule add ../submodule subsubmodule &&
680 git submodule init &&
681 git commit -m "new_subsubmodule"
682 ) &&
683 git add submodule &&
684 git commit -m "update_submodule" &&
685 (cd submodule &&
686 (cd subsubmodule &&
687 test_commit "update_subsubmodule" file
688 ) &&
689 git add subsubmodule &&
690 test_commit "update_submodule_again" file &&
691 (cd subsubmodule &&
692 test_commit "update_subsubmodule_again" file
693 ) &&
694 test_commit "update_submodule_again_again" file
695 ) &&
696 (cd submodule2 &&
ad6a599c 697 git rev-parse --verify HEAD >../expect &&
15ffb7cd
FG
698 test_commit "update_submodule2_again" file
699 ) &&
700 git add submodule &&
701 git add submodule2 &&
702 git commit -m "new_commits" &&
703 git checkout HEAD^ &&
704 (cd submodule &&
705 git checkout HEAD^ &&
706 (cd subsubmodule &&
707 echo "" > file
708 )
709 ) &&
710 test_must_fail git submodule update --recursive &&
711 (cd submodule2 &&
ad6a599c 712 git rev-parse --verify HEAD >../actual
15ffb7cd
FG
713 ) &&
714 test_cmp expect actual
715 )
716'
717
718test_expect_success 'submodule update exit immediately in case of merge conflict' '
719 (cd super &&
720 git checkout master &&
721 git reset --hard HEAD &&
722 (cd submodule &&
723 (cd subsubmodule &&
724 git reset --hard HEAD
725 )
726 ) &&
727 git submodule update --recursive &&
728 (cd submodule &&
729 test_commit "update_submodule_2" file
730 ) &&
731 (cd submodule2 &&
732 test_commit "update_submodule2_2" file
733 ) &&
734 git add submodule &&
735 git add submodule2 &&
736 git commit -m "two_new_submodule_commits" &&
737 (cd submodule &&
738 git checkout master &&
739 test_commit "conflict" file &&
740 echo "conflict" > file
741 ) &&
742 git checkout HEAD^ &&
743 (cd submodule2 &&
ad6a599c 744 git rev-parse --verify HEAD >../expect
15ffb7cd
FG
745 ) &&
746 git config submodule.submodule.update merge &&
747 test_must_fail git submodule update &&
748 (cd submodule2 &&
ad6a599c 749 git rev-parse --verify HEAD >../actual
15ffb7cd
FG
750 ) &&
751 test_cmp expect actual
752 )
753'
501770e1 754
15ffb7cd
FG
755test_expect_success 'submodule update exit immediately after recursive rebase error' '
756 (cd super &&
757 git checkout master &&
758 git reset --hard HEAD &&
759 (cd submodule &&
760 git reset --hard HEAD &&
761 git submodule update --recursive
762 ) &&
763 (cd submodule &&
764 test_commit "update_submodule_3" file
765 ) &&
766 (cd submodule2 &&
767 test_commit "update_submodule2_3" file
768 ) &&
769 git add submodule &&
770 git add submodule2 &&
771 git commit -m "two_new_submodule_commits" &&
772 (cd submodule &&
773 git checkout master &&
774 test_commit "conflict2" file &&
775 echo "conflict" > file
776 ) &&
777 git checkout HEAD^ &&
778 (cd submodule2 &&
ad6a599c 779 git rev-parse --verify HEAD >../expect
15ffb7cd
FG
780 ) &&
781 git config submodule.submodule.update rebase &&
782 test_must_fail git submodule update &&
783 (cd submodule2 &&
ad6a599c 784 git rev-parse --verify HEAD >../actual
15ffb7cd
FG
785 ) &&
786 test_cmp expect actual
787 )
788'
501770e1
FG
789
790test_expect_success 'add different submodules to the same path' '
791 (cd super &&
792 git submodule add ../submodule s1 &&
793 test_must_fail git submodule add ../merging s1
794 )
795'
796
797test_expect_success 'submodule add places git-dir in superprojects git-dir' '
798 (cd super &&
799 mkdir deeper &&
800 git submodule add ../submodule deeper/submodule &&
801 (cd deeper/submodule &&
802 git log > ../../expected
803 ) &&
804 (cd .git/modules/deeper/submodule &&
805 git log > ../../../../actual
806 ) &&
dcbaa0b3 807 test_cmp expected actual
501770e1
FG
808 )
809'
810
811test_expect_success 'submodule update places git-dir in superprojects git-dir' '
812 (cd super &&
813 git commit -m "added submodule"
814 ) &&
815 git clone super super2 &&
816 (cd super2 &&
817 git submodule init deeper/submodule &&
818 git submodule update &&
819 (cd deeper/submodule &&
820 git log > ../../expected
821 ) &&
822 (cd .git/modules/deeper/submodule &&
823 git log > ../../../../actual
824 ) &&
dcbaa0b3 825 test_cmp expected actual
501770e1
FG
826 )
827'
828
829test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
830 (cd super2 &&
831 (cd deeper/submodule &&
832 git submodule add ../submodule subsubmodule &&
833 (cd subsubmodule &&
834 git log > ../../../expected
835 ) &&
836 git commit -m "added subsubmodule" &&
ae74f7d2 837 git push origin :
501770e1
FG
838 ) &&
839 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
840 git log > ../../../../../actual
841 ) &&
842 git add deeper/submodule &&
843 git commit -m "update submodule" &&
ae74f7d2 844 git push origin : &&
dcbaa0b3 845 test_cmp expected actual
501770e1
FG
846 )
847'
848
849test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
850 mkdir super_update_r &&
851 (cd super_update_r &&
852 git init --bare
853 ) &&
854 mkdir subsuper_update_r &&
855 (cd subsuper_update_r &&
856 git init --bare
857 ) &&
858 mkdir subsubsuper_update_r &&
859 (cd subsubsuper_update_r &&
860 git init --bare
861 ) &&
862 git clone subsubsuper_update_r subsubsuper_update_r2 &&
863 (cd subsubsuper_update_r2 &&
864 test_commit "update_subsubsuper" file &&
865 git push origin master
866 ) &&
867 git clone subsuper_update_r subsuper_update_r2 &&
868 (cd subsuper_update_r2 &&
869 test_commit "update_subsuper" file &&
870 git submodule add ../subsubsuper_update_r subsubmodule &&
871 git commit -am "subsubmodule" &&
872 git push origin master
873 ) &&
874 git clone super_update_r super_update_r2 &&
875 (cd super_update_r2 &&
876 test_commit "update_super" file &&
877 git submodule add ../subsuper_update_r submodule &&
878 git commit -am "submodule" &&
879 git push origin master
880 ) &&
881 rm -rf super_update_r2 &&
882 git clone super_update_r super_update_r2 &&
883 (cd super_update_r2 &&
75bf5e60 884 git submodule update --init --recursive >actual &&
d851ffb9 885 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
501770e1
FG
886 (cd submodule/subsubmodule &&
887 git log > ../../expected
888 ) &&
e974e06d 889 (cd .git/modules/submodule/modules/subsubmodule &&
501770e1 890 git log > ../../../../../actual
e974e06d 891 ) &&
dcbaa0b3 892 test_cmp expected actual
501770e1
FG
893 )
894'
895
1017c1ab
JL
896test_expect_success 'submodule add properly re-creates deeper level submodules' '
897 (cd super &&
898 git reset --hard master &&
899 rm -rf deeper/ &&
4b7c286e 900 git submodule add --force ../submodule deeper/submodule
1017c1ab
JL
901 )
902'
903
69c30517
JL
904test_expect_success 'submodule update properly revives a moved submodule' '
905 (cd super &&
b397ea48 906 H=$(git rev-parse --short HEAD) &&
69c30517 907 git commit -am "pre move" &&
b397ea48 908 H2=$(git rev-parse --short HEAD) &&
65799fbc
EN
909 git status >out &&
910 sed "s/$H/XXX/" out >expect &&
e974e06d 911 H=$(cd submodule2 && git rev-parse HEAD) &&
69c30517
JL
912 git rm --cached submodule2 &&
913 rm -rf submodule2 &&
914 mkdir -p "moved/sub module" &&
915 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
8de19d6b 916 git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
69c30517
JL
917 git commit -am "post move" &&
918 git submodule update &&
65799fbc
EN
919 git status > out &&
920 sed "s/$H2/XXX/" out >actual &&
69c30517
JL
921 test_cmp expect actual
922 )
923'
924
6eafa6d0
JL
925test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
926 mkdir -p linked/dir &&
927 ln -s linked/dir linkto &&
275cd184
FG
928 (cd linkto &&
929 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
930 (cd super &&
931 git submodule update --init --recursive
932 )
6eafa6d0
JL
933 )
934'
935
275cd184 936test_expect_success 'submodule update clone shallow submodule' '
d4470c5a 937 test_when_finished "rm -rf super3" &&
65799fbc 938 first=$(git -C cloned rev-parse HEAD:submodule) &&
d4470c5a 939 second=$(git -C submodule rev-parse HEAD) &&
967d7f89 940 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
275cd184 941 git clone cloned super3 &&
99094a7a 942 pwd=$(pwd) &&
d4470c5a
SB
943 (
944 cd super3 &&
945 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
946 mv -f .gitmodules.tmp .gitmodules &&
947 git submodule update --init --depth=$commit_count &&
65799fbc
EN
948 git -C submodule log --oneline >out &&
949 test_line_count = 1 out
d4470c5a 950 )
36141282
JL
951'
952
6cbf454a
SB
953test_expect_success 'submodule update clone shallow submodule outside of depth' '
954 test_when_finished "rm -rf super3" &&
955 git clone cloned super3 &&
956 pwd=$(pwd) &&
957 (
958 cd super3 &&
959 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
960 mv -f .gitmodules.tmp .gitmodules &&
ab0c5f50
JT
961 # Some protocol versions (e.g. 2) support fetching
962 # unadvertised objects, so restrict this test to v0.
8a1b0978 963 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
ab0c5f50 964 git submodule update --init --depth=1 2>actual &&
6cbf454a
SB
965 test_i18ngrep "Direct fetching of that commit failed." actual &&
966 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
967 git submodule update --init --depth=1 >actual &&
65799fbc
EN
968 git -C submodule log --oneline >out &&
969 test_line_count = 1 out
6cbf454a
SB
970 )
971'
972
36141282
JL
973test_expect_success 'submodule update --recursive drops module name before recursing' '
974 (cd super2 &&
975 (cd deeper/submodule/subsubmodule &&
976 git checkout HEAD^
977 ) &&
978 git submodule update --recursive deeper/submodule >actual &&
979 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
275cd184
FG
980 )
981'
2335b870
SB
982
983test_expect_success 'submodule update can be run in parallel' '
984 (cd super2 &&
985 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
986 grep "7 tasks" trace.out &&
987 git config submodule.fetchJobs 8 &&
988 GIT_TRACE=$(pwd)/trace.out git submodule update &&
989 grep "8 tasks" trace.out &&
990 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
991 grep "9 tasks" trace.out
992 )
993'
72290d6a
SB
994
995test_expect_success 'git clone passes the parallel jobs config on to submodules' '
996 test_when_finished "rm -rf super4" &&
997 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
998 grep "7 tasks" trace.out &&
999 rm -rf super4 &&
1000 git config --global submodule.fetchJobs 8 &&
1001 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
1002 grep "8 tasks" trace.out &&
1003 rm -rf super4 &&
1004 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
1005 grep "9 tasks" trace.out &&
1006 rm -rf super4
1007'
1008
ca2cedba 1009test_done