t/gpg: simplify test for unknown key
[git/debian.git] / t / t5526-fetch-submodules.sh
blob2dc75b80db80964a6bcdbc3977be98f815b40dd0
1 #!/bin/sh
2 # Copyright (c) 2010, Jens Lehmann
4 test_description='Recursive "git fetch" for submodules'
6 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
7 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
10 export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
12 . ./test-lib.sh
14 pwd=$(pwd)
16 add_upstream_commit() {
18 cd submodule &&
19 head1=$(git rev-parse --short HEAD) &&
20 echo new >> subfile &&
21 test_tick &&
22 git add subfile &&
23 git commit -m new subfile &&
24 head2=$(git rev-parse --short HEAD) &&
25 echo "Fetching submodule submodule" > ../expect.err &&
26 echo "From $pwd/submodule" >> ../expect.err &&
27 echo " $head1..$head2 sub -> origin/sub" >> ../expect.err
28 ) &&
30 cd deepsubmodule &&
31 head1=$(git rev-parse --short HEAD) &&
32 echo new >> deepsubfile &&
33 test_tick &&
34 git add deepsubfile &&
35 git commit -m new deepsubfile &&
36 head2=$(git rev-parse --short HEAD) &&
37 echo "Fetching submodule submodule/subdir/deepsubmodule" >> ../expect.err
38 echo "From $pwd/deepsubmodule" >> ../expect.err &&
39 echo " $head1..$head2 deep -> origin/deep" >> ../expect.err
43 test_expect_success setup '
44 mkdir deepsubmodule &&
46 cd deepsubmodule &&
47 git init &&
48 echo deepsubcontent > deepsubfile &&
49 git add deepsubfile &&
50 git commit -m new deepsubfile &&
51 git branch -M deep
52 ) &&
53 mkdir submodule &&
55 cd submodule &&
56 git init &&
57 echo subcontent > subfile &&
58 git add subfile &&
59 git submodule add "$pwd/deepsubmodule" subdir/deepsubmodule &&
60 git commit -a -m new &&
61 git branch -M sub
62 ) &&
63 git submodule add "$pwd/submodule" submodule &&
64 git commit -am initial &&
65 git branch -M super &&
66 git clone . downstream &&
68 cd downstream &&
69 git submodule update --init --recursive
73 test_expect_success "fetch --recurse-submodules recurses into submodules" '
74 add_upstream_commit &&
76 cd downstream &&
77 git fetch --recurse-submodules >../actual.out 2>../actual.err
78 ) &&
79 test_must_be_empty actual.out &&
80 test_cmp expect.err actual.err
83 test_expect_success "submodule.recurse option triggers recursive fetch" '
84 add_upstream_commit &&
86 cd downstream &&
87 git -c submodule.recurse fetch >../actual.out 2>../actual.err
88 ) &&
89 test_must_be_empty actual.out &&
90 test_cmp expect.err actual.err
93 test_expect_success "fetch --recurse-submodules -j2 has the same output behaviour" '
94 add_upstream_commit &&
96 cd downstream &&
97 GIT_TRACE="$TRASH_DIRECTORY/trace.out" git fetch --recurse-submodules -j2 2>../actual.err
98 ) &&
99 test_must_be_empty actual.out &&
100 test_cmp expect.err actual.err &&
101 grep "2 tasks" trace.out
104 test_expect_success "fetch alone only fetches superproject" '
105 add_upstream_commit &&
107 cd downstream &&
108 git fetch >../actual.out 2>../actual.err
109 ) &&
110 test_must_be_empty actual.out &&
111 test_must_be_empty actual.err
114 test_expect_success "fetch --no-recurse-submodules only fetches superproject" '
116 cd downstream &&
117 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
118 ) &&
119 test_must_be_empty actual.out &&
120 test_must_be_empty actual.err
123 test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
125 cd downstream &&
126 git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
127 git fetch >../actual.out 2>../actual.err
128 ) &&
129 test_must_be_empty actual.out &&
130 test_cmp expect.err actual.err
133 test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
134 add_upstream_commit &&
136 cd downstream &&
137 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
138 ) &&
139 test_must_be_empty actual.out &&
140 test_must_be_empty actual.err
143 test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
145 cd downstream &&
146 git config submodule.submodule.fetchRecurseSubmodules false &&
147 git fetch >../actual.out 2>../actual.err
148 ) &&
149 test_must_be_empty actual.out &&
150 test_must_be_empty actual.err
153 test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
155 cd downstream &&
156 git fetch --recurse-submodules >../actual.out 2>../actual.err &&
157 git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
158 git config --unset submodule.submodule.fetchRecurseSubmodules
159 ) &&
160 test_must_be_empty actual.out &&
161 test_cmp expect.err actual.err
164 test_expect_success "--quiet propagates to submodules" '
166 cd downstream &&
167 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
168 ) &&
169 test_must_be_empty actual.out &&
170 test_must_be_empty actual.err
173 test_expect_success "--quiet propagates to parallel submodules" '
175 cd downstream &&
176 git fetch --recurse-submodules -j 2 --quiet >../actual.out 2>../actual.err
177 ) &&
178 test_must_be_empty actual.out &&
179 test_must_be_empty actual.err
182 test_expect_success "--dry-run propagates to submodules" '
183 add_upstream_commit &&
185 cd downstream &&
186 git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
187 ) &&
188 test_must_be_empty actual.out &&
189 test_cmp expect.err actual.err
192 test_expect_success "Without --dry-run propagates to submodules" '
194 cd downstream &&
195 git fetch --recurse-submodules >../actual.out 2>../actual.err
196 ) &&
197 test_must_be_empty actual.out &&
198 test_cmp expect.err actual.err
201 test_expect_success "recurseSubmodules=true propagates into submodules" '
202 add_upstream_commit &&
204 cd downstream &&
205 git config fetch.recurseSubmodules true &&
206 git fetch >../actual.out 2>../actual.err
207 ) &&
208 test_must_be_empty actual.out &&
209 test_cmp expect.err actual.err
212 test_expect_success "--recurse-submodules overrides config in submodule" '
213 add_upstream_commit &&
215 cd downstream &&
217 cd submodule &&
218 git config fetch.recurseSubmodules false
219 ) &&
220 git fetch --recurse-submodules >../actual.out 2>../actual.err
221 ) &&
222 test_must_be_empty actual.out &&
223 test_cmp expect.err actual.err
226 test_expect_success "--no-recurse-submodules overrides config setting" '
227 add_upstream_commit &&
229 cd downstream &&
230 git config fetch.recurseSubmodules true &&
231 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
232 ) &&
233 test_must_be_empty actual.out &&
234 test_must_be_empty actual.err
237 test_expect_success "Recursion doesn't happen when no new commits are fetched in the superproject" '
239 cd downstream &&
241 cd submodule &&
242 git config --unset fetch.recurseSubmodules
243 ) &&
244 git config --unset fetch.recurseSubmodules &&
245 git fetch >../actual.out 2>../actual.err
246 ) &&
247 test_must_be_empty actual.out &&
248 test_must_be_empty actual.err
251 test_expect_success "Recursion stops when no new submodule commits are fetched" '
252 head1=$(git rev-parse --short HEAD) &&
253 git add submodule &&
254 git commit -m "new submodule" &&
255 head2=$(git rev-parse --short HEAD) &&
256 echo "From $pwd/." > expect.err.sub &&
257 echo " $head1..$head2 super -> origin/super" >>expect.err.sub &&
258 head -3 expect.err >> expect.err.sub &&
260 cd downstream &&
261 git fetch >../actual.out 2>../actual.err
262 ) &&
263 test_cmp expect.err.sub actual.err &&
264 test_must_be_empty actual.out
267 test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
268 add_upstream_commit &&
269 head1=$(git rev-parse --short HEAD) &&
270 echo a > file &&
271 git add file &&
272 git commit -m "new file" &&
273 head2=$(git rev-parse --short HEAD) &&
274 echo "From $pwd/." > expect.err.file &&
275 echo " $head1..$head2 super -> origin/super" >> expect.err.file &&
277 cd downstream &&
278 git fetch >../actual.out 2>../actual.err
279 ) &&
280 test_must_be_empty actual.out &&
281 test_cmp expect.err.file actual.err
284 test_expect_success "Recursion picks up config in submodule" '
286 cd downstream &&
287 git fetch --recurse-submodules &&
289 cd submodule &&
290 git config fetch.recurseSubmodules true
292 ) &&
293 add_upstream_commit &&
294 head1=$(git rev-parse --short HEAD) &&
295 git add submodule &&
296 git commit -m "new submodule" &&
297 head2=$(git rev-parse --short HEAD) &&
298 echo "From $pwd/." > expect.err.sub &&
299 echo " $head1..$head2 super -> origin/super" >> expect.err.sub &&
300 cat expect.err >> expect.err.sub &&
302 cd downstream &&
303 git fetch >../actual.out 2>../actual.err &&
305 cd submodule &&
306 git config --unset fetch.recurseSubmodules
308 ) &&
309 test_cmp expect.err.sub actual.err &&
310 test_must_be_empty actual.out
313 test_expect_success "Recursion picks up all submodules when necessary" '
314 add_upstream_commit &&
316 cd submodule &&
318 cd subdir/deepsubmodule &&
319 git fetch &&
320 git checkout -q FETCH_HEAD
321 ) &&
322 head1=$(git rev-parse --short HEAD^) &&
323 git add subdir/deepsubmodule &&
324 git commit -m "new deepsubmodule" &&
325 head2=$(git rev-parse --short HEAD) &&
326 echo "Fetching submodule submodule" > ../expect.err.sub &&
327 echo "From $pwd/submodule" >> ../expect.err.sub &&
328 echo " $head1..$head2 sub -> origin/sub" >> ../expect.err.sub
329 ) &&
330 head1=$(git rev-parse --short HEAD) &&
331 git add submodule &&
332 git commit -m "new submodule" &&
333 head2=$(git rev-parse --short HEAD) &&
334 echo "From $pwd/." > expect.err.2 &&
335 echo " $head1..$head2 super -> origin/super" >> expect.err.2 &&
336 cat expect.err.sub >> expect.err.2 &&
337 tail -3 expect.err >> expect.err.2 &&
339 cd downstream &&
340 git fetch >../actual.out 2>../actual.err
341 ) &&
342 test_cmp expect.err.2 actual.err &&
343 test_must_be_empty actual.out
346 test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
347 add_upstream_commit &&
349 cd submodule &&
351 cd subdir/deepsubmodule &&
352 git fetch &&
353 git checkout -q FETCH_HEAD
354 ) &&
355 head1=$(git rev-parse --short HEAD^) &&
356 git add subdir/deepsubmodule &&
357 git commit -m "new deepsubmodule" &&
358 head2=$(git rev-parse --short HEAD) &&
359 echo Fetching submodule submodule > ../expect.err.sub &&
360 echo "From $pwd/submodule" >> ../expect.err.sub &&
361 echo " $head1..$head2 sub -> origin/sub" >> ../expect.err.sub
362 ) &&
364 cd downstream &&
365 git config fetch.recurseSubmodules true &&
366 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
367 git config --unset fetch.recurseSubmodules
368 ) &&
369 test_must_be_empty actual.out &&
370 test_must_be_empty actual.err
373 test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
374 head1=$(git rev-parse --short HEAD) &&
375 git add submodule &&
376 git commit -m "new submodule" &&
377 head2=$(git rev-parse --short HEAD) &&
378 tail -3 expect.err > expect.err.deepsub &&
379 echo "From $pwd/." > expect.err &&
380 echo " $head1..$head2 super -> origin/super" >>expect.err &&
381 cat expect.err.sub >> expect.err &&
382 cat expect.err.deepsub >> expect.err &&
384 cd downstream &&
385 git config fetch.recurseSubmodules false &&
387 cd submodule &&
388 git config -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive false
389 ) &&
390 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
391 git config --unset fetch.recurseSubmodules &&
393 cd submodule &&
394 git config --unset -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive
396 ) &&
397 test_must_be_empty actual.out &&
398 test_cmp expect.err actual.err
401 test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
402 add_upstream_commit &&
403 head1=$(git rev-parse --short HEAD) &&
404 echo a >> file &&
405 git add file &&
406 git commit -m "new file" &&
407 head2=$(git rev-parse --short HEAD) &&
408 echo "From $pwd/." > expect.err.file &&
409 echo " $head1..$head2 super -> origin/super" >> expect.err.file &&
411 cd downstream &&
412 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
413 ) &&
414 test_must_be_empty actual.out &&
415 test_cmp expect.err.file actual.err
418 test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" '
420 cd downstream &&
421 git fetch --recurse-submodules
422 ) &&
423 add_upstream_commit &&
424 git config --global fetch.recurseSubmodules false &&
425 head1=$(git rev-parse --short HEAD) &&
426 git add submodule &&
427 git commit -m "new submodule" &&
428 head2=$(git rev-parse --short HEAD) &&
429 echo "From $pwd/." > expect.err.2 &&
430 echo " $head1..$head2 super -> origin/super" >>expect.err.2 &&
431 head -3 expect.err >> expect.err.2 &&
433 cd downstream &&
434 git config fetch.recurseSubmodules on-demand &&
435 git fetch >../actual.out 2>../actual.err
436 ) &&
437 git config --global --unset fetch.recurseSubmodules &&
439 cd downstream &&
440 git config --unset fetch.recurseSubmodules
441 ) &&
442 test_must_be_empty actual.out &&
443 test_cmp expect.err.2 actual.err
446 test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
448 cd downstream &&
449 git fetch --recurse-submodules
450 ) &&
451 add_upstream_commit &&
452 git config fetch.recurseSubmodules false &&
453 head1=$(git rev-parse --short HEAD) &&
454 git add submodule &&
455 git commit -m "new submodule" &&
456 head2=$(git rev-parse --short HEAD) &&
457 echo "From $pwd/." > expect.err.2 &&
458 echo " $head1..$head2 super -> origin/super" >>expect.err.2 &&
459 head -3 expect.err >> expect.err.2 &&
461 cd downstream &&
462 git config submodule.submodule.fetchRecurseSubmodules on-demand &&
463 git fetch >../actual.out 2>../actual.err
464 ) &&
465 git config --unset fetch.recurseSubmodules &&
467 cd downstream &&
468 git config --unset submodule.submodule.fetchRecurseSubmodules
469 ) &&
470 test_must_be_empty actual.out &&
471 test_cmp expect.err.2 actual.err
474 test_expect_success "don't fetch submodule when newly recorded commits are already present" '
476 cd submodule &&
477 git checkout -q HEAD^^
478 ) &&
479 head1=$(git rev-parse --short HEAD) &&
480 git add submodule &&
481 git commit -m "submodule rewound" &&
482 head2=$(git rev-parse --short HEAD) &&
483 echo "From $pwd/." > expect.err &&
484 echo " $head1..$head2 super -> origin/super" >> expect.err &&
486 cd downstream &&
487 git fetch >../actual.out 2>../actual.err
488 ) &&
489 test_must_be_empty actual.out &&
490 test_cmp expect.err actual.err &&
492 cd submodule &&
493 git checkout -q sub
497 test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .gitmodules entry" '
499 cd downstream &&
500 git fetch --recurse-submodules
501 ) &&
502 add_upstream_commit &&
503 head1=$(git rev-parse --short HEAD) &&
504 git add submodule &&
505 git rm .gitmodules &&
506 git commit -m "new submodule without .gitmodules" &&
507 head2=$(git rev-parse --short HEAD) &&
508 echo "From $pwd/." >expect.err.2 &&
509 echo " $head1..$head2 super -> origin/super" >>expect.err.2 &&
510 head -3 expect.err >>expect.err.2 &&
512 cd downstream &&
513 rm .gitmodules &&
514 git config fetch.recurseSubmodules on-demand &&
515 # fake submodule configuration to avoid skipping submodule handling
516 git config -f .gitmodules submodule.fake.path fake &&
517 git config -f .gitmodules submodule.fake.url fakeurl &&
518 git add .gitmodules &&
519 git config --unset submodule.submodule.url &&
520 git fetch >../actual.out 2>../actual.err &&
521 # cleanup
522 git config --unset fetch.recurseSubmodules &&
523 git reset --hard
524 ) &&
525 test_must_be_empty actual.out &&
526 test_cmp expect.err.2 actual.err &&
527 git checkout HEAD^ -- .gitmodules &&
528 git add .gitmodules &&
529 git commit -m "new submodule restored .gitmodules"
532 test_expect_success 'fetching submodules respects parallel settings' '
533 git config fetch.recurseSubmodules true &&
535 cd downstream &&
536 GIT_TRACE=$(pwd)/trace.out git fetch &&
537 grep "1 tasks" trace.out &&
538 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
539 grep "7 tasks" trace.out &&
540 git config submodule.fetchJobs 8 &&
541 GIT_TRACE=$(pwd)/trace.out git fetch &&
542 grep "8 tasks" trace.out &&
543 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
544 grep "9 tasks" trace.out
548 test_expect_success 'fetching submodule into a broken repository' '
549 # Prepare src and src/sub nested in it
550 git init src &&
552 cd src &&
553 git init sub &&
554 git -C sub commit --allow-empty -m "initial in sub" &&
555 git submodule add -- ./sub sub &&
556 git commit -m "initial in top"
557 ) &&
559 # Clone the old-fashoned way
560 git clone src dst &&
561 git -C dst clone ../src/sub sub &&
563 # Make sure that old-fashoned layout is still supported
564 git -C dst status &&
566 # "diff" would find no change
567 git -C dst diff --exit-code &&
569 # Recursive-fetch works fine
570 git -C dst fetch --recurse-submodules &&
572 # Break the receiving submodule
573 rm -f dst/sub/.git/HEAD &&
575 # NOTE: without the fix the following tests will recurse forever!
576 # They should terminate with an error.
578 test_must_fail git -C dst status &&
579 test_must_fail git -C dst diff &&
580 test_must_fail git -C dst fetch --recurse-submodules
583 test_expect_success "fetch new commits when submodule got renamed" '
584 git clone . downstream_rename &&
586 cd downstream_rename &&
587 git submodule update --init --recursive &&
588 git checkout -b rename &&
589 git mv submodule submodule_renamed &&
591 cd submodule_renamed &&
592 git checkout -b rename_sub &&
593 echo a >a &&
594 git add a &&
595 git commit -ma &&
596 git push origin rename_sub &&
597 git rev-parse HEAD >../../expect
598 ) &&
599 git add submodule_renamed &&
600 git commit -m "update renamed submodule" &&
601 git push origin rename
602 ) &&
604 cd downstream &&
605 git fetch --recurse-submodules=on-demand &&
607 cd submodule &&
608 git rev-parse origin/rename_sub >../../actual
610 ) &&
611 test_cmp expect actual
614 test_expect_success "fetch new submodule commits on-demand outside standard refspec" '
615 # add a second submodule and ensure it is around in downstream first
616 git clone submodule sub1 &&
617 git submodule add ./sub1 &&
618 git commit -m "adding a second submodule" &&
619 git -C downstream pull &&
620 git -C downstream submodule update --init --recursive &&
622 git checkout --detach &&
624 C=$(git -C submodule commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
625 git -C submodule update-ref refs/changes/1 $C &&
626 git update-index --cacheinfo 160000 $C submodule &&
627 test_tick &&
629 D=$(git -C sub1 commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
630 git -C sub1 update-ref refs/changes/2 $D &&
631 git update-index --cacheinfo 160000 $D sub1 &&
633 git commit -m "updated submodules outside of refs/heads" &&
634 E=$(git rev-parse HEAD) &&
635 git update-ref refs/changes/3 $E &&
637 cd downstream &&
638 git fetch --recurse-submodules origin refs/changes/3:refs/heads/my_branch &&
639 git -C submodule cat-file -t $C &&
640 git -C sub1 cat-file -t $D &&
641 git checkout --recurse-submodules FETCH_HEAD
645 test_expect_success 'fetch new submodule commit on-demand in FETCH_HEAD' '
646 # depends on the previous test for setup
648 C=$(git -C submodule commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
649 git -C submodule update-ref refs/changes/4 $C &&
650 git update-index --cacheinfo 160000 $C submodule &&
651 test_tick &&
653 D=$(git -C sub1 commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
654 git -C sub1 update-ref refs/changes/5 $D &&
655 git update-index --cacheinfo 160000 $D sub1 &&
657 git commit -m "updated submodules outside of refs/heads" &&
658 E=$(git rev-parse HEAD) &&
659 git update-ref refs/changes/6 $E &&
661 cd downstream &&
662 git fetch --recurse-submodules origin refs/changes/6 &&
663 git -C submodule cat-file -t $C &&
664 git -C sub1 cat-file -t $D &&
665 git checkout --recurse-submodules FETCH_HEAD
669 test_expect_success 'fetch new submodule commits on-demand without .gitmodules entry' '
670 # depends on the previous test for setup
672 git config -f .gitmodules --remove-section submodule.sub1 &&
673 git add .gitmodules &&
674 git commit -m "delete gitmodules file" &&
675 git checkout -B super &&
676 git -C downstream fetch &&
677 git -C downstream checkout origin/super &&
679 C=$(git -C submodule commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
680 git -C submodule update-ref refs/changes/7 $C &&
681 git update-index --cacheinfo 160000 $C submodule &&
682 test_tick &&
684 D=$(git -C sub1 commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
685 git -C sub1 update-ref refs/changes/8 $D &&
686 git update-index --cacheinfo 160000 $D sub1 &&
688 git commit -m "updated submodules outside of refs/heads" &&
689 E=$(git rev-parse HEAD) &&
690 git update-ref refs/changes/9 $E &&
692 cd downstream &&
693 git fetch --recurse-submodules origin refs/changes/9 &&
694 git -C submodule cat-file -t $C &&
695 git -C sub1 cat-file -t $D &&
696 git checkout --recurse-submodules FETCH_HEAD
700 test_expect_success 'fetch new submodule commit intermittently referenced by superproject' '
701 # depends on the previous test for setup
703 D=$(git -C sub1 commit-tree -m "change 10 outside refs/heads" HEAD^{tree}) &&
704 E=$(git -C sub1 commit-tree -m "change 11 outside refs/heads" HEAD^{tree}) &&
705 F=$(git -C sub1 commit-tree -m "change 12 outside refs/heads" HEAD^{tree}) &&
707 git -C sub1 update-ref refs/changes/10 $D &&
708 git update-index --cacheinfo 160000 $D sub1 &&
709 git commit -m "updated submodules outside of refs/heads" &&
711 git -C sub1 update-ref refs/changes/11 $E &&
712 git update-index --cacheinfo 160000 $E sub1 &&
713 git commit -m "updated submodules outside of refs/heads" &&
715 git -C sub1 update-ref refs/changes/12 $F &&
716 git update-index --cacheinfo 160000 $F sub1 &&
717 git commit -m "updated submodules outside of refs/heads" &&
719 G=$(git rev-parse HEAD) &&
720 git update-ref refs/changes/13 $G &&
722 cd downstream &&
723 git fetch --recurse-submodules origin refs/changes/13 &&
725 git -C sub1 cat-file -t $D &&
726 git -C sub1 cat-file -t $E &&
727 git -C sub1 cat-file -t $F
731 add_commit_push () {
732 dir="$1" &&
733 msg="$2" &&
734 shift 2 &&
735 git -C "$dir" add "$@" &&
736 git -C "$dir" commit -a -m "$msg" &&
737 git -C "$dir" push
740 compare_refs_in_dir () {
741 fail= &&
742 if test "x$1" = 'x!'
743 then
744 fail='!' &&
745 shift
746 fi &&
747 git -C "$1" rev-parse --verify "$2" >expect &&
748 git -C "$3" rev-parse --verify "$4" >actual &&
749 eval $fail test_cmp expect actual
753 test_expect_success 'setup nested submodule fetch test' '
754 # does not depend on any previous test setups
756 for repo in outer middle inner
758 git init --bare $repo &&
759 git clone $repo ${repo}_content &&
760 echo "$repo" >"${repo}_content/file" &&
761 add_commit_push ${repo}_content "initial" file ||
762 return 1
763 done &&
765 git clone outer A &&
766 git -C A submodule add "$pwd/middle" &&
767 git -C A/middle/ submodule add "$pwd/inner" &&
768 add_commit_push A/middle/ "adding inner sub" .gitmodules inner &&
769 add_commit_push A/ "adding middle sub" .gitmodules middle &&
771 git clone outer B &&
772 git -C B/ submodule update --init middle &&
774 compare_refs_in_dir A HEAD B HEAD &&
775 compare_refs_in_dir A/middle HEAD B/middle HEAD &&
776 test_path_is_file B/file &&
777 test_path_is_file B/middle/file &&
778 test_path_is_missing B/middle/inner/file &&
780 echo "change on inner repo of A" >"A/middle/inner/file" &&
781 add_commit_push A/middle/inner "change on inner" file &&
782 add_commit_push A/middle "change on inner" inner &&
783 add_commit_push A "change on inner" middle
786 test_expect_success 'fetching a superproject containing an uninitialized sub/sub project' '
787 # depends on previous test for setup
789 git -C B/ fetch &&
790 compare_refs_in_dir A origin/HEAD B origin/HEAD
793 fetch_with_recursion_abort () {
794 # In a regression the following git call will run into infinite recursion.
795 # To handle that, we connect the sed command to the git call by a pipe
796 # so that sed can kill the infinite recursion when detected.
797 # The recursion creates git output like:
798 # Fetching submodule sub
799 # Fetching submodule sub/sub <-- [1]
800 # Fetching submodule sub/sub/sub
801 # ...
802 # [1] sed will stop reading and cause git to eventually stop and die
804 git -C "$1" fetch --recurse-submodules 2>&1 |
805 sed "/Fetching submodule $2[^$]/q" >out &&
806 ! grep "Fetching submodule $2[^$]" out
809 test_expect_success 'setup recursive fetch with uninit submodule' '
810 # does not depend on any previous test setups
812 test_create_repo super &&
813 test_commit -C super initial &&
814 test_create_repo sub &&
815 test_commit -C sub initial &&
816 git -C sub rev-parse HEAD >expect &&
818 git -C super submodule add ../sub &&
819 git -C super commit -m "add sub" &&
821 git clone super superclone &&
822 git -C superclone submodule status >out &&
823 sed -e "s/^-//" -e "s/ sub.*$//" out >actual &&
824 test_cmp expect actual
827 test_expect_success 'recursive fetch with uninit submodule' '
828 # depends on previous test for setup
830 fetch_with_recursion_abort superclone sub &&
831 git -C superclone submodule status >out &&
832 sed -e "s/^-//" -e "s/ sub$//" out >actual &&
833 test_cmp expect actual
836 test_expect_success 'recursive fetch after deinit a submodule' '
837 # depends on previous test for setup
839 git -C superclone submodule update --init sub &&
840 git -C superclone submodule deinit -f sub &&
842 fetch_with_recursion_abort superclone sub &&
843 git -C superclone submodule status >out &&
844 sed -e "s/^-//" -e "s/ sub$//" out >actual &&
845 test_cmp expect actual
848 test_done