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