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
427cat << EOF >expect
428Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
429Failed to recurse into submodule path '../super'
430EOF
431
432test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '
433 (cd recursivesuper &&
434 git submodule update --remote super &&
435 git add super &&
436 git commit -m "update to latest to have more than one commit in submodules"
437 ) &&
438 git -C recursivesuper/super config submodule.submodule.update "!false" &&
439 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
440 (cd recursivesuper &&
441 mkdir -p tmp && cd tmp &&
442 test_must_fail git submodule update --recursive ../super 2>../../actual
443 ) &&
444 test_i18ncmp actual expect
445'
446
447test_expect_success 'submodule init does not copy command into .git/config' '
448 (cd super &&
449 H=$(git ls-files -s submodule | cut -d" " -f2) &&
450 mkdir submodule1 &&
451 git update-index --add --cacheinfo 160000 $H submodule1 &&
452 git config -f .gitmodules submodule.submodule1.path submodule1 &&
453 git config -f .gitmodules submodule.submodule1.url ../submodule &&
454 git config -f .gitmodules submodule.submodule1.update !false &&
455 git submodule init submodule1 &&
456 echo "none" >expect &&
457 git config submodule.submodule1.update >actual &&
458 test_cmp expect actual
459 )
460'
461
462test_expect_success 'submodule init picks up rebase' '
463 (cd super &&
464 git config -f .gitmodules submodule.rebasing.update rebase &&
465 git submodule init rebasing &&
466 test "rebase" = "$(git config submodule.rebasing.update)"
467 )
468'
469
470test_expect_success 'submodule init picks up merge' '
471 (cd super &&
472 git config -f .gitmodules submodule.merging.update merge &&
473 git submodule init merging &&
474 test "merge" = "$(git config submodule.merging.update)"
475 )
476'
477
478test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
479 (cd super &&
480 rm -rf submodule &&
481 git submodule update submodule &&
482 git status -s submodule >expect &&
483 rm -rf submodule &&
484 git submodule update --merge submodule &&
485 git status -s submodule >actual &&
486 test_cmp expect actual
487 )
488'
489
490test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
491 (cd super &&
492 rm -rf submodule &&
493 git submodule update submodule &&
494 git status -s submodule >expect &&
495 rm -rf submodule &&
496 git submodule update --rebase submodule &&
497 git status -s submodule >actual &&
498 test_cmp expect actual
499 )
500'
501
502test_expect_success 'submodule update ignores update=merge config for new submodules' '
503 (cd super &&
504 rm -rf submodule &&
505 git submodule update submodule &&
506 git status -s submodule >expect &&
507 rm -rf submodule &&
508 git config submodule.submodule.update merge &&
509 git submodule update submodule &&
510 git status -s submodule >actual &&
511 git config --unset submodule.submodule.update &&
512 test_cmp expect actual
513 )
514'
515
516test_expect_success 'submodule update ignores update=rebase config for new submodules' '
517 (cd super &&
518 rm -rf submodule &&
519 git submodule update submodule &&
520 git status -s submodule >expect &&
521 rm -rf submodule &&
522 git config submodule.submodule.update rebase &&
523 git submodule update submodule &&
524 git status -s submodule >actual &&
525 git config --unset submodule.submodule.update &&
526 test_cmp expect actual
527 )
528'
529
530test_expect_success 'submodule init picks up update=none' '
531 (cd super &&
532 git config -f .gitmodules submodule.none.update none &&
533 git submodule init none &&
534 test "none" = "$(git config submodule.none.update)"
535 )
536'
537
538test_expect_success 'submodule update - update=none in .git/config' '
539 (cd super &&
540 git config submodule.submodule.update none &&
541 (cd submodule &&
542 git checkout master &&
543 compare_head
544 ) &&
545 git diff --raw | grep " submodule" &&
546 git submodule update &&
547 git diff --raw | grep " submodule" &&
548 (cd submodule &&
549 compare_head
550 ) &&
551 git config --unset submodule.submodule.update &&
552 git submodule update submodule
553 )
554'
555
556test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
557 (cd super &&
558 git config submodule.submodule.update none &&
559 (cd submodule &&
560 git checkout master &&
561 compare_head
562 ) &&
563 git diff --raw | grep " submodule" &&
564 git submodule update --checkout &&
565 test_must_fail git diff --raw \| grep " submodule" &&
566 (cd submodule &&
567 test_must_fail compare_head
568 ) &&
569 git config --unset submodule.submodule.update
570 )
571'
572
573test_expect_success 'submodule update --init skips submodule with update=none' '
574 (cd super &&
575 git add .gitmodules &&
576 git commit -m ".gitmodules"
577 ) &&
578 git clone super cloned &&
579 (cd cloned &&
580 git submodule update --init &&
581 test -e submodule/.git &&
582 test_must_fail test -e none/.git
583 )
584'
585
586test_expect_success 'submodule update continues after checkout error' '
587 (cd super &&
588 git reset --hard HEAD &&
589 git submodule add ../submodule submodule2 &&
590 git submodule init &&
591 git commit -am "new_submodule" &&
592 (cd submodule2 &&
593 git rev-parse --verify HEAD >../expect
594 ) &&
595 (cd submodule &&
596 test_commit "update_submodule" file
597 ) &&
598 (cd submodule2 &&
599 test_commit "update_submodule2" file
600 ) &&
601 git add submodule &&
602 git add submodule2 &&
603 git commit -m "two_new_submodule_commits" &&
604 (cd submodule &&
605 echo "" > file
606 ) &&
607 git checkout HEAD^ &&
608 test_must_fail git submodule update &&
609 (cd submodule2 &&
610 git rev-parse --verify HEAD >../actual
611 ) &&
612 test_cmp expect actual
613 )
614'
615test_expect_success 'submodule update continues after recursive checkout error' '
616 (cd super &&
617 git reset --hard HEAD &&
618 git checkout master &&
619 git submodule update &&
620 (cd submodule &&
621 git submodule add ../submodule subsubmodule &&
622 git submodule init &&
623 git commit -m "new_subsubmodule"
624 ) &&
625 git add submodule &&
626 git commit -m "update_submodule" &&
627 (cd submodule &&
628 (cd subsubmodule &&
629 test_commit "update_subsubmodule" file
630 ) &&
631 git add subsubmodule &&
632 test_commit "update_submodule_again" file &&
633 (cd subsubmodule &&
634 test_commit "update_subsubmodule_again" file
635 ) &&
636 test_commit "update_submodule_again_again" file
637 ) &&
638 (cd submodule2 &&
639 git rev-parse --verify HEAD >../expect &&
640 test_commit "update_submodule2_again" file
641 ) &&
642 git add submodule &&
643 git add submodule2 &&
644 git commit -m "new_commits" &&
645 git checkout HEAD^ &&
646 (cd submodule &&
647 git checkout HEAD^ &&
648 (cd subsubmodule &&
649 echo "" > file
650 )
651 ) &&
652 test_must_fail git submodule update --recursive &&
653 (cd submodule2 &&
654 git rev-parse --verify HEAD >../actual
655 ) &&
656 test_cmp expect actual
657 )
658'
659
660test_expect_success 'submodule update exit immediately in case of merge conflict' '
661 (cd super &&
662 git checkout master &&
663 git reset --hard HEAD &&
664 (cd submodule &&
665 (cd subsubmodule &&
666 git reset --hard HEAD
667 )
668 ) &&
669 git submodule update --recursive &&
670 (cd submodule &&
671 test_commit "update_submodule_2" file
672 ) &&
673 (cd submodule2 &&
674 test_commit "update_submodule2_2" file
675 ) &&
676 git add submodule &&
677 git add submodule2 &&
678 git commit -m "two_new_submodule_commits" &&
679 (cd submodule &&
680 git checkout master &&
681 test_commit "conflict" file &&
682 echo "conflict" > file
683 ) &&
684 git checkout HEAD^ &&
685 (cd submodule2 &&
686 git rev-parse --verify HEAD >../expect
687 ) &&
688 git config submodule.submodule.update merge &&
689 test_must_fail git submodule update &&
690 (cd submodule2 &&
691 git rev-parse --verify HEAD >../actual
692 ) &&
693 test_cmp expect actual
694 )
695'
696
697test_expect_success 'submodule update exit immediately after recursive rebase error' '
698 (cd super &&
699 git checkout master &&
700 git reset --hard HEAD &&
701 (cd submodule &&
702 git reset --hard HEAD &&
703 git submodule update --recursive
704 ) &&
705 (cd submodule &&
706 test_commit "update_submodule_3" file
707 ) &&
708 (cd submodule2 &&
709 test_commit "update_submodule2_3" file
710 ) &&
711 git add submodule &&
712 git add submodule2 &&
713 git commit -m "two_new_submodule_commits" &&
714 (cd submodule &&
715 git checkout master &&
716 test_commit "conflict2" file &&
717 echo "conflict" > file
718 ) &&
719 git checkout HEAD^ &&
720 (cd submodule2 &&
721 git rev-parse --verify HEAD >../expect
722 ) &&
723 git config submodule.submodule.update rebase &&
724 test_must_fail git submodule update &&
725 (cd submodule2 &&
726 git rev-parse --verify HEAD >../actual
727 ) &&
728 test_cmp expect actual
729 )
730'
731
732test_expect_success 'add different submodules to the same path' '
733 (cd super &&
734 git submodule add ../submodule s1 &&
735 test_must_fail git submodule add ../merging s1
736 )
737'
738
739test_expect_success 'submodule add places git-dir in superprojects git-dir' '
740 (cd super &&
741 mkdir deeper &&
742 git submodule add ../submodule deeper/submodule &&
743 (cd deeper/submodule &&
744 git log > ../../expected
745 ) &&
746 (cd .git/modules/deeper/submodule &&
747 git log > ../../../../actual
748 ) &&
749 test_cmp actual expected
750 )
751'
752
753test_expect_success 'submodule update places git-dir in superprojects git-dir' '
754 (cd super &&
755 git commit -m "added submodule"
756 ) &&
757 git clone super super2 &&
758 (cd super2 &&
759 git submodule init deeper/submodule &&
760 git submodule update &&
761 (cd deeper/submodule &&
762 git log > ../../expected
763 ) &&
764 (cd .git/modules/deeper/submodule &&
765 git log > ../../../../actual
766 ) &&
767 test_cmp actual expected
768 )
769'
770
771test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
772 (cd super2 &&
773 (cd deeper/submodule &&
774 git submodule add ../submodule subsubmodule &&
775 (cd subsubmodule &&
776 git log > ../../../expected
777 ) &&
778 git commit -m "added subsubmodule" &&
779 git push origin :
780 ) &&
781 (cd .git/modules/deeper/submodule/modules/subsubmodule &&
782 git log > ../../../../../actual
783 ) &&
784 git add deeper/submodule &&
785 git commit -m "update submodule" &&
786 git push origin : &&
787 test_cmp actual expected
788 )
789'
790
791test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
792 mkdir super_update_r &&
793 (cd super_update_r &&
794 git init --bare
795 ) &&
796 mkdir subsuper_update_r &&
797 (cd subsuper_update_r &&
798 git init --bare
799 ) &&
800 mkdir subsubsuper_update_r &&
801 (cd subsubsuper_update_r &&
802 git init --bare
803 ) &&
804 git clone subsubsuper_update_r subsubsuper_update_r2 &&
805 (cd subsubsuper_update_r2 &&
806 test_commit "update_subsubsuper" file &&
807 git push origin master
808 ) &&
809 git clone subsuper_update_r subsuper_update_r2 &&
810 (cd subsuper_update_r2 &&
811 test_commit "update_subsuper" file &&
812 git submodule add ../subsubsuper_update_r subsubmodule &&
813 git commit -am "subsubmodule" &&
814 git push origin master
815 ) &&
816 git clone super_update_r super_update_r2 &&
817 (cd super_update_r2 &&
818 test_commit "update_super" file &&
819 git submodule add ../subsuper_update_r submodule &&
820 git commit -am "submodule" &&
821 git push origin master
822 ) &&
823 rm -rf super_update_r2 &&
824 git clone super_update_r super_update_r2 &&
825 (cd super_update_r2 &&
826 git submodule update --init --recursive >actual &&
827 test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
828 (cd submodule/subsubmodule &&
829 git log > ../../expected
830 ) &&
831 (cd .git/modules/submodule/modules/subsubmodule
832 git log > ../../../../../actual
833 )
834 test_cmp actual expected
835 )
836'
837
838test_expect_success 'submodule add properly re-creates deeper level submodules' '
839 (cd super &&
840 git reset --hard master &&
841 rm -rf deeper/ &&
842 git submodule add --force ../submodule deeper/submodule
843 )
844'
845
846test_expect_success 'submodule update properly revives a moved submodule' '
847 (cd super &&
848 H=$(git rev-parse --short HEAD) &&
849 git commit -am "pre move" &&
850 H2=$(git rev-parse --short HEAD) &&
851 git status | sed "s/$H/XXX/" >expect &&
852 H=$(cd submodule2; git rev-parse HEAD) &&
853 git rm --cached submodule2 &&
854 rm -rf submodule2 &&
855 mkdir -p "moved/sub module" &&
856 git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
857 git config -f .gitmodules submodule.submodule2.path "moved/sub module"
858 git commit -am "post move" &&
859 git submodule update &&
860 git status | sed "s/$H2/XXX/" >actual &&
861 test_cmp expect actual
862 )
863'
864
865test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
866 mkdir -p linked/dir &&
867 ln -s linked/dir linkto &&
868 (cd linkto &&
869 git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
870 (cd super &&
871 git submodule update --init --recursive
872 )
873 )
874'
875
876test_expect_success 'submodule update clone shallow submodule' '
877 test_when_finished "rm -rf super3" &&
878 first=$(git -C cloned submodule status submodule |cut -c2-41) &&
879 second=$(git -C submodule rev-parse HEAD) &&
880 commit_count=$(git -C submodule rev-list --count $first^..$second) &&
881 git clone cloned super3 &&
882 pwd=$(pwd) &&
883 (
884 cd super3 &&
885 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
886 mv -f .gitmodules.tmp .gitmodules &&
887 git submodule update --init --depth=$commit_count &&
888 test 1 = $(git -C submodule log --oneline | wc -l)
889 )
890'
891
892test_expect_success 'submodule update clone shallow submodule outside of depth' '
893 test_when_finished "rm -rf super3" &&
894 git clone cloned super3 &&
895 pwd=$(pwd) &&
896 (
897 cd super3 &&
898 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
899 mv -f .gitmodules.tmp .gitmodules &&
900 test_must_fail git submodule update --init --depth=1 2>actual &&
901 test_i18ngrep "Direct fetching of that commit failed." actual &&
902 git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
903 git submodule update --init --depth=1 >actual &&
904 test 1 = $(git -C submodule log --oneline | wc -l)
905 )
906'
907
908test_expect_success 'submodule update --recursive drops module name before recursing' '
909 (cd super2 &&
910 (cd deeper/submodule/subsubmodule &&
911 git checkout HEAD^
912 ) &&
913 git submodule update --recursive deeper/submodule >actual &&
914 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
915 )
916'
917
918test_expect_success 'submodule update can be run in parallel' '
919 (cd super2 &&
920 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
921 grep "7 tasks" trace.out &&
922 git config submodule.fetchJobs 8 &&
923 GIT_TRACE=$(pwd)/trace.out git submodule update &&
924 grep "8 tasks" trace.out &&
925 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
926 grep "9 tasks" trace.out
927 )
928'
929
930test_expect_success 'git clone passes the parallel jobs config on to submodules' '
931 test_when_finished "rm -rf super4" &&
932 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
933 grep "7 tasks" trace.out &&
934 rm -rf super4 &&
935 git config --global submodule.fetchJobs 8 &&
936 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
937 grep "8 tasks" trace.out &&
938 rm -rf super4 &&
939 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
940 grep "9 tasks" trace.out &&
941 rm -rf super4
942'
943
944test_done