branch: add test for -m renaming multiple config sections
[git.git] / t / t7406-submodule-update.sh
blob034914a14fd49fea07e8bff4802994fcd38807a9
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 echo file > file &&
26 git add file &&
27 test_tick &&
28 git commit -m upstream &&
29 git clone . super &&
30 git clone super submodule &&
31 git clone super rebasing &&
32 git clone super merging &&
33 git clone super none &&
34 (cd super &&
35 git submodule add ../submodule submodule &&
36 test_tick &&
37 git commit -m "submodule" &&
38 git submodule init submodule
39 ) &&
40 (cd submodule &&
41 echo "line2" > file &&
42 git add file &&
43 git commit -m "Commit 2"
44 ) &&
45 (cd super &&
46 (cd submodule &&
47 git pull --rebase origin
48 ) &&
49 git add submodule &&
50 git commit -m "submodule update"
51 ) &&
52 (cd super &&
53 git submodule add ../rebasing rebasing &&
54 test_tick &&
55 git commit -m "rebasing"
56 ) &&
57 (cd super &&
58 git submodule add ../merging merging &&
59 test_tick &&
60 git commit -m "rebasing"
61 ) &&
62 (cd super &&
63 git submodule add ../none none &&
64 test_tick &&
65 git commit -m "none"
66 ) &&
67 git clone . recursivesuper &&
68 ( cd recursivesuper
69 git submodule add ../super super
73 test_expect_success 'submodule update detaching the HEAD ' '
74 (cd super/submodule &&
75 git reset --hard HEAD~1
76 ) &&
77 (cd super &&
78 (cd submodule &&
79 compare_head
80 ) &&
81 git submodule update submodule &&
82 cd submodule &&
83 ! compare_head
87 test_expect_success 'submodule update from subdirectory' '
88 (cd super/submodule &&
89 git reset --hard HEAD~1
90 ) &&
91 mkdir super/sub &&
92 (cd super/sub &&
93 (cd ../submodule &&
94 compare_head
95 ) &&
96 git submodule update ../submodule &&
97 cd ../submodule &&
98 ! compare_head
102 supersha1=$(git -C super rev-parse HEAD)
103 mergingsha1=$(git -C super/merging rev-parse HEAD)
104 nonesha1=$(git -C super/none rev-parse HEAD)
105 rebasingsha1=$(git -C super/rebasing rev-parse HEAD)
106 submodulesha1=$(git -C super/submodule rev-parse HEAD)
107 pwd=$(pwd)
109 cat <<EOF >expect
110 Submodule path '../super': checked out '$supersha1'
111 Submodule path '../super/merging': checked out '$mergingsha1'
112 Submodule path '../super/none': checked out '$nonesha1'
113 Submodule path '../super/rebasing': checked out '$rebasingsha1'
114 Submodule path '../super/submodule': checked out '$submodulesha1'
117 cat <<EOF >expect2
118 Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
119 Submodule 'none' ($pwd/none) registered for path '../super/none'
120 Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
121 Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
122 Cloning into '$pwd/recursivesuper/super/merging'...
123 done.
124 Cloning into '$pwd/recursivesuper/super/none'...
125 done.
126 Cloning into '$pwd/recursivesuper/super/rebasing'...
127 done.
128 Cloning into '$pwd/recursivesuper/super/submodule'...
129 done.
132 test_expect_success 'submodule update --init --recursive from subdirectory' '
133 git -C recursivesuper/super reset --hard HEAD^ &&
134 (cd recursivesuper &&
135 mkdir tmp &&
136 cd tmp &&
137 git submodule update --init --recursive ../super >../../actual 2>../../actual2
138 ) &&
139 test_i18ncmp expect actual &&
140 test_i18ncmp expect2 actual2
143 cat <<EOF >expect2
144 Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
147 test_expect_success 'submodule update --init from and of subdirectory' '
148 git init withsubs &&
149 (cd withsubs &&
150 mkdir foo &&
151 git submodule add "$(pwd)/../rebasing" foo/sub &&
152 (cd foo &&
153 git submodule deinit -f sub &&
154 git submodule update --init sub 2>../../actual2
156 ) &&
157 test_i18ncmp expect2 actual2
160 apos="'";
161 test_expect_success 'submodule update does not fetch already present commits' '
162 (cd submodule &&
163 echo line3 >> file &&
164 git add file &&
165 test_tick &&
166 git commit -m "upstream line3"
167 ) &&
168 (cd super/submodule &&
169 head=$(git rev-parse --verify HEAD) &&
170 echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
171 git reset --hard HEAD~1
172 ) &&
173 (cd super &&
174 git submodule update > ../actual 2> ../actual.err
175 ) &&
176 test_i18ncmp expected actual &&
177 ! test -s actual.err
180 test_expect_success 'submodule update should fail due to local changes' '
181 (cd super/submodule &&
182 git reset --hard HEAD~1 &&
183 echo "local change" > file
184 ) &&
185 (cd super &&
186 (cd submodule &&
187 compare_head
188 ) &&
189 test_must_fail git submodule update submodule
192 test_expect_success 'submodule update should throw away changes with --force ' '
193 (cd super &&
194 (cd submodule &&
195 compare_head
196 ) &&
197 git submodule update --force submodule &&
198 cd submodule &&
199 ! compare_head
203 test_expect_success 'submodule update --force forcibly checks out submodules' '
204 (cd super &&
205 (cd submodule &&
206 rm -f file
207 ) &&
208 git submodule update --force submodule &&
209 (cd submodule &&
210 test "$(git status -s file)" = ""
215 test_expect_success 'submodule update --remote should fetch upstream changes' '
216 (cd submodule &&
217 echo line4 >> file &&
218 git add file &&
219 test_tick &&
220 git commit -m "upstream line4"
221 ) &&
222 (cd super &&
223 git submodule update --remote --force submodule &&
224 cd submodule &&
225 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
229 test_expect_success 'submodule update --remote should fetch upstream changes with .' '
231 cd super &&
232 git config -f .gitmodules submodule."submodule".branch "." &&
233 git add .gitmodules &&
234 git commit -m "submodules: update from the respective superproject branch"
235 ) &&
237 cd submodule &&
238 echo line4a >> file &&
239 git add file &&
240 test_tick &&
241 git commit -m "upstream line4a" &&
242 git checkout -b test-branch &&
243 test_commit on-test-branch
244 ) &&
246 cd super &&
247 git submodule update --remote --force submodule &&
248 git -C submodule log -1 --oneline >actual
249 git -C ../submodule log -1 --oneline master >expect
250 test_cmp expect actual &&
251 git checkout -b test-branch &&
252 git submodule update --remote --force submodule &&
253 git -C submodule log -1 --oneline >actual
254 git -C ../submodule log -1 --oneline test-branch >expect
255 test_cmp expect actual &&
256 git checkout master &&
257 git branch -d test-branch &&
258 git reset --hard HEAD^
262 test_expect_success 'local config should override .gitmodules branch' '
263 (cd submodule &&
264 git checkout test-branch &&
265 echo line5 >> file &&
266 git add file &&
267 test_tick &&
268 git commit -m "upstream line5" &&
269 git checkout master
270 ) &&
271 (cd super &&
272 git config submodule.submodule.branch test-branch &&
273 git submodule update --remote --force submodule &&
274 cd submodule &&
275 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
279 test_expect_success 'submodule update --rebase staying on master' '
280 (cd super/submodule &&
281 git checkout master
282 ) &&
283 (cd super &&
284 (cd submodule &&
285 compare_head
286 ) &&
287 git submodule update --rebase submodule &&
288 cd submodule &&
289 compare_head
293 test_expect_success 'submodule update --merge staying on master' '
294 (cd super/submodule &&
295 git reset --hard HEAD~1
296 ) &&
297 (cd super &&
298 (cd submodule &&
299 compare_head
300 ) &&
301 git submodule update --merge submodule &&
302 cd submodule &&
303 compare_head
307 test_expect_success 'submodule update - rebase in .git/config' '
308 (cd super &&
309 git config submodule.submodule.update rebase
310 ) &&
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 submodule &&
319 cd submodule &&
320 compare_head
324 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
325 (cd super &&
326 git config submodule.submodule.update checkout
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 --rebase submodule &&
336 cd submodule &&
337 compare_head
341 test_expect_success 'submodule update - merge in .git/config' '
342 (cd super &&
343 git config submodule.submodule.update merge
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 submodule &&
353 cd submodule &&
354 compare_head
358 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
359 (cd super &&
360 git config submodule.submodule.update checkout
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 --merge submodule &&
370 cd submodule &&
371 compare_head
375 test_expect_success 'submodule update - checkout in .git/config' '
376 (cd super &&
377 git config submodule.submodule.update checkout
378 ) &&
379 (cd super/submodule &&
380 git reset --hard HEAD^
381 ) &&
382 (cd super &&
383 (cd submodule &&
384 compare_head
385 ) &&
386 git submodule update submodule &&
387 cd submodule &&
388 ! compare_head
392 test_expect_success 'submodule update - command in .git/config' '
393 (cd super &&
394 git config submodule.submodule.update "!git 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 cat << EOF >expect
410 Execution of 'false $submodulesha1' failed in submodule path 'submodule'
413 test_expect_success 'submodule update - command in .git/config catches failure' '
414 (cd super &&
415 git config submodule.submodule.update "!false"
416 ) &&
417 (cd super/submodule &&
418 git reset --hard $submodulesha1^
419 ) &&
420 (cd super &&
421 test_must_fail git submodule update submodule 2>../actual
422 ) &&
423 test_i18ncmp actual expect
426 cat << EOF >expect
427 Execution of 'false $submodulesha1' failed in submodule path '../submodule'
430 test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' '
431 (cd super &&
432 git config submodule.submodule.update "!false"
433 ) &&
434 (cd super/submodule &&
435 git reset --hard $submodulesha1^
436 ) &&
437 (cd super &&
438 mkdir tmp && cd tmp &&
439 test_must_fail git submodule update ../submodule 2>../../actual
440 ) &&
441 test_i18ncmp actual expect
444 test_expect_success 'submodule update - command run for initial population of submodule' '
445 cat >expect <<-EOF &&
446 Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
448 rm -rf super/submodule &&
449 test_must_fail git -C super submodule update 2>actual &&
450 test_i18ncmp expect actual &&
451 git -C super submodule update --checkout
454 cat << EOF >expect
455 Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
456 Failed to recurse into submodule path '../super'
459 test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '
460 (cd recursivesuper &&
461 git submodule update --remote super &&
462 git add super &&
463 git commit -m "update to latest to have more than one commit in submodules"
464 ) &&
465 git -C recursivesuper/super config submodule.submodule.update "!false" &&
466 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
467 (cd recursivesuper &&
468 mkdir -p tmp && cd tmp &&
469 test_must_fail git submodule update --recursive ../super 2>../../actual
470 ) &&
471 test_i18ncmp actual expect
474 test_expect_success 'submodule init does not copy command into .git/config' '
475 (cd super &&
476 H=$(git ls-files -s submodule | cut -d" " -f2) &&
477 mkdir submodule1 &&
478 git update-index --add --cacheinfo 160000 $H submodule1 &&
479 git config -f .gitmodules submodule.submodule1.path submodule1 &&
480 git config -f .gitmodules submodule.submodule1.url ../submodule &&
481 git config -f .gitmodules submodule.submodule1.update !false &&
482 git submodule init submodule1 &&
483 echo "none" >expect &&
484 git config submodule.submodule1.update >actual &&
485 test_cmp expect actual
489 test_expect_success 'submodule init picks up rebase' '
490 (cd super &&
491 git config -f .gitmodules submodule.rebasing.update rebase &&
492 git submodule init rebasing &&
493 test "rebase" = "$(git config submodule.rebasing.update)"
497 test_expect_success 'submodule init picks up merge' '
498 (cd super &&
499 git config -f .gitmodules submodule.merging.update merge &&
500 git submodule init merging &&
501 test "merge" = "$(git config submodule.merging.update)"
505 test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
506 test_config -C super submodule.submodule.update checkout &&
507 (cd super &&
508 rm -rf submodule &&
509 git submodule update submodule &&
510 git status -s submodule >expect &&
511 rm -rf submodule &&
512 git submodule update --merge submodule &&
513 git status -s submodule >actual &&
514 test_cmp expect actual
518 test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
519 test_config -C super submodule.submodule.update checkout &&
520 (cd super &&
521 rm -rf submodule &&
522 git submodule update submodule &&
523 git status -s submodule >expect &&
524 rm -rf submodule &&
525 git submodule update --rebase submodule &&
526 git status -s submodule >actual &&
527 test_cmp expect actual
531 test_expect_success 'submodule update ignores update=merge config for new submodules' '
532 (cd super &&
533 rm -rf submodule &&
534 git submodule update submodule &&
535 git status -s submodule >expect &&
536 rm -rf submodule &&
537 git config submodule.submodule.update merge &&
538 git submodule update submodule &&
539 git status -s submodule >actual &&
540 git config --unset submodule.submodule.update &&
541 test_cmp expect actual
545 test_expect_success 'submodule update ignores update=rebase config for new submodules' '
546 (cd super &&
547 rm -rf submodule &&
548 git submodule update submodule &&
549 git status -s submodule >expect &&
550 rm -rf submodule &&
551 git config submodule.submodule.update rebase &&
552 git submodule update submodule &&
553 git status -s submodule >actual &&
554 git config --unset submodule.submodule.update &&
555 test_cmp expect actual
559 test_expect_success 'submodule init picks up update=none' '
560 (cd super &&
561 git config -f .gitmodules submodule.none.update none &&
562 git submodule init none &&
563 test "none" = "$(git config submodule.none.update)"
567 test_expect_success 'submodule update - update=none in .git/config' '
568 (cd super &&
569 git config submodule.submodule.update none &&
570 (cd submodule &&
571 git checkout master &&
572 compare_head
573 ) &&
574 git diff --raw | grep " submodule" &&
575 git submodule update &&
576 git diff --raw | grep " submodule" &&
577 (cd submodule &&
578 compare_head
579 ) &&
580 git config --unset submodule.submodule.update &&
581 git submodule update submodule
585 test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
586 (cd super &&
587 git config submodule.submodule.update none &&
588 (cd submodule &&
589 git checkout master &&
590 compare_head
591 ) &&
592 git diff --raw | grep " submodule" &&
593 git submodule update --checkout &&
594 test_must_fail git diff --raw \| grep " submodule" &&
595 (cd submodule &&
596 test_must_fail compare_head
597 ) &&
598 git config --unset submodule.submodule.update
602 test_expect_success 'submodule update --init skips submodule with update=none' '
603 (cd super &&
604 git add .gitmodules &&
605 git commit -m ".gitmodules"
606 ) &&
607 git clone super cloned &&
608 (cd cloned &&
609 git submodule update --init &&
610 test -e submodule/.git &&
611 test_must_fail test -e none/.git
615 test_expect_success 'submodule update continues after checkout error' '
616 (cd super &&
617 git reset --hard HEAD &&
618 git submodule add ../submodule submodule2 &&
619 git submodule init &&
620 git commit -am "new_submodule" &&
621 (cd submodule2 &&
622 git rev-parse --verify HEAD >../expect
623 ) &&
624 (cd submodule &&
625 test_commit "update_submodule" file
626 ) &&
627 (cd submodule2 &&
628 test_commit "update_submodule2" file
629 ) &&
630 git add submodule &&
631 git add submodule2 &&
632 git commit -m "two_new_submodule_commits" &&
633 (cd submodule &&
634 echo "" > file
635 ) &&
636 git checkout HEAD^ &&
637 test_must_fail git submodule update &&
638 (cd submodule2 &&
639 git rev-parse --verify HEAD >../actual
640 ) &&
641 test_cmp expect actual
644 test_expect_success 'submodule update continues after recursive checkout error' '
645 (cd super &&
646 git reset --hard HEAD &&
647 git checkout master &&
648 git submodule update &&
649 (cd submodule &&
650 git submodule add ../submodule subsubmodule &&
651 git submodule init &&
652 git commit -m "new_subsubmodule"
653 ) &&
654 git add submodule &&
655 git commit -m "update_submodule" &&
656 (cd submodule &&
657 (cd subsubmodule &&
658 test_commit "update_subsubmodule" file
659 ) &&
660 git add subsubmodule &&
661 test_commit "update_submodule_again" file &&
662 (cd subsubmodule &&
663 test_commit "update_subsubmodule_again" file
664 ) &&
665 test_commit "update_submodule_again_again" file
666 ) &&
667 (cd submodule2 &&
668 git rev-parse --verify HEAD >../expect &&
669 test_commit "update_submodule2_again" file
670 ) &&
671 git add submodule &&
672 git add submodule2 &&
673 git commit -m "new_commits" &&
674 git checkout HEAD^ &&
675 (cd submodule &&
676 git checkout HEAD^ &&
677 (cd subsubmodule &&
678 echo "" > file
680 ) &&
681 test_must_fail git submodule update --recursive &&
682 (cd submodule2 &&
683 git rev-parse --verify HEAD >../actual
684 ) &&
685 test_cmp expect actual
689 test_expect_success 'submodule update exit immediately in case of merge conflict' '
690 (cd super &&
691 git checkout master &&
692 git reset --hard HEAD &&
693 (cd submodule &&
694 (cd subsubmodule &&
695 git reset --hard HEAD
697 ) &&
698 git submodule update --recursive &&
699 (cd submodule &&
700 test_commit "update_submodule_2" file
701 ) &&
702 (cd submodule2 &&
703 test_commit "update_submodule2_2" file
704 ) &&
705 git add submodule &&
706 git add submodule2 &&
707 git commit -m "two_new_submodule_commits" &&
708 (cd submodule &&
709 git checkout master &&
710 test_commit "conflict" file &&
711 echo "conflict" > file
712 ) &&
713 git checkout HEAD^ &&
714 (cd submodule2 &&
715 git rev-parse --verify HEAD >../expect
716 ) &&
717 git config submodule.submodule.update merge &&
718 test_must_fail git submodule update &&
719 (cd submodule2 &&
720 git rev-parse --verify HEAD >../actual
721 ) &&
722 test_cmp expect actual
726 test_expect_success 'submodule update exit immediately after recursive rebase error' '
727 (cd super &&
728 git checkout master &&
729 git reset --hard HEAD &&
730 (cd submodule &&
731 git reset --hard HEAD &&
732 git submodule update --recursive
733 ) &&
734 (cd submodule &&
735 test_commit "update_submodule_3" file
736 ) &&
737 (cd submodule2 &&
738 test_commit "update_submodule2_3" file
739 ) &&
740 git add submodule &&
741 git add submodule2 &&
742 git commit -m "two_new_submodule_commits" &&
743 (cd submodule &&
744 git checkout master &&
745 test_commit "conflict2" file &&
746 echo "conflict" > file
747 ) &&
748 git checkout HEAD^ &&
749 (cd submodule2 &&
750 git rev-parse --verify HEAD >../expect
751 ) &&
752 git config submodule.submodule.update rebase &&
753 test_must_fail git submodule update &&
754 (cd submodule2 &&
755 git rev-parse --verify HEAD >../actual
756 ) &&
757 test_cmp expect actual
761 test_expect_success 'add different submodules to the same path' '
762 (cd super &&
763 git submodule add ../submodule s1 &&
764 test_must_fail git submodule add ../merging s1
768 test_expect_success 'submodule add places git-dir in superprojects git-dir' '
769 (cd super &&
770 mkdir deeper &&
771 git submodule add ../submodule deeper/submodule &&
772 (cd deeper/submodule &&
773 git log > ../../expected
774 ) &&
775 (cd .git/modules/deeper/submodule &&
776 git log > ../../../../actual
777 ) &&
778 test_cmp actual expected
782 test_expect_success 'submodule update places git-dir in superprojects git-dir' '
783 (cd super &&
784 git commit -m "added submodule"
785 ) &&
786 git clone super super2 &&
787 (cd super2 &&
788 git submodule init deeper/submodule &&
789 git submodule update &&
790 (cd deeper/submodule &&
791 git log > ../../expected
792 ) &&
793 (cd .git/modules/deeper/submodule &&
794 git log > ../../../../actual
795 ) &&
796 test_cmp actual expected
800 test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
801 (cd super2 &&
802 (cd deeper/submodule &&
803 git submodule add ../submodule subsubmodule &&
804 (cd subsubmodule &&
805 git log > ../../../expected
806 ) &&
807 git commit -m "added subsubmodule" &&
808 git push origin :
809 ) &&
810 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
811 git log > ../../../../../actual
812 ) &&
813 git add deeper/submodule &&
814 git commit -m "update submodule" &&
815 git push origin : &&
816 test_cmp actual expected
820 test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
821 mkdir super_update_r &&
822 (cd super_update_r &&
823 git init --bare
824 ) &&
825 mkdir subsuper_update_r &&
826 (cd subsuper_update_r &&
827 git init --bare
828 ) &&
829 mkdir subsubsuper_update_r &&
830 (cd subsubsuper_update_r &&
831 git init --bare
832 ) &&
833 git clone subsubsuper_update_r subsubsuper_update_r2 &&
834 (cd subsubsuper_update_r2 &&
835 test_commit "update_subsubsuper" file &&
836 git push origin master
837 ) &&
838 git clone subsuper_update_r subsuper_update_r2 &&
839 (cd subsuper_update_r2 &&
840 test_commit "update_subsuper" file &&
841 git submodule add ../subsubsuper_update_r subsubmodule &&
842 git commit -am "subsubmodule" &&
843 git push origin master
844 ) &&
845 git clone super_update_r super_update_r2 &&
846 (cd super_update_r2 &&
847 test_commit "update_super" file &&
848 git submodule add ../subsuper_update_r submodule &&
849 git commit -am "submodule" &&
850 git push origin master
851 ) &&
852 rm -rf super_update_r2 &&
853 git clone super_update_r super_update_r2 &&
854 (cd super_update_r2 &&
855 git submodule update --init --recursive >actual &&
856 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
857 (cd submodule/subsubmodule &&
858 git log > ../../expected
859 ) &&
860 (cd .git/modules/submodule/modules/subsubmodule
861 git log > ../../../../../actual
863 test_cmp actual expected
867 test_expect_success 'submodule add properly re-creates deeper level submodules' '
868 (cd super &&
869 git reset --hard master &&
870 rm -rf deeper/ &&
871 git submodule add --force ../submodule deeper/submodule
875 test_expect_success 'submodule update properly revives a moved submodule' '
876 (cd super &&
877 H=$(git rev-parse --short HEAD) &&
878 git commit -am "pre move" &&
879 H2=$(git rev-parse --short HEAD) &&
880 git status | sed "s/$H/XXX/" >expect &&
881 H=$(cd submodule2; git rev-parse HEAD) &&
882 git rm --cached submodule2 &&
883 rm -rf submodule2 &&
884 mkdir -p "moved/sub module" &&
885 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
886 git config -f .gitmodules submodule.submodule2.path "moved/sub module"
887 git commit -am "post move" &&
888 git submodule update &&
889 git status | sed "s/$H2/XXX/" >actual &&
890 test_cmp expect actual
894 test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
895 mkdir -p linked/dir &&
896 ln -s linked/dir linkto &&
897 (cd linkto &&
898 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
899 (cd super &&
900 git submodule update --init --recursive
905 test_expect_success 'submodule update clone shallow submodule' '
906 test_when_finished "rm -rf super3" &&
907 first=$(git -C cloned submodule status submodule |cut -c2-41) &&
908 second=$(git -C submodule rev-parse HEAD) &&
909 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
910 git clone cloned super3 &&
911 pwd=$(pwd) &&
913 cd super3 &&
914 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
915 mv -f .gitmodules.tmp .gitmodules &&
916 git submodule update --init --depth=$commit_count &&
917 test 1 = $(git -C submodule log --oneline | wc -l)
921 test_expect_success 'submodule update clone shallow submodule outside of depth' '
922 test_when_finished "rm -rf super3" &&
923 git clone cloned super3 &&
924 pwd=$(pwd) &&
926 cd super3 &&
927 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
928 mv -f .gitmodules.tmp .gitmodules &&
929 test_must_fail git submodule update --init --depth=1 2>actual &&
930 test_i18ngrep "Direct fetching of that commit failed." actual &&
931 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
932 git submodule update --init --depth=1 >actual &&
933 test 1 = $(git -C submodule log --oneline | wc -l)
937 test_expect_success 'submodule update --recursive drops module name before recursing' '
938 (cd super2 &&
939 (cd deeper/submodule/subsubmodule &&
940 git checkout HEAD^
941 ) &&
942 git submodule update --recursive deeper/submodule >actual &&
943 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
947 test_expect_success 'submodule update can be run in parallel' '
948 (cd super2 &&
949 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
950 grep "7 tasks" trace.out &&
951 git config submodule.fetchJobs 8 &&
952 GIT_TRACE=$(pwd)/trace.out git submodule update &&
953 grep "8 tasks" trace.out &&
954 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
955 grep "9 tasks" trace.out
959 test_expect_success 'git clone passes the parallel jobs config on to submodules' '
960 test_when_finished "rm -rf super4" &&
961 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
962 grep "7 tasks" trace.out &&
963 rm -rf super4 &&
964 git config --global submodule.fetchJobs 8 &&
965 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
966 grep "8 tasks" trace.out &&
967 rm -rf super4 &&
968 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
969 grep "9 tasks" trace.out &&
970 rm -rf super4
973 test_done