8c086a429b8253871b652265390ff6ba47c7074d
1#!/bin/sh
2#
3# Copyright (c) 2009 Red Hat, Inc.
4#
5
6test_description='Test updating submodules
7
8This test verifies that "git submodule update" detaches the HEAD of the
9submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
10'
11
12. ./test-lib.sh
13
14
15compare_head()
16{
17 sha_master=$(git rev-list --max-count=1 master)
18 sha_head=$(git rev-list --max-count=1 HEAD)
19
20 test "$sha_master" = "$sha_head"
21}
22
23
24test_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
70 )
71'
72
73test_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
84 )
85'
86
87test_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
99 )
100'
101
102supersha1=$(git -C super rev-parse HEAD)
103mergingsha1=$(git -C super/merging rev-parse HEAD)
104nonesha1=$(git -C super/none rev-parse HEAD)
105rebasingsha1=$(git -C super/rebasing rev-parse HEAD)
106submodulesha1=$(git -C super/submodule rev-parse HEAD)
107pwd=$(pwd)
108
109cat <<EOF >expect
110Submodule path '../super': checked out '$supersha1'
111Submodule path '../super/merging': checked out '$mergingsha1'
112Submodule path '../super/none': checked out '$nonesha1'
113Submodule path '../super/rebasing': checked out '$rebasingsha1'
114Submodule path '../super/submodule': checked out '$submodulesha1'
115EOF
116
117cat <<EOF >expect2
118Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
119Submodule 'none' ($pwd/none) registered for path '../super/none'
120Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
121Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
122Cloning into '$pwd/recursivesuper/super/merging'...
123done.
124Cloning into '$pwd/recursivesuper/super/none'...
125done.
126Cloning into '$pwd/recursivesuper/super/rebasing'...
127done.
128Cloning into '$pwd/recursivesuper/super/submodule'...
129done.
130EOF
131
132test_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
141'
142
143apos="'";
144test_expect_success 'submodule update does not fetch already present commits' '
145 (cd submodule &&
146 echo line3 >> file &&
147 git add file &&
148 test_tick &&
149 git commit -m "upstream line3"
150 ) &&
151 (cd super/submodule &&
152 head=$(git rev-parse --verify HEAD) &&
153 echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
154 git reset --hard HEAD~1
155 ) &&
156 (cd super &&
157 git submodule update > ../actual 2> ../actual.err
158 ) &&
159 test_i18ncmp expected actual &&
160 ! test -s actual.err
161'
162
163test_expect_success 'submodule update should fail due to local changes' '
164 (cd super/submodule &&
165 git reset --hard HEAD~1 &&
166 echo "local change" > file
167 ) &&
168 (cd super &&
169 (cd submodule &&
170 compare_head
171 ) &&
172 test_must_fail git submodule update submodule
173 )
174'
175test_expect_success 'submodule update should throw away changes with --force ' '
176 (cd super &&
177 (cd submodule &&
178 compare_head
179 ) &&
180 git submodule update --force submodule &&
181 cd submodule &&
182 ! compare_head
183 )
184'
185
186test_expect_success 'submodule update --force forcibly checks out submodules' '
187 (cd super &&
188 (cd submodule &&
189 rm -f file
190 ) &&
191 git submodule update --force submodule &&
192 (cd submodule &&
193 test "$(git status -s file)" = ""
194 )
195 )
196'
197
198test_expect_success 'submodule update --remote should fetch upstream changes' '
199 (cd submodule &&
200 echo line4 >> file &&
201 git add file &&
202 test_tick &&
203 git commit -m "upstream line4"
204 ) &&
205 (cd super &&
206 git submodule update --remote --force submodule &&
207 cd submodule &&
208 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
209 )
210'
211
212test_expect_success 'submodule update --remote should fetch upstream changes with .' '
213 (
214 cd super &&
215 git config -f .gitmodules submodule."submodule".branch "." &&
216 git add .gitmodules &&
217 git commit -m "submodules: update from the respective superproject branch"
218 ) &&
219 (
220 cd submodule &&
221 echo line4a >> file &&
222 git add file &&
223 test_tick &&
224 git commit -m "upstream line4a" &&
225 git checkout -b test-branch &&
226 test_commit on-test-branch
227 ) &&
228 (
229 cd super &&
230 git submodule update --remote --force submodule &&
231 git -C submodule log -1 --oneline >actual
232 git -C ../submodule log -1 --oneline master >expect
233 test_cmp expect actual &&
234 git checkout -b test-branch &&
235 git submodule update --remote --force submodule &&
236 git -C submodule log -1 --oneline >actual
237 git -C ../submodule log -1 --oneline test-branch >expect
238 test_cmp expect actual &&
239 git checkout master &&
240 git branch -d test-branch &&
241 git reset --hard HEAD^
242 )
243'
244
245test_expect_success 'local config should override .gitmodules branch' '
246 (cd submodule &&
247 git checkout test-branch &&
248 echo line5 >> file &&
249 git add file &&
250 test_tick &&
251 git commit -m "upstream line5" &&
252 git checkout master
253 ) &&
254 (cd super &&
255 git config submodule.submodule.branch test-branch &&
256 git submodule update --remote --force submodule &&
257 cd submodule &&
258 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
259 )
260'
261
262test_expect_success 'submodule update --rebase staying on master' '
263 (cd super/submodule &&
264 git checkout master
265 ) &&
266 (cd super &&
267 (cd submodule &&
268 compare_head
269 ) &&
270 git submodule update --rebase submodule &&
271 cd submodule &&
272 compare_head
273 )
274'
275
276test_expect_success 'submodule update --merge staying on master' '
277 (cd super/submodule &&
278 git reset --hard HEAD~1
279 ) &&
280 (cd super &&
281 (cd submodule &&
282 compare_head
283 ) &&
284 git submodule update --merge submodule &&
285 cd submodule &&
286 compare_head
287 )
288'
289
290test_expect_success 'submodule update - rebase in .git/config' '
291 (cd super &&
292 git config submodule.submodule.update rebase
293 ) &&
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 submodule &&
302 cd submodule &&
303 compare_head
304 )
305'
306
307test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
308 (cd super &&
309 git config submodule.submodule.update checkout
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 --rebase submodule &&
319 cd submodule &&
320 compare_head
321 )
322'
323
324test_expect_success 'submodule update - merge in .git/config' '
325 (cd super &&
326 git config submodule.submodule.update merge
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
338 )
339'
340
341test_expect_success 'submodule update - checkout in .git/config but --merge 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 --merge submodule &&
353 cd submodule &&
354 compare_head
355 )
356'
357
358test_expect_success 'submodule update - checkout in .git/config' '
359 (cd super &&
360 git config submodule.submodule.update checkout
361 ) &&
362 (cd super/submodule &&
363 git reset --hard HEAD^
364 ) &&
365 (cd super &&
366 (cd submodule &&
367 compare_head
368 ) &&
369 git submodule update submodule &&
370 cd submodule &&
371 ! compare_head
372 )
373'
374
375test_expect_success 'submodule update - command in .git/config' '
376 (cd super &&
377 git config submodule.submodule.update "!git 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
389 )
390'
391
392cat << EOF >expect
393Execution of 'false $submodulesha1' failed in submodule path 'submodule'
394EOF
395
396test_expect_success 'submodule update - command in .git/config catches failure' '
397 (cd super &&
398 git config submodule.submodule.update "!false"
399 ) &&
400 (cd super/submodule &&
401 git reset --hard $submodulesha1^
402 ) &&
403 (cd super &&
404 test_must_fail git submodule update submodule 2>../actual
405 ) &&
406 test_i18ncmp actual expect
407'
408
409cat << EOF >expect
410Execution of 'false $submodulesha1' failed in submodule path '../submodule'
411EOF
412
413test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' '
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 mkdir tmp && cd tmp &&
422 test_must_fail git submodule update ../submodule 2>../../actual
423 ) &&
424 test_i18ncmp actual expect
425'
426
427test_expect_success 'submodule update - command run for initial population of submodule' '
428 cat <<-\ EOF >expect
429 Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
430 EOF &&
431 rm -rf super/submodule &&
432 test_must_fail git -C super submodule update >../actual &&
433 test_cmp expect actual &&
434 git -C super submodule update --checkout
435'
436
437cat << EOF >expect
438Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
439Failed to recurse into submodule path '../super'
440EOF
441
442test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '
443 (cd recursivesuper &&
444 git submodule update --remote super &&
445 git add super &&
446 git commit -m "update to latest to have more than one commit in submodules"
447 ) &&
448 git -C recursivesuper/super config submodule.submodule.update "!false" &&
449 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
450 (cd recursivesuper &&
451 mkdir -p tmp && cd tmp &&
452 test_must_fail git submodule update --recursive ../super 2>../../actual
453 ) &&
454 test_i18ncmp actual expect
455'
456
457test_expect_success 'submodule init does not copy command into .git/config' '
458 (cd super &&
459 H=$(git ls-files -s submodule | cut -d" " -f2) &&
460 mkdir submodule1 &&
461 git update-index --add --cacheinfo 160000 $H submodule1 &&
462 git config -f .gitmodules submodule.submodule1.path submodule1 &&
463 git config -f .gitmodules submodule.submodule1.url ../submodule &&
464 git config -f .gitmodules submodule.submodule1.update !false &&
465 git submodule init submodule1 &&
466 echo "none" >expect &&
467 git config submodule.submodule1.update >actual &&
468 test_cmp expect actual
469 )
470'
471
472test_expect_success 'submodule init picks up rebase' '
473 (cd super &&
474 git config -f .gitmodules submodule.rebasing.update rebase &&
475 git submodule init rebasing &&
476 test "rebase" = "$(git config submodule.rebasing.update)"
477 )
478'
479
480test_expect_success 'submodule init picks up merge' '
481 (cd super &&
482 git config -f .gitmodules submodule.merging.update merge &&
483 git submodule init merging &&
484 test "merge" = "$(git config submodule.merging.update)"
485 )
486'
487
488test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
489 test_config -C super submodule.submodule.update checkout &&
490 (cd super &&
491 rm -rf submodule &&
492 git submodule update submodule &&
493 git status -s submodule >expect &&
494 rm -rf submodule &&
495 git submodule update --merge submodule &&
496 git status -s submodule >actual &&
497 test_cmp expect actual
498 )
499'
500
501test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
502 test_config -C super submodule.submodule.update checkout &&
503 (cd super &&
504 rm -rf submodule &&
505 git submodule update submodule &&
506 git status -s submodule >expect &&
507 rm -rf submodule &&
508 git submodule update --rebase submodule &&
509 git status -s submodule >actual &&
510 test_cmp expect actual
511 )
512'
513
514test_expect_success 'submodule update ignores update=merge config for new submodules' '
515 (cd super &&
516 rm -rf submodule &&
517 git submodule update submodule &&
518 git status -s submodule >expect &&
519 rm -rf submodule &&
520 git config submodule.submodule.update merge &&
521 git submodule update submodule &&
522 git status -s submodule >actual &&
523 git config --unset submodule.submodule.update &&
524 test_cmp expect actual
525 )
526'
527
528test_expect_success 'submodule update ignores update=rebase config for new submodules' '
529 (cd super &&
530 rm -rf submodule &&
531 git submodule update submodule &&
532 git status -s submodule >expect &&
533 rm -rf submodule &&
534 git config submodule.submodule.update rebase &&
535 git submodule update submodule &&
536 git status -s submodule >actual &&
537 git config --unset submodule.submodule.update &&
538 test_cmp expect actual
539 )
540'
541
542test_expect_success 'submodule init picks up update=none' '
543 (cd super &&
544 git config -f .gitmodules submodule.none.update none &&
545 git submodule init none &&
546 test "none" = "$(git config submodule.none.update)"
547 )
548'
549
550test_expect_success 'submodule update - update=none in .git/config' '
551 (cd super &&
552 git config submodule.submodule.update none &&
553 (cd submodule &&
554 git checkout master &&
555 compare_head
556 ) &&
557 git diff --raw | grep " submodule" &&
558 git submodule update &&
559 git diff --raw | grep " submodule" &&
560 (cd submodule &&
561 compare_head
562 ) &&
563 git config --unset submodule.submodule.update &&
564 git submodule update submodule
565 )
566'
567
568test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
569 (cd super &&
570 git config submodule.submodule.update none &&
571 (cd submodule &&
572 git checkout master &&
573 compare_head
574 ) &&
575 git diff --raw | grep " submodule" &&
576 git submodule update --checkout &&
577 test_must_fail git diff --raw \| grep " submodule" &&
578 (cd submodule &&
579 test_must_fail compare_head
580 ) &&
581 git config --unset submodule.submodule.update
582 )
583'
584
585test_expect_success 'submodule update --init skips submodule with update=none' '
586 (cd super &&
587 git add .gitmodules &&
588 git commit -m ".gitmodules"
589 ) &&
590 git clone super cloned &&
591 (cd cloned &&
592 git submodule update --init &&
593 test -e submodule/.git &&
594 test_must_fail test -e none/.git
595 )
596'
597
598test_expect_success 'submodule update continues after checkout error' '
599 (cd super &&
600 git reset --hard HEAD &&
601 git submodule add ../submodule submodule2 &&
602 git submodule init &&
603 git commit -am "new_submodule" &&
604 (cd submodule2 &&
605 git rev-parse --verify HEAD >../expect
606 ) &&
607 (cd submodule &&
608 test_commit "update_submodule" file
609 ) &&
610 (cd submodule2 &&
611 test_commit "update_submodule2" file
612 ) &&
613 git add submodule &&
614 git add submodule2 &&
615 git commit -m "two_new_submodule_commits" &&
616 (cd submodule &&
617 echo "" > file
618 ) &&
619 git checkout HEAD^ &&
620 test_must_fail git submodule update &&
621 (cd submodule2 &&
622 git rev-parse --verify HEAD >../actual
623 ) &&
624 test_cmp expect actual
625 )
626'
627test_expect_success 'submodule update continues after recursive checkout error' '
628 (cd super &&
629 git reset --hard HEAD &&
630 git checkout master &&
631 git submodule update &&
632 (cd submodule &&
633 git submodule add ../submodule subsubmodule &&
634 git submodule init &&
635 git commit -m "new_subsubmodule"
636 ) &&
637 git add submodule &&
638 git commit -m "update_submodule" &&
639 (cd submodule &&
640 (cd subsubmodule &&
641 test_commit "update_subsubmodule" file
642 ) &&
643 git add subsubmodule &&
644 test_commit "update_submodule_again" file &&
645 (cd subsubmodule &&
646 test_commit "update_subsubmodule_again" file
647 ) &&
648 test_commit "update_submodule_again_again" file
649 ) &&
650 (cd submodule2 &&
651 git rev-parse --verify HEAD >../expect &&
652 test_commit "update_submodule2_again" file
653 ) &&
654 git add submodule &&
655 git add submodule2 &&
656 git commit -m "new_commits" &&
657 git checkout HEAD^ &&
658 (cd submodule &&
659 git checkout HEAD^ &&
660 (cd subsubmodule &&
661 echo "" > file
662 )
663 ) &&
664 test_must_fail git submodule update --recursive &&
665 (cd submodule2 &&
666 git rev-parse --verify HEAD >../actual
667 ) &&
668 test_cmp expect actual
669 )
670'
671
672test_expect_success 'submodule update exit immediately in case of merge conflict' '
673 (cd super &&
674 git checkout master &&
675 git reset --hard HEAD &&
676 (cd submodule &&
677 (cd subsubmodule &&
678 git reset --hard HEAD
679 )
680 ) &&
681 git submodule update --recursive &&
682 (cd submodule &&
683 test_commit "update_submodule_2" file
684 ) &&
685 (cd submodule2 &&
686 test_commit "update_submodule2_2" file
687 ) &&
688 git add submodule &&
689 git add submodule2 &&
690 git commit -m "two_new_submodule_commits" &&
691 (cd submodule &&
692 git checkout master &&
693 test_commit "conflict" file &&
694 echo "conflict" > file
695 ) &&
696 git checkout HEAD^ &&
697 (cd submodule2 &&
698 git rev-parse --verify HEAD >../expect
699 ) &&
700 git config submodule.submodule.update merge &&
701 test_must_fail git submodule update &&
702 (cd submodule2 &&
703 git rev-parse --verify HEAD >../actual
704 ) &&
705 test_cmp expect actual
706 )
707'
708
709test_expect_success 'submodule update exit immediately after recursive rebase error' '
710 (cd super &&
711 git checkout master &&
712 git reset --hard HEAD &&
713 (cd submodule &&
714 git reset --hard HEAD &&
715 git submodule update --recursive
716 ) &&
717 (cd submodule &&
718 test_commit "update_submodule_3" file
719 ) &&
720 (cd submodule2 &&
721 test_commit "update_submodule2_3" file
722 ) &&
723 git add submodule &&
724 git add submodule2 &&
725 git commit -m "two_new_submodule_commits" &&
726 (cd submodule &&
727 git checkout master &&
728 test_commit "conflict2" file &&
729 echo "conflict" > file
730 ) &&
731 git checkout HEAD^ &&
732 (cd submodule2 &&
733 git rev-parse --verify HEAD >../expect
734 ) &&
735 git config submodule.submodule.update rebase &&
736 test_must_fail git submodule update &&
737 (cd submodule2 &&
738 git rev-parse --verify HEAD >../actual
739 ) &&
740 test_cmp expect actual
741 )
742'
743
744test_expect_success 'add different submodules to the same path' '
745 (cd super &&
746 git submodule add ../submodule s1 &&
747 test_must_fail git submodule add ../merging s1
748 )
749'
750
751test_expect_success 'submodule add places git-dir in superprojects git-dir' '
752 (cd super &&
753 mkdir deeper &&
754 git submodule add ../submodule deeper/submodule &&
755 (cd deeper/submodule &&
756 git log > ../../expected
757 ) &&
758 (cd .git/modules/deeper/submodule &&
759 git log > ../../../../actual
760 ) &&
761 test_cmp actual expected
762 )
763'
764
765test_expect_success 'submodule update places git-dir in superprojects git-dir' '
766 (cd super &&
767 git commit -m "added submodule"
768 ) &&
769 git clone super super2 &&
770 (cd super2 &&
771 git submodule init deeper/submodule &&
772 git submodule update &&
773 (cd deeper/submodule &&
774 git log > ../../expected
775 ) &&
776 (cd .git/modules/deeper/submodule &&
777 git log > ../../../../actual
778 ) &&
779 test_cmp actual expected
780 )
781'
782
783test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
784 (cd super2 &&
785 (cd deeper/submodule &&
786 git submodule add ../submodule subsubmodule &&
787 (cd subsubmodule &&
788 git log > ../../../expected
789 ) &&
790 git commit -m "added subsubmodule" &&
791 git push origin :
792 ) &&
793 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
794 git log > ../../../../../actual
795 ) &&
796 git add deeper/submodule &&
797 git commit -m "update submodule" &&
798 git push origin : &&
799 test_cmp actual expected
800 )
801'
802
803test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
804 mkdir super_update_r &&
805 (cd super_update_r &&
806 git init --bare
807 ) &&
808 mkdir subsuper_update_r &&
809 (cd subsuper_update_r &&
810 git init --bare
811 ) &&
812 mkdir subsubsuper_update_r &&
813 (cd subsubsuper_update_r &&
814 git init --bare
815 ) &&
816 git clone subsubsuper_update_r subsubsuper_update_r2 &&
817 (cd subsubsuper_update_r2 &&
818 test_commit "update_subsubsuper" file &&
819 git push origin master
820 ) &&
821 git clone subsuper_update_r subsuper_update_r2 &&
822 (cd subsuper_update_r2 &&
823 test_commit "update_subsuper" file &&
824 git submodule add ../subsubsuper_update_r subsubmodule &&
825 git commit -am "subsubmodule" &&
826 git push origin master
827 ) &&
828 git clone super_update_r super_update_r2 &&
829 (cd super_update_r2 &&
830 test_commit "update_super" file &&
831 git submodule add ../subsuper_update_r submodule &&
832 git commit -am "submodule" &&
833 git push origin master
834 ) &&
835 rm -rf super_update_r2 &&
836 git clone super_update_r super_update_r2 &&
837 (cd super_update_r2 &&
838 git submodule update --init --recursive >actual &&
839 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
840 (cd submodule/subsubmodule &&
841 git log > ../../expected
842 ) &&
843 (cd .git/modules/submodule/modules/subsubmodule
844 git log > ../../../../../actual
845 )
846 test_cmp actual expected
847 )
848'
849
850test_expect_success 'submodule add properly re-creates deeper level submodules' '
851 (cd super &&
852 git reset --hard master &&
853 rm -rf deeper/ &&
854 git submodule add --force ../submodule deeper/submodule
855 )
856'
857
858test_expect_success 'submodule update properly revives a moved submodule' '
859 (cd super &&
860 H=$(git rev-parse --short HEAD) &&
861 git commit -am "pre move" &&
862 H2=$(git rev-parse --short HEAD) &&
863 git status | sed "s/$H/XXX/" >expect &&
864 H=$(cd submodule2; git rev-parse HEAD) &&
865 git rm --cached submodule2 &&
866 rm -rf submodule2 &&
867 mkdir -p "moved/sub module" &&
868 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
869 git config -f .gitmodules submodule.submodule2.path "moved/sub module"
870 git commit -am "post move" &&
871 git submodule update &&
872 git status | sed "s/$H2/XXX/" >actual &&
873 test_cmp expect actual
874 )
875'
876
877test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
878 mkdir -p linked/dir &&
879 ln -s linked/dir linkto &&
880 (cd linkto &&
881 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
882 (cd super &&
883 git submodule update --init --recursive
884 )
885 )
886'
887
888test_expect_success 'submodule update clone shallow submodule' '
889 test_when_finished "rm -rf super3" &&
890 first=$(git -C cloned submodule status submodule |cut -c2-41) &&
891 second=$(git -C submodule rev-parse HEAD) &&
892 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
893 git clone cloned super3 &&
894 pwd=$(pwd) &&
895 (
896 cd super3 &&
897 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
898 mv -f .gitmodules.tmp .gitmodules &&
899 git submodule update --init --depth=$commit_count &&
900 test 1 = $(git -C submodule log --oneline | wc -l)
901 )
902'
903
904test_expect_success 'submodule update clone shallow submodule outside of depth' '
905 test_when_finished "rm -rf super3" &&
906 git clone cloned super3 &&
907 pwd=$(pwd) &&
908 (
909 cd super3 &&
910 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
911 mv -f .gitmodules.tmp .gitmodules &&
912 test_must_fail git submodule update --init --depth=1 2>actual &&
913 test_i18ngrep "Direct fetching of that commit failed." actual &&
914 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
915 git submodule update --init --depth=1 >actual &&
916 test 1 = $(git -C submodule log --oneline | wc -l)
917 )
918'
919
920test_expect_success 'submodule update --recursive drops module name before recursing' '
921 (cd super2 &&
922 (cd deeper/submodule/subsubmodule &&
923 git checkout HEAD^
924 ) &&
925 git submodule update --recursive deeper/submodule >actual &&
926 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
927 )
928'
929
930test_expect_success 'submodule update can be run in parallel' '
931 (cd super2 &&
932 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
933 grep "7 tasks" trace.out &&
934 git config submodule.fetchJobs 8 &&
935 GIT_TRACE=$(pwd)/trace.out git submodule update &&
936 grep "8 tasks" trace.out &&
937 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
938 grep "9 tasks" trace.out
939 )
940'
941
942test_expect_success 'git clone passes the parallel jobs config on to submodules' '
943 test_when_finished "rm -rf super4" &&
944 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
945 grep "7 tasks" trace.out &&
946 rm -rf super4 &&
947 git config --global submodule.fetchJobs 8 &&
948 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
949 grep "8 tasks" trace.out &&
950 rm -rf super4 &&
951 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
952 grep "9 tasks" trace.out &&
953 rm -rf super4
954'
955
956test_done