Sync with 2.19.3
[git/debian.git] / t / t7406-submodule-update.sh
blobad7d8fa69e52046a653ba5b3789ce2cbc9d66a2c
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 Cloning into '$pwd/recursivesuper/super/merging'...
119 Cloning into '$pwd/recursivesuper/super/none'...
120 Cloning into '$pwd/recursivesuper/super/rebasing'...
121 Cloning into '$pwd/recursivesuper/super/submodule'...
122 Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
123 Submodule 'none' ($pwd/none) registered for path '../super/none'
124 Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
125 Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
126 done.
127 done.
128 done.
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 sort actual2 >actual2.sorted &&
141 test_i18ncmp expect2 actual2.sorted
144 cat <<EOF >expect2
145 Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
148 test_expect_success 'submodule update --init from and of subdirectory' '
149 git init withsubs &&
150 (cd withsubs &&
151 mkdir foo &&
152 git submodule add "$(pwd)/../rebasing" foo/sub &&
153 (cd foo &&
154 git submodule deinit -f sub &&
155 git submodule update --init sub 2>../../actual2
157 ) &&
158 test_i18ncmp expect2 actual2
161 apos="'";
162 test_expect_success 'submodule update does not fetch already present commits' '
163 (cd submodule &&
164 echo line3 >> file &&
165 git add file &&
166 test_tick &&
167 git commit -m "upstream line3"
168 ) &&
169 (cd super/submodule &&
170 head=$(git rev-parse --verify HEAD) &&
171 echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
172 git reset --hard HEAD~1
173 ) &&
174 (cd super &&
175 git submodule update > ../actual 2> ../actual.err
176 ) &&
177 test_i18ncmp expected actual &&
178 test_must_be_empty actual.err
181 test_expect_success 'submodule update should fail due to local changes' '
182 (cd super/submodule &&
183 git reset --hard HEAD~1 &&
184 echo "local change" > file
185 ) &&
186 (cd super &&
187 (cd submodule &&
188 compare_head
189 ) &&
190 test_must_fail git submodule update submodule
193 test_expect_success 'submodule update should throw away changes with --force ' '
194 (cd super &&
195 (cd submodule &&
196 compare_head
197 ) &&
198 git submodule update --force submodule &&
199 cd submodule &&
200 ! compare_head
204 test_expect_success 'submodule update --force forcibly checks out submodules' '
205 (cd super &&
206 (cd submodule &&
207 rm -f file
208 ) &&
209 git submodule update --force submodule &&
210 (cd submodule &&
211 test "$(git status -s file)" = ""
216 test_expect_success 'submodule update --remote should fetch upstream changes' '
217 (cd submodule &&
218 echo line4 >> file &&
219 git add file &&
220 test_tick &&
221 git commit -m "upstream line4"
222 ) &&
223 (cd super &&
224 git submodule update --remote --force submodule &&
225 cd submodule &&
226 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
230 test_expect_success 'submodule update --remote should fetch upstream changes with .' '
232 cd super &&
233 git config -f .gitmodules submodule."submodule".branch "." &&
234 git add .gitmodules &&
235 git commit -m "submodules: update from the respective superproject branch"
236 ) &&
238 cd submodule &&
239 echo line4a >> file &&
240 git add file &&
241 test_tick &&
242 git commit -m "upstream line4a" &&
243 git checkout -b test-branch &&
244 test_commit on-test-branch
245 ) &&
247 cd super &&
248 git submodule update --remote --force submodule &&
249 git -C submodule log -1 --oneline >actual &&
250 git -C ../submodule log -1 --oneline master >expect &&
251 test_cmp expect actual &&
252 git checkout -b test-branch &&
253 git submodule update --remote --force submodule &&
254 git -C submodule log -1 --oneline >actual &&
255 git -C ../submodule log -1 --oneline test-branch >expect &&
256 test_cmp expect actual &&
257 git checkout master &&
258 git branch -d test-branch &&
259 git reset --hard HEAD^
263 test_expect_success 'local config should override .gitmodules branch' '
264 (cd submodule &&
265 git checkout test-branch &&
266 echo line5 >> file &&
267 git add file &&
268 test_tick &&
269 git commit -m "upstream line5" &&
270 git checkout master
271 ) &&
272 (cd super &&
273 git config submodule.submodule.branch test-branch &&
274 git submodule update --remote --force submodule &&
275 cd submodule &&
276 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
280 test_expect_success 'submodule update --rebase staying on master' '
281 (cd super/submodule &&
282 git checkout master
283 ) &&
284 (cd super &&
285 (cd submodule &&
286 compare_head
287 ) &&
288 git submodule update --rebase submodule &&
289 cd submodule &&
290 compare_head
294 test_expect_success 'submodule update --merge staying on master' '
295 (cd super/submodule &&
296 git reset --hard HEAD~1
297 ) &&
298 (cd super &&
299 (cd submodule &&
300 compare_head
301 ) &&
302 git submodule update --merge submodule &&
303 cd submodule &&
304 compare_head
308 test_expect_success 'submodule update - rebase in .git/config' '
309 (cd super &&
310 git config submodule.submodule.update rebase
311 ) &&
312 (cd super/submodule &&
313 git reset --hard HEAD~1
314 ) &&
315 (cd super &&
316 (cd submodule &&
317 compare_head
318 ) &&
319 git submodule update submodule &&
320 cd submodule &&
321 compare_head
325 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
326 (cd super &&
327 git config submodule.submodule.update checkout
328 ) &&
329 (cd super/submodule &&
330 git reset --hard HEAD~1
331 ) &&
332 (cd super &&
333 (cd submodule &&
334 compare_head
335 ) &&
336 git submodule update --rebase submodule &&
337 cd submodule &&
338 compare_head
342 test_expect_success 'submodule update - merge in .git/config' '
343 (cd super &&
344 git config submodule.submodule.update merge
345 ) &&
346 (cd super/submodule &&
347 git reset --hard HEAD~1
348 ) &&
349 (cd super &&
350 (cd submodule &&
351 compare_head
352 ) &&
353 git submodule update submodule &&
354 cd submodule &&
355 compare_head
359 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
360 (cd super &&
361 git config submodule.submodule.update checkout
362 ) &&
363 (cd super/submodule &&
364 git reset --hard HEAD~1
365 ) &&
366 (cd super &&
367 (cd submodule &&
368 compare_head
369 ) &&
370 git submodule update --merge submodule &&
371 cd submodule &&
372 compare_head
376 test_expect_success 'submodule update - checkout in .git/config' '
377 (cd super &&
378 git config submodule.submodule.update checkout
379 ) &&
380 (cd super/submodule &&
381 git reset --hard HEAD^
382 ) &&
383 (cd super &&
384 (cd submodule &&
385 compare_head
386 ) &&
387 git submodule update submodule &&
388 cd submodule &&
389 ! compare_head
393 test_expect_success 'submodule update - command in .git/config' '
394 (cd super &&
395 git config submodule.submodule.update "!git checkout"
396 ) &&
397 (cd super/submodule &&
398 git reset --hard HEAD^
399 ) &&
400 (cd super &&
401 (cd submodule &&
402 compare_head
403 ) &&
404 git submodule update submodule &&
405 cd submodule &&
406 ! compare_head
410 test_expect_success 'submodule update - command in .gitmodules is rejected' '
411 test_when_finished "git -C super reset --hard HEAD^" &&
412 git -C super config -f .gitmodules submodule.submodule.update "!false" &&
413 git -C super commit -a -m "add command to .gitmodules file" &&
414 git -C super/submodule reset --hard $submodulesha1^ &&
415 test_must_fail git -C super submodule update submodule
418 test_expect_success 'fsck detects command in .gitmodules' '
419 git init command-in-gitmodules &&
421 cd command-in-gitmodules &&
422 git submodule add ../submodule submodule &&
423 test_commit adding-submodule &&
425 git config -f .gitmodules submodule.submodule.update "!false" &&
426 git add .gitmodules &&
427 test_commit configuring-update &&
428 test_must_fail git fsck
432 cat << EOF >expect
433 Execution of 'false $submodulesha1' failed in submodule path 'submodule'
436 test_expect_success 'submodule update - command in .git/config catches failure' '
437 (cd super &&
438 git config submodule.submodule.update "!false"
439 ) &&
440 (cd super/submodule &&
441 git reset --hard $submodulesha1^
442 ) &&
443 (cd super &&
444 test_must_fail git submodule update submodule 2>../actual
445 ) &&
446 test_i18ncmp actual expect
449 cat << EOF >expect
450 Execution of 'false $submodulesha1' failed in submodule path '../submodule'
453 test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' '
454 (cd super &&
455 git config submodule.submodule.update "!false"
456 ) &&
457 (cd super/submodule &&
458 git reset --hard $submodulesha1^
459 ) &&
460 (cd super &&
461 mkdir tmp && cd tmp &&
462 test_must_fail git submodule update ../submodule 2>../../actual
463 ) &&
464 test_i18ncmp actual expect
467 test_expect_success 'submodule update - command run for initial population of submodule' '
468 cat >expect <<-EOF &&
469 Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
471 rm -rf super/submodule &&
472 test_must_fail git -C super submodule update 2>actual &&
473 test_i18ncmp expect actual &&
474 git -C super submodule update --checkout
477 cat << EOF >expect
478 Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
479 Failed to recurse into submodule path '../super'
482 test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '
483 (cd recursivesuper &&
484 git submodule update --remote super &&
485 git add super &&
486 git commit -m "update to latest to have more than one commit in submodules"
487 ) &&
488 git -C recursivesuper/super config submodule.submodule.update "!false" &&
489 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
490 (cd recursivesuper &&
491 mkdir -p tmp && cd tmp &&
492 test_must_fail git submodule update --recursive ../super 2>../../actual
493 ) &&
494 test_i18ncmp actual expect
497 test_expect_success 'submodule init does not copy command into .git/config' '
498 test_when_finished "git -C super update-index --force-remove submodule1" &&
499 test_when_finished git config -f super/.gitmodules \
500 --remove-section submodule.submodule1 &&
501 (cd super &&
502 git ls-files -s submodule >out &&
503 H=$(cut -d" " -f2 out) &&
504 mkdir submodule1 &&
505 git update-index --add --cacheinfo 160000 $H submodule1 &&
506 git config -f .gitmodules submodule.submodule1.path submodule1 &&
507 git config -f .gitmodules submodule.submodule1.url ../submodule &&
508 git config -f .gitmodules submodule.submodule1.update !false &&
509 test_must_fail git submodule init submodule1 &&
510 test_expect_code 1 git config submodule.submodule1.update >actual &&
511 test_must_be_empty actual
515 test_expect_success 'submodule init picks up rebase' '
516 (cd super &&
517 git config -f .gitmodules submodule.rebasing.update rebase &&
518 git submodule init rebasing &&
519 test "rebase" = "$(git config submodule.rebasing.update)"
523 test_expect_success 'submodule init picks up merge' '
524 (cd super &&
525 git config -f .gitmodules submodule.merging.update merge &&
526 git submodule init merging &&
527 test "merge" = "$(git config submodule.merging.update)"
531 test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
532 test_config -C super submodule.submodule.update checkout &&
533 (cd super &&
534 rm -rf submodule &&
535 git submodule update submodule &&
536 git status -s submodule >expect &&
537 rm -rf submodule &&
538 git submodule update --merge submodule &&
539 git status -s submodule >actual &&
540 test_cmp expect actual
544 test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
545 test_config -C super submodule.submodule.update checkout &&
546 (cd super &&
547 rm -rf submodule &&
548 git submodule update submodule &&
549 git status -s submodule >expect &&
550 rm -rf submodule &&
551 git submodule update --rebase submodule &&
552 git status -s submodule >actual &&
553 test_cmp expect actual
557 test_expect_success 'submodule update ignores update=merge config for new submodules' '
558 (cd super &&
559 rm -rf submodule &&
560 git submodule update submodule &&
561 git status -s submodule >expect &&
562 rm -rf submodule &&
563 git config submodule.submodule.update merge &&
564 git submodule update submodule &&
565 git status -s submodule >actual &&
566 git config --unset submodule.submodule.update &&
567 test_cmp expect actual
571 test_expect_success 'submodule update ignores update=rebase config for new submodules' '
572 (cd super &&
573 rm -rf submodule &&
574 git submodule update submodule &&
575 git status -s submodule >expect &&
576 rm -rf submodule &&
577 git config submodule.submodule.update rebase &&
578 git submodule update submodule &&
579 git status -s submodule >actual &&
580 git config --unset submodule.submodule.update &&
581 test_cmp expect actual
585 test_expect_success 'submodule init picks up update=none' '
586 (cd super &&
587 git config -f .gitmodules submodule.none.update none &&
588 git submodule init none &&
589 test "none" = "$(git config submodule.none.update)"
593 test_expect_success 'submodule update - update=none in .git/config' '
594 (cd super &&
595 git config submodule.submodule.update none &&
596 (cd submodule &&
597 git checkout master &&
598 compare_head
599 ) &&
600 git diff --name-only >out &&
601 grep ^submodule$ out &&
602 git submodule update &&
603 git diff --name-only >out &&
604 grep ^submodule$ out &&
605 (cd submodule &&
606 compare_head
607 ) &&
608 git config --unset submodule.submodule.update &&
609 git submodule update submodule
613 test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
614 (cd super &&
615 git config submodule.submodule.update none &&
616 (cd submodule &&
617 git checkout master &&
618 compare_head
619 ) &&
620 git diff --name-only >out &&
621 grep ^submodule$ out &&
622 git submodule update --checkout &&
623 git diff --name-only >out &&
624 ! grep ^submodule$ out &&
625 (cd submodule &&
626 ! compare_head
627 ) &&
628 git config --unset submodule.submodule.update
632 test_expect_success 'submodule update --init skips submodule with update=none' '
633 (cd super &&
634 git add .gitmodules &&
635 git commit -m ".gitmodules"
636 ) &&
637 git clone super cloned &&
638 (cd cloned &&
639 git submodule update --init &&
640 test_path_exists submodule/.git &&
641 test_path_is_missing none/.git
645 test_expect_success 'submodule update continues after checkout error' '
646 (cd super &&
647 git reset --hard HEAD &&
648 git submodule add ../submodule submodule2 &&
649 git submodule init &&
650 git commit -am "new_submodule" &&
651 (cd submodule2 &&
652 git rev-parse --verify HEAD >../expect
653 ) &&
654 (cd submodule &&
655 test_commit "update_submodule" file
656 ) &&
657 (cd submodule2 &&
658 test_commit "update_submodule2" file
659 ) &&
660 git add submodule &&
661 git add submodule2 &&
662 git commit -m "two_new_submodule_commits" &&
663 (cd submodule &&
664 echo "" > file
665 ) &&
666 git checkout HEAD^ &&
667 test_must_fail git submodule update &&
668 (cd submodule2 &&
669 git rev-parse --verify HEAD >../actual
670 ) &&
671 test_cmp expect actual
674 test_expect_success 'submodule update continues after recursive checkout error' '
675 (cd super &&
676 git reset --hard HEAD &&
677 git checkout master &&
678 git submodule update &&
679 (cd submodule &&
680 git submodule add ../submodule subsubmodule &&
681 git submodule init &&
682 git commit -m "new_subsubmodule"
683 ) &&
684 git add submodule &&
685 git commit -m "update_submodule" &&
686 (cd submodule &&
687 (cd subsubmodule &&
688 test_commit "update_subsubmodule" file
689 ) &&
690 git add subsubmodule &&
691 test_commit "update_submodule_again" file &&
692 (cd subsubmodule &&
693 test_commit "update_subsubmodule_again" file
694 ) &&
695 test_commit "update_submodule_again_again" file
696 ) &&
697 (cd submodule2 &&
698 git rev-parse --verify HEAD >../expect &&
699 test_commit "update_submodule2_again" file
700 ) &&
701 git add submodule &&
702 git add submodule2 &&
703 git commit -m "new_commits" &&
704 git checkout HEAD^ &&
705 (cd submodule &&
706 git checkout HEAD^ &&
707 (cd subsubmodule &&
708 echo "" > file
710 ) &&
711 test_must_fail git submodule update --recursive &&
712 (cd submodule2 &&
713 git rev-parse --verify HEAD >../actual
714 ) &&
715 test_cmp expect actual
719 test_expect_success 'submodule update exit immediately in case of merge conflict' '
720 (cd super &&
721 git checkout master &&
722 git reset --hard HEAD &&
723 (cd submodule &&
724 (cd subsubmodule &&
725 git reset --hard HEAD
727 ) &&
728 git submodule update --recursive &&
729 (cd submodule &&
730 test_commit "update_submodule_2" file
731 ) &&
732 (cd submodule2 &&
733 test_commit "update_submodule2_2" file
734 ) &&
735 git add submodule &&
736 git add submodule2 &&
737 git commit -m "two_new_submodule_commits" &&
738 (cd submodule &&
739 git checkout master &&
740 test_commit "conflict" file &&
741 echo "conflict" > file
742 ) &&
743 git checkout HEAD^ &&
744 (cd submodule2 &&
745 git rev-parse --verify HEAD >../expect
746 ) &&
747 git config submodule.submodule.update merge &&
748 test_must_fail git submodule update &&
749 (cd submodule2 &&
750 git rev-parse --verify HEAD >../actual
751 ) &&
752 test_cmp expect actual
756 test_expect_success 'submodule update exit immediately after recursive rebase error' '
757 (cd super &&
758 git checkout master &&
759 git reset --hard HEAD &&
760 (cd submodule &&
761 git reset --hard HEAD &&
762 git submodule update --recursive
763 ) &&
764 (cd submodule &&
765 test_commit "update_submodule_3" file
766 ) &&
767 (cd submodule2 &&
768 test_commit "update_submodule2_3" file
769 ) &&
770 git add submodule &&
771 git add submodule2 &&
772 git commit -m "two_new_submodule_commits" &&
773 (cd submodule &&
774 git checkout master &&
775 test_commit "conflict2" file &&
776 echo "conflict" > file
777 ) &&
778 git checkout HEAD^ &&
779 (cd submodule2 &&
780 git rev-parse --verify HEAD >../expect
781 ) &&
782 git config submodule.submodule.update rebase &&
783 test_must_fail git submodule update &&
784 (cd submodule2 &&
785 git rev-parse --verify HEAD >../actual
786 ) &&
787 test_cmp expect actual
791 test_expect_success 'add different submodules to the same path' '
792 (cd super &&
793 git submodule add ../submodule s1 &&
794 test_must_fail git submodule add ../merging s1
798 test_expect_success 'submodule add places git-dir in superprojects git-dir' '
799 (cd super &&
800 mkdir deeper &&
801 git submodule add ../submodule deeper/submodule &&
802 (cd deeper/submodule &&
803 git log > ../../expected
804 ) &&
805 (cd .git/modules/deeper/submodule &&
806 git log > ../../../../actual
807 ) &&
808 test_cmp expected actual
812 test_expect_success 'submodule update places git-dir in superprojects git-dir' '
813 (cd super &&
814 git commit -m "added submodule"
815 ) &&
816 git clone super super2 &&
817 (cd super2 &&
818 git submodule init deeper/submodule &&
819 git submodule update &&
820 (cd deeper/submodule &&
821 git log > ../../expected
822 ) &&
823 (cd .git/modules/deeper/submodule &&
824 git log > ../../../../actual
825 ) &&
826 test_cmp expected actual
830 test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
831 (cd super2 &&
832 (cd deeper/submodule &&
833 git submodule add ../submodule subsubmodule &&
834 (cd subsubmodule &&
835 git log > ../../../expected
836 ) &&
837 git commit -m "added subsubmodule" &&
838 git push origin :
839 ) &&
840 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
841 git log > ../../../../../actual
842 ) &&
843 git add deeper/submodule &&
844 git commit -m "update submodule" &&
845 git push origin : &&
846 test_cmp expected actual
850 test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
851 mkdir super_update_r &&
852 (cd super_update_r &&
853 git init --bare
854 ) &&
855 mkdir subsuper_update_r &&
856 (cd subsuper_update_r &&
857 git init --bare
858 ) &&
859 mkdir subsubsuper_update_r &&
860 (cd subsubsuper_update_r &&
861 git init --bare
862 ) &&
863 git clone subsubsuper_update_r subsubsuper_update_r2 &&
864 (cd subsubsuper_update_r2 &&
865 test_commit "update_subsubsuper" file &&
866 git push origin master
867 ) &&
868 git clone subsuper_update_r subsuper_update_r2 &&
869 (cd subsuper_update_r2 &&
870 test_commit "update_subsuper" file &&
871 git submodule add ../subsubsuper_update_r subsubmodule &&
872 git commit -am "subsubmodule" &&
873 git push origin master
874 ) &&
875 git clone super_update_r super_update_r2 &&
876 (cd super_update_r2 &&
877 test_commit "update_super" file &&
878 git submodule add ../subsuper_update_r submodule &&
879 git commit -am "submodule" &&
880 git push origin master
881 ) &&
882 rm -rf super_update_r2 &&
883 git clone super_update_r super_update_r2 &&
884 (cd super_update_r2 &&
885 git submodule update --init --recursive >actual &&
886 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
887 (cd submodule/subsubmodule &&
888 git log > ../../expected
889 ) &&
890 (cd .git/modules/submodule/modules/subsubmodule &&
891 git log > ../../../../../actual
892 ) &&
893 test_cmp expected actual
897 test_expect_success 'submodule add properly re-creates deeper level submodules' '
898 (cd super &&
899 git reset --hard master &&
900 rm -rf deeper/ &&
901 git submodule add --force ../submodule deeper/submodule
905 test_expect_success 'submodule update properly revives a moved submodule' '
906 (cd super &&
907 H=$(git rev-parse --short HEAD) &&
908 git commit -am "pre move" &&
909 H2=$(git rev-parse --short HEAD) &&
910 git status >out &&
911 sed "s/$H/XXX/" out >expect &&
912 H=$(cd submodule2 && git rev-parse HEAD) &&
913 git rm --cached submodule2 &&
914 rm -rf submodule2 &&
915 mkdir -p "moved/sub module" &&
916 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
917 git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
918 git commit -am "post move" &&
919 git submodule update &&
920 git status > out &&
921 sed "s/$H2/XXX/" out >actual &&
922 test_cmp expect actual
926 test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
927 mkdir -p linked/dir &&
928 ln -s linked/dir linkto &&
929 (cd linkto &&
930 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
931 (cd super &&
932 git submodule update --init --recursive
937 test_expect_success 'submodule update clone shallow submodule' '
938 test_when_finished "rm -rf super3" &&
939 first=$(git -C cloned rev-parse HEAD:submodule) &&
940 second=$(git -C submodule rev-parse HEAD) &&
941 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
942 git clone cloned super3 &&
943 pwd=$(pwd) &&
945 cd super3 &&
946 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
947 mv -f .gitmodules.tmp .gitmodules &&
948 git submodule update --init --depth=$commit_count &&
949 git -C submodule log --oneline >out &&
950 test_line_count = 1 out
954 test_expect_success 'submodule update clone shallow submodule outside of depth' '
955 test_when_finished "rm -rf super3" &&
956 git clone cloned super3 &&
957 pwd=$(pwd) &&
959 cd super3 &&
960 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
961 mv -f .gitmodules.tmp .gitmodules &&
962 test_must_fail git submodule update --init --depth=1 2>actual &&
963 test_i18ngrep "Direct fetching of that commit failed." actual &&
964 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
965 git submodule update --init --depth=1 >actual &&
966 git -C submodule log --oneline >out &&
967 test_line_count = 1 out
971 test_expect_success 'submodule update --recursive drops module name before recursing' '
972 (cd super2 &&
973 (cd deeper/submodule/subsubmodule &&
974 git checkout HEAD^
975 ) &&
976 git submodule update --recursive deeper/submodule >actual &&
977 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
981 test_expect_success 'submodule update can be run in parallel' '
982 (cd super2 &&
983 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
984 grep "7 tasks" trace.out &&
985 git config submodule.fetchJobs 8 &&
986 GIT_TRACE=$(pwd)/trace.out git submodule update &&
987 grep "8 tasks" trace.out &&
988 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
989 grep "9 tasks" trace.out
993 test_expect_success 'git clone passes the parallel jobs config on to submodules' '
994 test_when_finished "rm -rf super4" &&
995 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
996 grep "7 tasks" trace.out &&
997 rm -rf super4 &&
998 git config --global submodule.fetchJobs 8 &&
999 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
1000 grep "8 tasks" trace.out &&
1001 rm -rf super4 &&
1002 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
1003 grep "9 tasks" trace.out &&
1004 rm -rf super4
1007 test_done