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