list-objects-filter: don't memset after releasing filter struct
[git/debian.git] / t / t7406-submodule-update.sh
blob43f779d751cfe2645b038811e69b6f67fee2ed34
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 with pathspec warns against uninitialized ones' '
674 test_when_finished "rm -fr selective" &&
675 git clone super selective &&
677 cd selective &&
678 git submodule init submodule &&
680 git submodule update submodule 2>err &&
681 ! grep "Submodule path .* not initialized" err &&
683 git submodule update rebasing 2>err &&
684 grep "Submodule path .rebasing. not initialized" err &&
686 test_path_exists submodule/.git &&
687 test_path_is_missing rebasing/.git
692 test_expect_success 'submodule update without pathspec updates only initialized ones' '
693 test_when_finished "rm -fr selective" &&
694 git clone super selective &&
696 cd selective &&
697 git submodule init submodule &&
698 git submodule update 2>err &&
699 test_path_exists submodule/.git &&
700 test_path_is_missing rebasing/.git &&
701 ! grep "Submodule path .* not initialized" err
706 test_expect_success 'submodule update continues after checkout error' '
707 (cd super &&
708 git reset --hard HEAD &&
709 git submodule add ../submodule submodule2 &&
710 git submodule init &&
711 git commit -am "new_submodule" &&
712 (cd submodule2 &&
713 git rev-parse --verify HEAD >../expect
714 ) &&
715 (cd submodule &&
716 test_commit "update_submodule" file
717 ) &&
718 (cd submodule2 &&
719 test_commit "update_submodule2" file
720 ) &&
721 git add submodule &&
722 git add submodule2 &&
723 git commit -m "two_new_submodule_commits" &&
724 (cd submodule &&
725 echo "" > file
726 ) &&
727 git checkout HEAD^ &&
728 test_must_fail git submodule update &&
729 (cd submodule2 &&
730 git rev-parse --verify HEAD >../actual
731 ) &&
732 test_cmp expect actual
735 test_expect_success 'submodule update continues after recursive checkout error' '
736 (cd super &&
737 git reset --hard HEAD &&
738 git checkout main &&
739 git submodule update &&
740 (cd submodule &&
741 git submodule add ../submodule subsubmodule &&
742 git submodule init &&
743 git commit -m "new_subsubmodule"
744 ) &&
745 git add submodule &&
746 git commit -m "update_submodule" &&
747 (cd submodule &&
748 (cd subsubmodule &&
749 test_commit "update_subsubmodule" file
750 ) &&
751 git add subsubmodule &&
752 test_commit "update_submodule_again" file &&
753 (cd subsubmodule &&
754 test_commit "update_subsubmodule_again" file
755 ) &&
756 test_commit "update_submodule_again_again" file
757 ) &&
758 (cd submodule2 &&
759 git rev-parse --verify HEAD >../expect &&
760 test_commit "update_submodule2_again" file
761 ) &&
762 git add submodule &&
763 git add submodule2 &&
764 git commit -m "new_commits" &&
765 git checkout HEAD^ &&
766 (cd submodule &&
767 git checkout HEAD^ &&
768 (cd subsubmodule &&
769 echo "" > file
771 ) &&
772 test_must_fail git submodule update --recursive &&
773 (cd submodule2 &&
774 git rev-parse --verify HEAD >../actual
775 ) &&
776 test_cmp expect actual
780 test_expect_success 'submodule update exit immediately in case of merge conflict' '
781 (cd super &&
782 git checkout main &&
783 git reset --hard HEAD &&
784 (cd submodule &&
785 (cd subsubmodule &&
786 git reset --hard HEAD
788 ) &&
789 git submodule update --recursive &&
790 (cd submodule &&
791 test_commit "update_submodule_2" file
792 ) &&
793 (cd submodule2 &&
794 test_commit "update_submodule2_2" file
795 ) &&
796 git add submodule &&
797 git add submodule2 &&
798 git commit -m "two_new_submodule_commits" &&
799 (cd submodule &&
800 git checkout main &&
801 test_commit "conflict" file &&
802 echo "conflict" > file
803 ) &&
804 git checkout HEAD^ &&
805 (cd submodule2 &&
806 git rev-parse --verify HEAD >../expect
807 ) &&
808 git config submodule.submodule.update merge &&
809 test_must_fail git submodule update &&
810 (cd submodule2 &&
811 git rev-parse --verify HEAD >../actual
812 ) &&
813 test_cmp expect actual
817 test_expect_success 'submodule update exit immediately after recursive rebase error' '
818 (cd super &&
819 git checkout main &&
820 git reset --hard HEAD &&
821 (cd submodule &&
822 git reset --hard HEAD &&
823 git submodule update --recursive
824 ) &&
825 (cd submodule &&
826 test_commit "update_submodule_3" file
827 ) &&
828 (cd submodule2 &&
829 test_commit "update_submodule2_3" file
830 ) &&
831 git add submodule &&
832 git add submodule2 &&
833 git commit -m "two_new_submodule_commits" &&
834 (cd submodule &&
835 git checkout main &&
836 test_commit "conflict2" file &&
837 echo "conflict" > file
838 ) &&
839 git checkout HEAD^ &&
840 (cd submodule2 &&
841 git rev-parse --verify HEAD >../expect
842 ) &&
843 git config submodule.submodule.update rebase &&
844 test_must_fail git submodule update &&
845 (cd submodule2 &&
846 git rev-parse --verify HEAD >../actual
847 ) &&
848 test_cmp expect actual
852 test_expect_success 'add different submodules to the same path' '
853 (cd super &&
854 git submodule add ../submodule s1 &&
855 test_must_fail git submodule add ../merging s1
859 test_expect_success 'submodule add places git-dir in superprojects git-dir' '
860 (cd super &&
861 mkdir deeper &&
862 git submodule add ../submodule deeper/submodule &&
863 (cd deeper/submodule &&
864 git log > ../../expected
865 ) &&
866 (cd .git/modules/deeper/submodule &&
867 git log > ../../../../actual
868 ) &&
869 test_cmp expected actual
873 test_expect_success 'submodule update places git-dir in superprojects git-dir' '
874 (cd super &&
875 git commit -m "added submodule"
876 ) &&
877 git clone super super2 &&
878 (cd super2 &&
879 git submodule init deeper/submodule &&
880 git submodule update &&
881 (cd deeper/submodule &&
882 git log > ../../expected
883 ) &&
884 (cd .git/modules/deeper/submodule &&
885 git log > ../../../../actual
886 ) &&
887 test_cmp expected actual
891 test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
892 (cd super2 &&
893 (cd deeper/submodule &&
894 git submodule add ../submodule subsubmodule &&
895 (cd subsubmodule &&
896 git log > ../../../expected
897 ) &&
898 git commit -m "added subsubmodule" &&
899 git push origin :
900 ) &&
901 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
902 git log > ../../../../../actual
903 ) &&
904 git add deeper/submodule &&
905 git commit -m "update submodule" &&
906 git push origin : &&
907 test_cmp expected actual
911 test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
912 mkdir super_update_r &&
913 (cd super_update_r &&
914 git init --bare
915 ) &&
916 mkdir subsuper_update_r &&
917 (cd subsuper_update_r &&
918 git init --bare
919 ) &&
920 mkdir subsubsuper_update_r &&
921 (cd subsubsuper_update_r &&
922 git init --bare
923 ) &&
924 git clone subsubsuper_update_r subsubsuper_update_r2 &&
925 (cd subsubsuper_update_r2 &&
926 test_commit "update_subsubsuper" file &&
927 git push origin main
928 ) &&
929 git clone subsuper_update_r subsuper_update_r2 &&
930 (cd subsuper_update_r2 &&
931 test_commit "update_subsuper" file &&
932 git submodule add ../subsubsuper_update_r subsubmodule &&
933 git commit -am "subsubmodule" &&
934 git push origin main
935 ) &&
936 git clone super_update_r super_update_r2 &&
937 (cd super_update_r2 &&
938 test_commit "update_super" file &&
939 git submodule add ../subsuper_update_r submodule &&
940 git commit -am "submodule" &&
941 git push origin main
942 ) &&
943 rm -rf super_update_r2 &&
944 git clone super_update_r super_update_r2 &&
945 (cd super_update_r2 &&
946 git submodule update --init --recursive >actual &&
947 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
948 (cd submodule/subsubmodule &&
949 git log > ../../expected
950 ) &&
951 (cd .git/modules/submodule/modules/subsubmodule &&
952 git log > ../../../../../actual
953 ) &&
954 test_cmp expected actual
958 test_expect_success 'submodule add properly re-creates deeper level submodules' '
959 (cd super &&
960 git reset --hard main &&
961 rm -rf deeper/ &&
962 git submodule add --force ../submodule deeper/submodule
966 test_expect_success 'submodule update properly revives a moved submodule' '
967 (cd super &&
968 H=$(git rev-parse --short HEAD) &&
969 git commit -am "pre move" &&
970 H2=$(git rev-parse --short HEAD) &&
971 git status >out &&
972 sed "s/$H/XXX/" out >expect &&
973 H=$(cd submodule2 && git rev-parse HEAD) &&
974 git rm --cached submodule2 &&
975 rm -rf submodule2 &&
976 mkdir -p "moved/sub module" &&
977 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
978 git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
979 git commit -am "post move" &&
980 git submodule update &&
981 git status > out &&
982 sed "s/$H2/XXX/" out >actual &&
983 test_cmp expect actual
987 test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
988 mkdir -p linked/dir &&
989 ln -s linked/dir linkto &&
990 (cd linkto &&
991 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
992 (cd super &&
993 git submodule update --init --recursive
998 test_expect_success 'submodule update clone shallow submodule' '
999 test_when_finished "rm -rf super3" &&
1000 first=$(git -C cloned rev-parse HEAD:submodule) &&
1001 second=$(git -C submodule rev-parse HEAD) &&
1002 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
1003 git clone cloned super3 &&
1004 pwd=$(pwd) &&
1006 cd super3 &&
1007 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
1008 mv -f .gitmodules.tmp .gitmodules &&
1009 git submodule update --init --depth=$commit_count &&
1010 git -C submodule log --oneline >out &&
1011 test_line_count = 1 out
1015 test_expect_success 'submodule update clone shallow submodule outside of depth' '
1016 test_when_finished "rm -rf super3" &&
1017 git clone cloned super3 &&
1018 pwd=$(pwd) &&
1020 cd super3 &&
1021 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
1022 mv -f .gitmodules.tmp .gitmodules &&
1023 # Some protocol versions (e.g. 2) support fetching
1024 # unadvertised objects, so restrict this test to v0.
1025 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1026 git submodule update --init --depth=1 2>actual &&
1027 test_i18ngrep "Direct fetching of that commit failed." actual &&
1028 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
1029 git submodule update --init --depth=1 >actual &&
1030 git -C submodule log --oneline >out &&
1031 test_line_count = 1 out
1035 test_expect_success 'submodule update --recursive drops module name before recursing' '
1036 (cd super2 &&
1037 (cd deeper/submodule/subsubmodule &&
1038 git checkout HEAD^
1039 ) &&
1040 git submodule update --recursive deeper/submodule >actual &&
1041 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
1045 test_expect_success 'submodule update can be run in parallel' '
1046 (cd super2 &&
1047 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
1048 grep "7 tasks" trace.out &&
1049 git config submodule.fetchJobs 8 &&
1050 GIT_TRACE=$(pwd)/trace.out git submodule update &&
1051 grep "8 tasks" trace.out &&
1052 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
1053 grep "9 tasks" trace.out
1057 test_expect_success 'git clone passes the parallel jobs config on to submodules' '
1058 test_when_finished "rm -rf super4" &&
1059 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
1060 grep "7 tasks" trace.out &&
1061 rm -rf super4 &&
1062 git config --global submodule.fetchJobs 8 &&
1063 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
1064 grep "8 tasks" trace.out &&
1065 rm -rf super4 &&
1066 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
1067 grep "9 tasks" trace.out &&
1068 rm -rf super4
1071 test_expect_success 'submodule update --quiet passes quietness to merge/rebase' '
1072 (cd super &&
1073 test_commit -C rebasing message &&
1074 git submodule update --rebase --quiet >out 2>err &&
1075 test_must_be_empty out &&
1076 test_must_be_empty err &&
1077 git submodule update --rebase -v >out 2>err &&
1078 test_file_not_empty out &&
1079 test_must_be_empty err
1083 test_expect_success 'submodule update --quiet passes quietness to fetch with a shallow clone' '
1084 test_when_finished "rm -rf super4 super5 super6" &&
1085 git clone . super4 &&
1086 (cd super4 &&
1087 git submodule add --quiet file://"$TRASH_DIRECTORY"/submodule submodule3 &&
1088 git commit -am "setup submodule3"
1089 ) &&
1090 (cd submodule &&
1091 test_commit line6 file
1092 ) &&
1093 git clone super4 super5 &&
1094 (cd super5 &&
1095 git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
1096 test_must_be_empty out &&
1097 test_must_be_empty err
1098 ) &&
1099 git clone super4 super6 &&
1100 (cd super6 &&
1101 git submodule update --init --depth=1 submodule3 >out 2>err &&
1102 test_file_not_empty out &&
1103 test_file_not_empty err
1107 test_expect_success 'submodule update --filter requires --init' '
1108 test_expect_code 129 git -C super submodule update --filter blob:none
1111 test_expect_success 'submodule update --filter sets partial clone settings' '
1112 test_when_finished "rm -rf super-filter" &&
1113 git clone cloned super-filter &&
1114 git -C super-filter submodule update --init --filter blob:none &&
1115 test_cmp_config -C super-filter/submodule true remote.origin.promisor &&
1116 test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter
1119 test_done