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