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