unit-tests: do not mistake `.pdb` files for being executable
[git.git] / t / t7406-submodule-update.sh
blobf094e3d7f3642de61a69b3d9131e31707654539c
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 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
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 &&
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 &&
85 git -C main-branch-submodule switch -c hello &&
86 test_commit -C main-branch-submodule world &&
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
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
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
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)
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'
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.
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
164 cat <<EOF >expect2
165 Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
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
177 ) &&
178 test_cmp expect2 actual2
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
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 2>../actual.raw
210 ) &&
211 sed "s/^> //" >expect <<-\EOF &&
212 > error: Your local changes to the following files would be overwritten by checkout:
213 > file
214 > Please commit your changes or stash them before you switch branches.
215 > Aborting
216 > fatal: Unable to checkout OID in submodule path '\''submodule'\''
218 sed -e "s/checkout $SQ[^$SQ]*$SQ/checkout OID/" <actual.raw >actual &&
219 test_cmp expect actual
222 test_expect_success 'submodule update should throw away changes with --force ' '
223 (cd super &&
224 (cd submodule &&
225 compare_head
226 ) &&
227 git submodule update --force submodule &&
228 cd submodule &&
229 ! compare_head
233 test_expect_success 'submodule update --force forcibly checks out submodules' '
234 (cd super &&
235 (cd submodule &&
236 rm -f file
237 ) &&
238 git submodule update --force submodule &&
239 (cd submodule &&
240 test "$(git status -s file)" = ""
245 test_expect_success 'submodule update --remote should fetch upstream changes' '
246 (cd submodule &&
247 echo line4 >> file &&
248 git add file &&
249 test_tick &&
250 git commit -m "upstream line4"
251 ) &&
252 (cd super &&
253 git submodule update --remote --force submodule &&
254 cd submodule &&
255 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
259 test_expect_success 'submodule update --remote should fetch upstream changes with .' '
261 cd super &&
262 git config -f .gitmodules submodule."submodule".branch "." &&
263 git add .gitmodules &&
264 git commit -m "submodules: update from the respective superproject branch"
265 ) &&
267 cd submodule &&
268 echo line4a >> file &&
269 git add file &&
270 test_tick &&
271 git commit -m "upstream line4a" &&
272 git checkout -b test-branch &&
273 test_commit on-test-branch
274 ) &&
276 cd super &&
277 git submodule update --remote --force submodule &&
278 git -C submodule log -1 --oneline >actual &&
279 git -C ../submodule log -1 --oneline main >expect &&
280 test_cmp expect actual &&
281 git checkout -b test-branch &&
282 git submodule update --remote --force submodule &&
283 git -C submodule log -1 --oneline >actual &&
284 git -C ../submodule log -1 --oneline test-branch >expect &&
285 test_cmp expect actual &&
286 git checkout main &&
287 git branch -d test-branch &&
288 git reset --hard HEAD^
292 test_expect_success 'local config should override .gitmodules branch' '
293 (cd submodule &&
294 git checkout test-branch &&
295 echo line5 >> file &&
296 git add file &&
297 test_tick &&
298 git commit -m "upstream line5" &&
299 git checkout main
300 ) &&
301 (cd super &&
302 git config submodule.submodule.branch test-branch &&
303 git submodule update --remote --force submodule &&
304 cd submodule &&
305 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
309 test_expect_success 'submodule update --rebase staying on main' '
310 (cd super/submodule &&
311 git checkout main
312 ) &&
313 (cd super &&
314 (cd submodule &&
315 compare_head
316 ) &&
317 git submodule update --rebase submodule &&
318 cd submodule &&
319 compare_head
323 test_expect_success 'submodule update --merge staying on main' '
324 (cd super/submodule &&
325 git reset --hard HEAD~1
326 ) &&
327 (cd super &&
328 (cd submodule &&
329 compare_head
330 ) &&
331 git submodule update --merge submodule &&
332 cd submodule &&
333 compare_head
337 test_expect_success 'submodule update - rebase in .git/config' '
338 (cd super &&
339 git config submodule.submodule.update rebase
340 ) &&
341 (cd super/submodule &&
342 git reset --hard HEAD~1
343 ) &&
344 (cd super &&
345 (cd submodule &&
346 compare_head
347 ) &&
348 git submodule update submodule &&
349 cd submodule &&
350 compare_head
354 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
355 (cd super &&
356 git config submodule.submodule.update checkout
357 ) &&
358 (cd super/submodule &&
359 git reset --hard HEAD~1
360 ) &&
361 (cd super &&
362 (cd submodule &&
363 compare_head
364 ) &&
365 git submodule update --rebase submodule &&
366 cd submodule &&
367 compare_head
371 test_expect_success 'submodule update - merge in .git/config' '
372 (cd super &&
373 git config submodule.submodule.update merge
374 ) &&
375 (cd super/submodule &&
376 git reset --hard HEAD~1
377 ) &&
378 (cd super &&
379 (cd submodule &&
380 compare_head
381 ) &&
382 git submodule update submodule &&
383 cd submodule &&
384 compare_head
388 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
389 (cd super &&
390 git config submodule.submodule.update checkout
391 ) &&
392 (cd super/submodule &&
393 git reset --hard HEAD~1
394 ) &&
395 (cd super &&
396 (cd submodule &&
397 compare_head
398 ) &&
399 git submodule update --merge submodule &&
400 cd submodule &&
401 compare_head
405 test_expect_success 'submodule update - checkout in .git/config' '
406 (cd super &&
407 git config submodule.submodule.update checkout
408 ) &&
409 (cd super/submodule &&
410 git reset --hard HEAD^
411 ) &&
412 (cd super &&
413 (cd submodule &&
414 compare_head
415 ) &&
416 git submodule update submodule &&
417 cd submodule &&
418 ! compare_head
422 test_expect_success 'submodule update - command in .git/config' '
423 (cd super &&
424 git config submodule.submodule.update "!git checkout"
425 ) &&
426 (cd super/submodule &&
427 git reset --hard HEAD^
428 ) &&
429 (cd super &&
430 (cd submodule &&
431 compare_head
432 ) &&
433 git submodule update submodule &&
434 cd submodule &&
435 ! compare_head
439 test_expect_success 'submodule update - command in .gitmodules is rejected' '
440 test_when_finished "git -C super reset --hard HEAD^" &&
441 git -C super config -f .gitmodules submodule.submodule.update "!false" &&
442 git -C super commit -a -m "add command to .gitmodules file" &&
443 git -C super/submodule reset --hard $submodulesha1^ &&
444 test_must_fail git -C super submodule update submodule
447 test_expect_success 'fsck detects command in .gitmodules' '
448 git init command-in-gitmodules &&
450 cd command-in-gitmodules &&
451 git submodule add ../submodule submodule &&
452 test_commit adding-submodule &&
454 git config -f .gitmodules submodule.submodule.update "!false" &&
455 git add .gitmodules &&
456 test_commit configuring-update &&
457 test_must_fail git fsck
461 cat << EOF >expect
462 fatal: Execution of 'false $submodulesha1' failed in submodule path 'submodule'
465 test_expect_success 'submodule update - command in .git/config catches failure' '
466 (cd super &&
467 git config submodule.submodule.update "!false"
468 ) &&
469 (cd super/submodule &&
470 git reset --hard $submodulesha1^
471 ) &&
472 (cd super &&
473 test_must_fail git submodule update submodule 2>../actual
474 ) &&
475 test_cmp actual expect
478 cat << EOF >expect
479 fatal: Execution of 'false $submodulesha1' failed in submodule path '../submodule'
482 test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' '
483 (cd super &&
484 git config submodule.submodule.update "!false"
485 ) &&
486 (cd super/submodule &&
487 git reset --hard $submodulesha1^
488 ) &&
489 (cd super &&
490 mkdir tmp && cd tmp &&
491 test_must_fail git submodule update ../submodule 2>../../actual
492 ) &&
493 test_cmp actual expect
496 test_expect_success 'submodule update - command run for initial population of submodule' '
497 cat >expect <<-EOF &&
498 fatal: Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
500 rm -rf super/submodule &&
501 test_must_fail git -C super submodule update 2>actual &&
502 test_cmp expect actual &&
503 git -C super submodule update --checkout
506 cat << EOF >expect
507 fatal: Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
508 fatal: Failed to recurse into submodule path '../super'
511 test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '
512 (cd recursivesuper &&
513 git submodule update --remote super &&
514 git add super &&
515 git commit -m "update to latest to have more than one commit in submodules"
516 ) &&
517 git -C recursivesuper/super config submodule.submodule.update "!false" &&
518 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
519 (cd recursivesuper &&
520 mkdir -p tmp && cd tmp &&
521 test_must_fail git submodule update --recursive ../super 2>../../actual
522 ) &&
523 test_cmp actual expect
526 test_expect_success 'submodule init does not copy command into .git/config' '
527 test_when_finished "git -C super update-index --force-remove submodule1" &&
528 test_when_finished git config -f super/.gitmodules \
529 --remove-section submodule.submodule1 &&
530 (cd super &&
531 git ls-files -s submodule >out &&
532 H=$(cut -d" " -f2 out) &&
533 mkdir submodule1 &&
534 git update-index --add --cacheinfo 160000 $H submodule1 &&
535 git config -f .gitmodules submodule.submodule1.path submodule1 &&
536 git config -f .gitmodules submodule.submodule1.url ../submodule &&
537 git config -f .gitmodules submodule.submodule1.update !false &&
538 test_must_fail git submodule init submodule1 &&
539 test_expect_code 1 git config submodule.submodule1.update >actual &&
540 test_must_be_empty actual
544 test_expect_success 'submodule init picks up rebase' '
545 (cd super &&
546 git config -f .gitmodules submodule.rebasing.update rebase &&
547 git submodule init rebasing &&
548 test "rebase" = "$(git config submodule.rebasing.update)"
552 test_expect_success 'submodule init picks up merge' '
553 (cd super &&
554 git config -f .gitmodules submodule.merging.update merge &&
555 git submodule init merging &&
556 test "merge" = "$(git config submodule.merging.update)"
560 test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
561 test_config -C super submodule.submodule.update checkout &&
562 (cd super &&
563 rm -rf submodule &&
564 git submodule update submodule &&
565 git status -s submodule >expect &&
566 rm -rf submodule &&
567 git submodule update --merge submodule &&
568 git status -s submodule >actual &&
569 test_cmp expect actual
573 test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
574 test_config -C super submodule.submodule.update checkout &&
575 (cd super &&
576 rm -rf submodule &&
577 git submodule update submodule &&
578 git status -s submodule >expect &&
579 rm -rf submodule &&
580 git submodule update --rebase submodule &&
581 git status -s submodule >actual &&
582 test_cmp expect actual
586 test_expect_success 'submodule update ignores update=merge 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 merge &&
593 git submodule update submodule &&
594 git status -s submodule >actual &&
595 git config --unset submodule.submodule.update &&
596 test_cmp expect actual
600 test_expect_success 'submodule update ignores update=rebase config for new submodules' '
601 (cd super &&
602 rm -rf submodule &&
603 git submodule update submodule &&
604 git status -s submodule >expect &&
605 rm -rf submodule &&
606 git config submodule.submodule.update rebase &&
607 git submodule update submodule &&
608 git status -s submodule >actual &&
609 git config --unset submodule.submodule.update &&
610 test_cmp expect actual
614 test_expect_success 'submodule init picks up update=none' '
615 (cd super &&
616 git config -f .gitmodules submodule.none.update none &&
617 git submodule init none &&
618 test "none" = "$(git config submodule.none.update)"
622 test_expect_success 'submodule update - update=none in .git/config' '
623 (cd super &&
624 git config submodule.submodule.update none &&
625 (cd submodule &&
626 git checkout main &&
627 compare_head
628 ) &&
629 git diff --name-only >out &&
630 grep ^submodule$ out &&
631 git submodule update &&
632 git diff --name-only >out &&
633 grep ^submodule$ out &&
634 (cd submodule &&
635 compare_head
636 ) &&
637 git config --unset submodule.submodule.update &&
638 git submodule update submodule
642 test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
643 (cd super &&
644 git config submodule.submodule.update none &&
645 (cd submodule &&
646 git checkout main &&
647 compare_head
648 ) &&
649 git diff --name-only >out &&
650 grep ^submodule$ out &&
651 git submodule update --checkout &&
652 git diff --name-only >out &&
653 ! grep ^submodule$ out &&
654 (cd submodule &&
655 ! compare_head
656 ) &&
657 git config --unset submodule.submodule.update
661 test_expect_success 'submodule update --init skips submodule with update=none' '
662 (cd super &&
663 git add .gitmodules &&
664 git commit -m ".gitmodules"
665 ) &&
666 git clone super cloned &&
667 (cd cloned &&
668 git submodule update --init &&
669 test_path_exists submodule/.git &&
670 test_path_is_missing none/.git
674 test_expect_success 'submodule update with pathspec warns against uninitialized ones' '
675 test_when_finished "rm -fr selective" &&
676 git clone super selective &&
678 cd selective &&
679 git submodule init submodule &&
681 git submodule update submodule 2>err &&
682 ! grep "Submodule path .* not initialized" err &&
684 git submodule update rebasing 2>err &&
685 grep "Submodule path .rebasing. not initialized" err &&
687 test_path_exists submodule/.git &&
688 test_path_is_missing rebasing/.git
693 test_expect_success 'submodule update without pathspec updates only initialized ones' '
694 test_when_finished "rm -fr selective" &&
695 git clone super selective &&
697 cd selective &&
698 git submodule init submodule &&
699 git submodule update 2>err &&
700 test_path_exists submodule/.git &&
701 test_path_is_missing rebasing/.git &&
702 ! grep "Submodule path .* not initialized" err
707 test_expect_success 'submodule update continues after checkout error' '
708 (cd super &&
709 git reset --hard HEAD &&
710 git submodule add ../submodule submodule2 &&
711 git submodule init &&
712 git commit -am "new_submodule" &&
713 (cd submodule2 &&
714 git rev-parse --verify HEAD >../expect
715 ) &&
716 (cd submodule &&
717 test_commit "update_submodule" file
718 ) &&
719 (cd submodule2 &&
720 test_commit "update_submodule2" file
721 ) &&
722 git add submodule &&
723 git add submodule2 &&
724 git commit -m "two_new_submodule_commits" &&
725 (cd submodule &&
726 echo "" > file
727 ) &&
728 git checkout HEAD^ &&
729 test_must_fail git submodule update &&
730 (cd submodule2 &&
731 git rev-parse --verify HEAD >../actual
732 ) &&
733 test_cmp expect actual
736 test_expect_success 'submodule update continues after recursive checkout error' '
737 (cd super &&
738 git reset --hard HEAD &&
739 git checkout main &&
740 git submodule update &&
741 (cd submodule &&
742 git submodule add ../submodule subsubmodule &&
743 git submodule init &&
744 git commit -m "new_subsubmodule"
745 ) &&
746 git add submodule &&
747 git commit -m "update_submodule" &&
748 (cd submodule &&
749 (cd subsubmodule &&
750 test_commit "update_subsubmodule" file
751 ) &&
752 git add subsubmodule &&
753 test_commit "update_submodule_again" file &&
754 (cd subsubmodule &&
755 test_commit "update_subsubmodule_again" file
756 ) &&
757 test_commit "update_submodule_again_again" file
758 ) &&
759 (cd submodule2 &&
760 git rev-parse --verify HEAD >../expect &&
761 test_commit "update_submodule2_again" file
762 ) &&
763 git add submodule &&
764 git add submodule2 &&
765 git commit -m "new_commits" &&
766 git checkout HEAD^ &&
767 (cd submodule &&
768 git checkout HEAD^ &&
769 (cd subsubmodule &&
770 echo "" > file
772 ) &&
773 test_expect_code 1 git submodule update --recursive &&
774 (cd submodule2 &&
775 git rev-parse --verify HEAD >../actual
776 ) &&
777 test_cmp expect actual
781 test_expect_success 'submodule update exit immediately in case of merge conflict' '
782 (cd super &&
783 git checkout main &&
784 git reset --hard HEAD &&
785 (cd submodule &&
786 (cd subsubmodule &&
787 git reset --hard HEAD
789 ) &&
790 git submodule update --recursive &&
791 (cd submodule &&
792 test_commit "update_submodule_2" file
793 ) &&
794 (cd submodule2 &&
795 test_commit "update_submodule2_2" file
796 ) &&
797 git add submodule &&
798 git add submodule2 &&
799 git commit -m "two_new_submodule_commits" &&
800 (cd submodule &&
801 git checkout main &&
802 test_commit "conflict" file &&
803 echo "conflict" > file
804 ) &&
805 git checkout HEAD^ &&
806 (cd submodule2 &&
807 git rev-parse --verify HEAD >../expect
808 ) &&
809 git config submodule.submodule.update merge &&
810 test_must_fail git submodule update &&
811 (cd submodule2 &&
812 git rev-parse --verify HEAD >../actual
813 ) &&
814 test_cmp expect actual
818 test_expect_success 'submodule update exit immediately after recursive rebase error' '
819 (cd super &&
820 git checkout main &&
821 git reset --hard HEAD &&
822 (cd submodule &&
823 git reset --hard HEAD &&
824 git submodule update --recursive
825 ) &&
826 (cd submodule &&
827 test_commit "update_submodule_3" file
828 ) &&
829 (cd submodule2 &&
830 test_commit "update_submodule2_3" file
831 ) &&
832 git add submodule &&
833 git add submodule2 &&
834 git commit -m "two_new_submodule_commits" &&
835 (cd submodule &&
836 git checkout main &&
837 test_commit "conflict2" file &&
838 echo "conflict" > file
839 ) &&
840 git checkout HEAD^ &&
841 (cd submodule2 &&
842 git rev-parse --verify HEAD >../expect
843 ) &&
844 git config submodule.submodule.update rebase &&
845 test_must_fail git submodule update &&
846 (cd submodule2 &&
847 git rev-parse --verify HEAD >../actual
848 ) &&
849 test_cmp expect actual
853 test_expect_success 'add different submodules to the same path' '
854 (cd super &&
855 git submodule add ../submodule s1 &&
856 test_must_fail git submodule add ../merging s1
860 test_expect_success 'submodule add places git-dir in superprojects git-dir' '
861 (cd super &&
862 mkdir deeper &&
863 git submodule add ../submodule deeper/submodule &&
864 (cd deeper/submodule &&
865 git log > ../../expected
866 ) &&
867 (cd .git/modules/deeper/submodule &&
868 git log > ../../../../actual
869 ) &&
870 test_cmp expected actual
874 test_expect_success 'submodule update places git-dir in superprojects git-dir' '
875 (cd super &&
876 git commit -m "added submodule"
877 ) &&
878 git clone super super2 &&
879 (cd super2 &&
880 git submodule init deeper/submodule &&
881 git submodule update &&
882 (cd deeper/submodule &&
883 git log > ../../expected
884 ) &&
885 (cd .git/modules/deeper/submodule &&
886 git log > ../../../../actual
887 ) &&
888 test_cmp expected actual
892 test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
893 (cd super2 &&
894 (cd deeper/submodule &&
895 git submodule add ../submodule subsubmodule &&
896 (cd subsubmodule &&
897 git log > ../../../expected
898 ) &&
899 git commit -m "added subsubmodule" &&
900 git push origin :
901 ) &&
902 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
903 git log > ../../../../../actual
904 ) &&
905 git add deeper/submodule &&
906 git commit -m "update submodule" &&
907 git push origin : &&
908 test_cmp expected actual
912 test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
913 mkdir super_update_r &&
914 (cd super_update_r &&
915 git init --bare
916 ) &&
917 mkdir subsuper_update_r &&
918 (cd subsuper_update_r &&
919 git init --bare
920 ) &&
921 mkdir subsubsuper_update_r &&
922 (cd subsubsuper_update_r &&
923 git init --bare
924 ) &&
925 git clone subsubsuper_update_r subsubsuper_update_r2 &&
926 (cd subsubsuper_update_r2 &&
927 test_commit "update_subsubsuper" file &&
928 git push origin main
929 ) &&
930 git clone subsuper_update_r subsuper_update_r2 &&
931 (cd subsuper_update_r2 &&
932 test_commit "update_subsuper" file &&
933 git submodule add ../subsubsuper_update_r subsubmodule &&
934 git commit -am "subsubmodule" &&
935 git push origin main
936 ) &&
937 git clone super_update_r super_update_r2 &&
938 (cd super_update_r2 &&
939 test_commit "update_super" file &&
940 git submodule add ../subsuper_update_r submodule &&
941 git commit -am "submodule" &&
942 git push origin main
943 ) &&
944 rm -rf super_update_r2 &&
945 git clone super_update_r super_update_r2 &&
946 (cd super_update_r2 &&
947 git submodule update --init --recursive >actual &&
948 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
949 (cd submodule/subsubmodule &&
950 git log > ../../expected
951 ) &&
952 (cd .git/modules/submodule/modules/subsubmodule &&
953 git log > ../../../../../actual
954 ) &&
955 test_cmp expected actual
959 test_expect_success 'submodule add properly re-creates deeper level submodules' '
960 (cd super &&
961 git reset --hard main &&
962 rm -rf deeper/ &&
963 git submodule add --force ../submodule deeper/submodule
967 test_expect_success 'submodule update properly revives a moved submodule' '
968 (cd super &&
969 H=$(git rev-parse --short HEAD) &&
970 git commit -am "pre move" &&
971 H2=$(git rev-parse --short HEAD) &&
972 git status >out &&
973 sed "s/$H/XXX/" out >expect &&
974 H=$(cd submodule2 && git rev-parse HEAD) &&
975 git rm --cached submodule2 &&
976 rm -rf submodule2 &&
977 mkdir -p "moved/sub module" &&
978 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
979 git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
980 git commit -am "post move" &&
981 git submodule update &&
982 git status > out &&
983 sed "s/$H2/XXX/" out >actual &&
984 test_cmp expect actual
988 test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
989 mkdir -p linked/dir &&
990 ln -s linked/dir linkto &&
991 (cd linkto &&
992 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
993 (cd super &&
994 git submodule update --init --recursive
999 test_expect_success 'submodule update clone shallow submodule' '
1000 test_when_finished "rm -rf super3" &&
1001 first=$(git -C cloned rev-parse HEAD:submodule) &&
1002 second=$(git -C submodule rev-parse HEAD) &&
1003 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
1004 git clone cloned super3 &&
1005 pwd=$(pwd) &&
1007 cd super3 &&
1008 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
1009 mv -f .gitmodules.tmp .gitmodules &&
1010 git submodule update --init --depth=$commit_count &&
1011 git -C submodule log --oneline >out &&
1012 test_line_count = 1 out
1016 test_expect_success 'submodule update clone shallow submodule outside of depth' '
1017 test_when_finished "rm -rf super3" &&
1018 git clone cloned super3 &&
1019 pwd=$(pwd) &&
1021 cd super3 &&
1022 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
1023 mv -f .gitmodules.tmp .gitmodules &&
1024 # Some protocol versions (e.g. 2) support fetching
1025 # unadvertised objects, so restrict this test to v0.
1026 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1027 git submodule update --init --depth=1 2>actual &&
1028 test_i18ngrep "Direct fetching of that commit failed." actual &&
1029 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
1030 git submodule update --init --depth=1 >actual &&
1031 git -C submodule log --oneline >out &&
1032 test_line_count = 1 out
1036 test_expect_success 'submodule update --recursive drops module name before recursing' '
1037 (cd super2 &&
1038 (cd deeper/submodule/subsubmodule &&
1039 git checkout HEAD^
1040 ) &&
1041 git submodule update --recursive deeper/submodule >actual &&
1042 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
1046 test_expect_success 'submodule update can be run in parallel' '
1047 (cd super2 &&
1048 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
1049 grep "7 tasks" trace.out &&
1050 git config submodule.fetchJobs 8 &&
1051 GIT_TRACE=$(pwd)/trace.out git submodule update &&
1052 grep "8 tasks" trace.out &&
1053 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
1054 grep "9 tasks" trace.out
1058 test_expect_success 'git clone passes the parallel jobs config on to submodules' '
1059 test_when_finished "rm -rf super4" &&
1060 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
1061 grep "7 tasks" trace.out &&
1062 rm -rf super4 &&
1063 git config --global submodule.fetchJobs 8 &&
1064 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
1065 grep "8 tasks" trace.out &&
1066 rm -rf super4 &&
1067 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
1068 grep "9 tasks" trace.out &&
1069 rm -rf super4
1072 test_expect_success 'submodule update --quiet passes quietness to merge/rebase' '
1073 (cd super &&
1074 test_commit -C rebasing message &&
1075 git submodule update --rebase --quiet >out 2>err &&
1076 test_must_be_empty out &&
1077 test_must_be_empty err &&
1078 git submodule update --rebase >out 2>err &&
1079 test_file_not_empty out &&
1080 test_must_be_empty err
1084 test_expect_success 'submodule update --quiet passes quietness to fetch with a shallow clone' '
1085 test_when_finished "rm -rf super4 super5 super6" &&
1086 git clone . super4 &&
1087 (cd super4 &&
1088 git submodule add --quiet file://"$TRASH_DIRECTORY"/submodule submodule3 &&
1089 git commit -am "setup submodule3"
1090 ) &&
1091 (cd submodule &&
1092 test_commit line6 file
1093 ) &&
1094 git clone super4 super5 &&
1095 (cd super5 &&
1096 git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
1097 test_must_be_empty out &&
1098 test_must_be_empty err
1099 ) &&
1100 git clone super4 super6 &&
1101 (cd super6 &&
1102 git submodule update --init --depth=1 submodule3 >out 2>err &&
1103 test_file_not_empty out &&
1104 test_file_not_empty err
1108 test_expect_success 'submodule update --filter requires --init' '
1109 test_expect_code 129 git -C super submodule update --filter blob:none
1112 test_expect_success 'submodule update --filter sets partial clone settings' '
1113 test_when_finished "rm -rf super-filter" &&
1114 git clone cloned super-filter &&
1115 git -C super-filter submodule update --init --filter blob:none &&
1116 test_cmp_config -C super-filter/submodule true remote.origin.promisor &&
1117 test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter
1120 # NEEDSWORK: Clean up the tests so that we can reuse the test setup.
1121 # Don't reuse the existing repos because the earlier tests have
1122 # intentionally disruptive configurations.
1123 test_expect_success 'setup clean recursive superproject' '
1124 git init bottom &&
1125 test_commit -C bottom "bottom" &&
1126 git init middle &&
1127 git -C middle submodule add ../bottom bottom &&
1128 git -C middle commit -m "middle" &&
1129 git init top &&
1130 git -C top submodule add ../middle middle &&
1131 git -C top commit -m "top" &&
1132 git clone --recurse-submodules top top-clean
1135 test_expect_success 'submodule update should skip unmerged submodules' '
1136 test_when_finished "rm -fr top-cloned" &&
1137 cp -r top-clean top-cloned &&
1139 # Create an upstream commit in each repo, starting with bottom
1140 test_commit -C bottom upstream_commit &&
1141 # Create middle commit
1142 git -C middle/bottom fetch &&
1143 git -C middle/bottom checkout -f FETCH_HEAD &&
1144 git -C middle add bottom &&
1145 git -C middle commit -m "upstream_commit" &&
1146 # Create top commit
1147 git -C top/middle fetch &&
1148 git -C top/middle checkout -f FETCH_HEAD &&
1149 git -C top add middle &&
1150 git -C top commit -m "upstream_commit" &&
1152 # Create a downstream conflict
1153 test_commit -C top-cloned/middle/bottom downstream_commit &&
1154 git -C top-cloned/middle add bottom &&
1155 git -C top-cloned/middle commit -m "downstream_commit" &&
1156 git -C top-cloned/middle fetch --recurse-submodules origin &&
1157 test_must_fail git -C top-cloned/middle merge origin/main &&
1159 # Make the update of "middle" a no-op, otherwise we error out
1160 # because of its unmerged state
1161 test_config -C top-cloned submodule.middle.update !true &&
1162 git -C top-cloned submodule update --recursive 2>actual.err &&
1163 cat >expect.err <<-\EOF &&
1164 Skipping unmerged submodule middle/bottom
1166 test_cmp expect.err actual.err
1169 test_expect_success 'submodule update --recursive skip submodules with strategy=none' '
1170 test_when_finished "rm -fr top-cloned" &&
1171 cp -r top-clean top-cloned &&
1173 test_commit -C top-cloned/middle/bottom downstream_commit &&
1174 git -C top-cloned/middle config submodule.bottom.update none &&
1175 git -C top-cloned submodule update --recursive 2>actual.err &&
1176 cat >expect.err <<-\EOF &&
1177 Skipping submodule '\''middle/bottom'\''
1179 test_cmp expect.err actual.err
1182 test_done