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