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