]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5526-fetch-submodules.sh
Sync with 2.33.5
[thirdparty/git.git] / t / t5526-fetch-submodules.sh
1 #!/bin/sh
2 # Copyright (c) 2010, Jens Lehmann
3
4 test_description='Recursive "git fetch" for submodules'
5
6 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
7 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8
9 GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
10 export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
11
12 . ./test-lib.sh
13
14 pwd=$(pwd)
15
16 add_upstream_commit() {
17 (
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 ) &&
29 (
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
40 )
41 }
42
43 test_expect_success setup '
44 git config --global protocol.file.allow always &&
45 mkdir deepsubmodule &&
46 (
47 cd deepsubmodule &&
48 git init &&
49 echo deepsubcontent > deepsubfile &&
50 git add deepsubfile &&
51 git commit -m new deepsubfile &&
52 git branch -M deep
53 ) &&
54 mkdir submodule &&
55 (
56 cd submodule &&
57 git init &&
58 echo subcontent > subfile &&
59 git add subfile &&
60 git submodule add "$pwd/deepsubmodule" subdir/deepsubmodule &&
61 git commit -a -m new &&
62 git branch -M sub
63 ) &&
64 git submodule add "$pwd/submodule" submodule &&
65 git commit -am initial &&
66 git branch -M super &&
67 git clone . downstream &&
68 (
69 cd downstream &&
70 git submodule update --init --recursive
71 )
72 '
73
74 test_expect_success "fetch --recurse-submodules recurses into submodules" '
75 add_upstream_commit &&
76 (
77 cd downstream &&
78 git fetch --recurse-submodules >../actual.out 2>../actual.err
79 ) &&
80 test_must_be_empty actual.out &&
81 test_cmp expect.err actual.err
82 '
83
84 test_expect_success "submodule.recurse option triggers recursive fetch" '
85 add_upstream_commit &&
86 (
87 cd downstream &&
88 git -c submodule.recurse fetch >../actual.out 2>../actual.err
89 ) &&
90 test_must_be_empty actual.out &&
91 test_cmp expect.err actual.err
92 '
93
94 test_expect_success "fetch --recurse-submodules -j2 has the same output behaviour" '
95 add_upstream_commit &&
96 (
97 cd downstream &&
98 GIT_TRACE="$TRASH_DIRECTORY/trace.out" git fetch --recurse-submodules -j2 2>../actual.err
99 ) &&
100 test_must_be_empty actual.out &&
101 test_cmp expect.err actual.err &&
102 grep "2 tasks" trace.out
103 '
104
105 test_expect_success "fetch alone only fetches superproject" '
106 add_upstream_commit &&
107 (
108 cd downstream &&
109 git fetch >../actual.out 2>../actual.err
110 ) &&
111 test_must_be_empty actual.out &&
112 test_must_be_empty actual.err
113 '
114
115 test_expect_success "fetch --no-recurse-submodules only fetches superproject" '
116 (
117 cd downstream &&
118 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
119 ) &&
120 test_must_be_empty actual.out &&
121 test_must_be_empty actual.err
122 '
123
124 test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
125 (
126 cd downstream &&
127 git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
128 git fetch >../actual.out 2>../actual.err
129 ) &&
130 test_must_be_empty actual.out &&
131 test_cmp expect.err actual.err
132 '
133
134 test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
135 add_upstream_commit &&
136 (
137 cd downstream &&
138 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
139 ) &&
140 test_must_be_empty actual.out &&
141 test_must_be_empty actual.err
142 '
143
144 test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
145 (
146 cd downstream &&
147 git config submodule.submodule.fetchRecurseSubmodules false &&
148 git fetch >../actual.out 2>../actual.err
149 ) &&
150 test_must_be_empty actual.out &&
151 test_must_be_empty actual.err
152 '
153
154 test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
155 (
156 cd downstream &&
157 git fetch --recurse-submodules >../actual.out 2>../actual.err &&
158 git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
159 git config --unset submodule.submodule.fetchRecurseSubmodules
160 ) &&
161 test_must_be_empty actual.out &&
162 test_cmp expect.err actual.err
163 '
164
165 test_expect_success "--quiet propagates to submodules" '
166 (
167 cd downstream &&
168 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
169 ) &&
170 test_must_be_empty actual.out &&
171 test_must_be_empty actual.err
172 '
173
174 test_expect_success "--quiet propagates to parallel submodules" '
175 (
176 cd downstream &&
177 git fetch --recurse-submodules -j 2 --quiet >../actual.out 2>../actual.err
178 ) &&
179 test_must_be_empty actual.out &&
180 test_must_be_empty actual.err
181 '
182
183 test_expect_success "--dry-run propagates to submodules" '
184 add_upstream_commit &&
185 (
186 cd downstream &&
187 git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
188 ) &&
189 test_must_be_empty actual.out &&
190 test_cmp expect.err actual.err
191 '
192
193 test_expect_success "Without --dry-run propagates to submodules" '
194 (
195 cd downstream &&
196 git fetch --recurse-submodules >../actual.out 2>../actual.err
197 ) &&
198 test_must_be_empty actual.out &&
199 test_cmp expect.err actual.err
200 '
201
202 test_expect_success "recurseSubmodules=true propagates into submodules" '
203 add_upstream_commit &&
204 (
205 cd downstream &&
206 git config fetch.recurseSubmodules true &&
207 git fetch >../actual.out 2>../actual.err
208 ) &&
209 test_must_be_empty actual.out &&
210 test_cmp expect.err actual.err
211 '
212
213 test_expect_success "--recurse-submodules overrides config in submodule" '
214 add_upstream_commit &&
215 (
216 cd downstream &&
217 (
218 cd submodule &&
219 git config fetch.recurseSubmodules false
220 ) &&
221 git fetch --recurse-submodules >../actual.out 2>../actual.err
222 ) &&
223 test_must_be_empty actual.out &&
224 test_cmp expect.err actual.err
225 '
226
227 test_expect_success "--no-recurse-submodules overrides config setting" '
228 add_upstream_commit &&
229 (
230 cd downstream &&
231 git config fetch.recurseSubmodules true &&
232 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
233 ) &&
234 test_must_be_empty actual.out &&
235 test_must_be_empty actual.err
236 '
237
238 test_expect_success "Recursion doesn't happen when no new commits are fetched in the superproject" '
239 (
240 cd downstream &&
241 (
242 cd submodule &&
243 git config --unset fetch.recurseSubmodules
244 ) &&
245 git config --unset fetch.recurseSubmodules &&
246 git fetch >../actual.out 2>../actual.err
247 ) &&
248 test_must_be_empty actual.out &&
249 test_must_be_empty actual.err
250 '
251
252 test_expect_success "Recursion stops when no new submodule commits are fetched" '
253 head1=$(git rev-parse --short HEAD) &&
254 git add submodule &&
255 git commit -m "new submodule" &&
256 head2=$(git rev-parse --short HEAD) &&
257 echo "From $pwd/." > expect.err.sub &&
258 echo " $head1..$head2 super -> origin/super" >>expect.err.sub &&
259 head -3 expect.err >> expect.err.sub &&
260 (
261 cd downstream &&
262 git fetch >../actual.out 2>../actual.err
263 ) &&
264 test_cmp expect.err.sub actual.err &&
265 test_must_be_empty actual.out
266 '
267
268 test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
269 add_upstream_commit &&
270 head1=$(git rev-parse --short HEAD) &&
271 echo a > file &&
272 git add file &&
273 git commit -m "new file" &&
274 head2=$(git rev-parse --short HEAD) &&
275 echo "From $pwd/." > expect.err.file &&
276 echo " $head1..$head2 super -> origin/super" >> expect.err.file &&
277 (
278 cd downstream &&
279 git fetch >../actual.out 2>../actual.err
280 ) &&
281 test_must_be_empty actual.out &&
282 test_cmp expect.err.file actual.err
283 '
284
285 test_expect_success "Recursion picks up config in submodule" '
286 (
287 cd downstream &&
288 git fetch --recurse-submodules &&
289 (
290 cd submodule &&
291 git config fetch.recurseSubmodules true
292 )
293 ) &&
294 add_upstream_commit &&
295 head1=$(git rev-parse --short HEAD) &&
296 git add submodule &&
297 git commit -m "new submodule" &&
298 head2=$(git rev-parse --short HEAD) &&
299 echo "From $pwd/." > expect.err.sub &&
300 echo " $head1..$head2 super -> origin/super" >> expect.err.sub &&
301 cat expect.err >> expect.err.sub &&
302 (
303 cd downstream &&
304 git fetch >../actual.out 2>../actual.err &&
305 (
306 cd submodule &&
307 git config --unset fetch.recurseSubmodules
308 )
309 ) &&
310 test_cmp expect.err.sub actual.err &&
311 test_must_be_empty actual.out
312 '
313
314 test_expect_success "Recursion picks up all submodules when necessary" '
315 add_upstream_commit &&
316 (
317 cd submodule &&
318 (
319 cd subdir/deepsubmodule &&
320 git fetch &&
321 git checkout -q FETCH_HEAD
322 ) &&
323 head1=$(git rev-parse --short HEAD^) &&
324 git add subdir/deepsubmodule &&
325 git commit -m "new deepsubmodule" &&
326 head2=$(git rev-parse --short HEAD) &&
327 echo "Fetching submodule submodule" > ../expect.err.sub &&
328 echo "From $pwd/submodule" >> ../expect.err.sub &&
329 echo " $head1..$head2 sub -> origin/sub" >> ../expect.err.sub
330 ) &&
331 head1=$(git rev-parse --short HEAD) &&
332 git add submodule &&
333 git commit -m "new submodule" &&
334 head2=$(git rev-parse --short HEAD) &&
335 echo "From $pwd/." > expect.err.2 &&
336 echo " $head1..$head2 super -> origin/super" >> expect.err.2 &&
337 cat expect.err.sub >> expect.err.2 &&
338 tail -3 expect.err >> expect.err.2 &&
339 (
340 cd downstream &&
341 git fetch >../actual.out 2>../actual.err
342 ) &&
343 test_cmp expect.err.2 actual.err &&
344 test_must_be_empty actual.out
345 '
346
347 test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
348 add_upstream_commit &&
349 (
350 cd submodule &&
351 (
352 cd subdir/deepsubmodule &&
353 git fetch &&
354 git checkout -q FETCH_HEAD
355 ) &&
356 head1=$(git rev-parse --short HEAD^) &&
357 git add subdir/deepsubmodule &&
358 git commit -m "new deepsubmodule" &&
359 head2=$(git rev-parse --short HEAD) &&
360 echo Fetching submodule submodule > ../expect.err.sub &&
361 echo "From $pwd/submodule" >> ../expect.err.sub &&
362 echo " $head1..$head2 sub -> origin/sub" >> ../expect.err.sub
363 ) &&
364 (
365 cd downstream &&
366 git config fetch.recurseSubmodules true &&
367 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
368 git config --unset fetch.recurseSubmodules
369 ) &&
370 test_must_be_empty actual.out &&
371 test_must_be_empty actual.err
372 '
373
374 test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
375 head1=$(git rev-parse --short HEAD) &&
376 git add submodule &&
377 git commit -m "new submodule" &&
378 head2=$(git rev-parse --short HEAD) &&
379 tail -3 expect.err > expect.err.deepsub &&
380 echo "From $pwd/." > expect.err &&
381 echo " $head1..$head2 super -> origin/super" >>expect.err &&
382 cat expect.err.sub >> expect.err &&
383 cat expect.err.deepsub >> expect.err &&
384 (
385 cd downstream &&
386 git config fetch.recurseSubmodules false &&
387 (
388 cd submodule &&
389 git config -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive false
390 ) &&
391 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
392 git config --unset fetch.recurseSubmodules &&
393 (
394 cd submodule &&
395 git config --unset -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive
396 )
397 ) &&
398 test_must_be_empty actual.out &&
399 test_cmp expect.err actual.err
400 '
401
402 test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
403 add_upstream_commit &&
404 head1=$(git rev-parse --short HEAD) &&
405 echo a >> file &&
406 git add file &&
407 git commit -m "new file" &&
408 head2=$(git rev-parse --short HEAD) &&
409 echo "From $pwd/." > expect.err.file &&
410 echo " $head1..$head2 super -> origin/super" >> expect.err.file &&
411 (
412 cd downstream &&
413 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
414 ) &&
415 test_must_be_empty actual.out &&
416 test_cmp expect.err.file actual.err
417 '
418
419 test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" '
420 (
421 cd downstream &&
422 git fetch --recurse-submodules
423 ) &&
424 add_upstream_commit &&
425 git config --global fetch.recurseSubmodules false &&
426 head1=$(git rev-parse --short HEAD) &&
427 git add submodule &&
428 git commit -m "new submodule" &&
429 head2=$(git rev-parse --short HEAD) &&
430 echo "From $pwd/." > expect.err.2 &&
431 echo " $head1..$head2 super -> origin/super" >>expect.err.2 &&
432 head -3 expect.err >> expect.err.2 &&
433 (
434 cd downstream &&
435 git config fetch.recurseSubmodules on-demand &&
436 git fetch >../actual.out 2>../actual.err
437 ) &&
438 git config --global --unset fetch.recurseSubmodules &&
439 (
440 cd downstream &&
441 git config --unset fetch.recurseSubmodules
442 ) &&
443 test_must_be_empty actual.out &&
444 test_cmp expect.err.2 actual.err
445 '
446
447 test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
448 (
449 cd downstream &&
450 git fetch --recurse-submodules
451 ) &&
452 add_upstream_commit &&
453 git config fetch.recurseSubmodules false &&
454 head1=$(git rev-parse --short HEAD) &&
455 git add submodule &&
456 git commit -m "new submodule" &&
457 head2=$(git rev-parse --short HEAD) &&
458 echo "From $pwd/." > expect.err.2 &&
459 echo " $head1..$head2 super -> origin/super" >>expect.err.2 &&
460 head -3 expect.err >> expect.err.2 &&
461 (
462 cd downstream &&
463 git config submodule.submodule.fetchRecurseSubmodules on-demand &&
464 git fetch >../actual.out 2>../actual.err
465 ) &&
466 git config --unset fetch.recurseSubmodules &&
467 (
468 cd downstream &&
469 git config --unset submodule.submodule.fetchRecurseSubmodules
470 ) &&
471 test_must_be_empty actual.out &&
472 test_cmp expect.err.2 actual.err
473 '
474
475 test_expect_success "don't fetch submodule when newly recorded commits are already present" '
476 (
477 cd submodule &&
478 git checkout -q HEAD^^
479 ) &&
480 head1=$(git rev-parse --short HEAD) &&
481 git add submodule &&
482 git commit -m "submodule rewound" &&
483 head2=$(git rev-parse --short HEAD) &&
484 echo "From $pwd/." > expect.err &&
485 echo " $head1..$head2 super -> origin/super" >> expect.err &&
486 (
487 cd downstream &&
488 git fetch >../actual.out 2>../actual.err
489 ) &&
490 test_must_be_empty actual.out &&
491 test_cmp expect.err actual.err &&
492 (
493 cd submodule &&
494 git checkout -q sub
495 )
496 '
497
498 test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .gitmodules entry" '
499 (
500 cd downstream &&
501 git fetch --recurse-submodules
502 ) &&
503 add_upstream_commit &&
504 head1=$(git rev-parse --short HEAD) &&
505 git add submodule &&
506 git rm .gitmodules &&
507 git commit -m "new submodule without .gitmodules" &&
508 head2=$(git rev-parse --short HEAD) &&
509 echo "From $pwd/." >expect.err.2 &&
510 echo " $head1..$head2 super -> origin/super" >>expect.err.2 &&
511 head -3 expect.err >>expect.err.2 &&
512 (
513 cd downstream &&
514 rm .gitmodules &&
515 git config fetch.recurseSubmodules on-demand &&
516 # fake submodule configuration to avoid skipping submodule handling
517 git config -f .gitmodules submodule.fake.path fake &&
518 git config -f .gitmodules submodule.fake.url fakeurl &&
519 git add .gitmodules &&
520 git config --unset submodule.submodule.url &&
521 git fetch >../actual.out 2>../actual.err &&
522 # cleanup
523 git config --unset fetch.recurseSubmodules &&
524 git reset --hard
525 ) &&
526 test_must_be_empty actual.out &&
527 test_cmp expect.err.2 actual.err &&
528 git checkout HEAD^ -- .gitmodules &&
529 git add .gitmodules &&
530 git commit -m "new submodule restored .gitmodules"
531 '
532
533 test_expect_success 'fetching submodules respects parallel settings' '
534 git config fetch.recurseSubmodules true &&
535 (
536 cd downstream &&
537 GIT_TRACE=$(pwd)/trace.out git fetch &&
538 grep "1 tasks" trace.out &&
539 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
540 grep "7 tasks" trace.out &&
541 git config submodule.fetchJobs 8 &&
542 GIT_TRACE=$(pwd)/trace.out git fetch &&
543 grep "8 tasks" trace.out &&
544 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
545 grep "9 tasks" trace.out
546 )
547 '
548
549 test_expect_success 'fetching submodule into a broken repository' '
550 # Prepare src and src/sub nested in it
551 git init src &&
552 (
553 cd src &&
554 git init sub &&
555 git -C sub commit --allow-empty -m "initial in sub" &&
556 git submodule add -- ./sub sub &&
557 git commit -m "initial in top"
558 ) &&
559
560 # Clone the old-fashoned way
561 git clone src dst &&
562 git -C dst clone ../src/sub sub &&
563
564 # Make sure that old-fashoned layout is still supported
565 git -C dst status &&
566
567 # "diff" would find no change
568 git -C dst diff --exit-code &&
569
570 # Recursive-fetch works fine
571 git -C dst fetch --recurse-submodules &&
572
573 # Break the receiving submodule
574 rm -f dst/sub/.git/HEAD &&
575
576 # NOTE: without the fix the following tests will recurse forever!
577 # They should terminate with an error.
578
579 test_must_fail git -C dst status &&
580 test_must_fail git -C dst diff &&
581 test_must_fail git -C dst fetch --recurse-submodules
582 '
583
584 test_expect_success "fetch new commits when submodule got renamed" '
585 git clone . downstream_rename &&
586 (
587 cd downstream_rename &&
588 git submodule update --init --recursive &&
589 git checkout -b rename &&
590 git mv submodule submodule_renamed &&
591 (
592 cd submodule_renamed &&
593 git checkout -b rename_sub &&
594 echo a >a &&
595 git add a &&
596 git commit -ma &&
597 git push origin rename_sub &&
598 git rev-parse HEAD >../../expect
599 ) &&
600 git add submodule_renamed &&
601 git commit -m "update renamed submodule" &&
602 git push origin rename
603 ) &&
604 (
605 cd downstream &&
606 git fetch --recurse-submodules=on-demand &&
607 (
608 cd submodule &&
609 git rev-parse origin/rename_sub >../../actual
610 )
611 ) &&
612 test_cmp expect actual
613 '
614
615 test_expect_success "fetch new submodule commits on-demand outside standard refspec" '
616 # add a second submodule and ensure it is around in downstream first
617 git clone submodule sub1 &&
618 git submodule add ./sub1 &&
619 git commit -m "adding a second submodule" &&
620 git -C downstream pull &&
621 git -C downstream submodule update --init --recursive &&
622
623 git checkout --detach &&
624
625 C=$(git -C submodule commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
626 git -C submodule update-ref refs/changes/1 $C &&
627 git update-index --cacheinfo 160000 $C submodule &&
628 test_tick &&
629
630 D=$(git -C sub1 commit-tree -m "new change outside refs/heads" HEAD^{tree}) &&
631 git -C sub1 update-ref refs/changes/2 $D &&
632 git update-index --cacheinfo 160000 $D sub1 &&
633
634 git commit -m "updated submodules outside of refs/heads" &&
635 E=$(git rev-parse HEAD) &&
636 git update-ref refs/changes/3 $E &&
637 (
638 cd downstream &&
639 git fetch --recurse-submodules origin refs/changes/3:refs/heads/my_branch &&
640 git -C submodule cat-file -t $C &&
641 git -C sub1 cat-file -t $D &&
642 git checkout --recurse-submodules FETCH_HEAD
643 )
644 '
645
646 test_expect_success 'fetch new submodule commit on-demand in FETCH_HEAD' '
647 # depends on the previous test for setup
648
649 C=$(git -C submodule commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
650 git -C submodule update-ref refs/changes/4 $C &&
651 git update-index --cacheinfo 160000 $C submodule &&
652 test_tick &&
653
654 D=$(git -C sub1 commit-tree -m "another change outside refs/heads" HEAD^{tree}) &&
655 git -C sub1 update-ref refs/changes/5 $D &&
656 git update-index --cacheinfo 160000 $D sub1 &&
657
658 git commit -m "updated submodules outside of refs/heads" &&
659 E=$(git rev-parse HEAD) &&
660 git update-ref refs/changes/6 $E &&
661 (
662 cd downstream &&
663 git fetch --recurse-submodules origin refs/changes/6 &&
664 git -C submodule cat-file -t $C &&
665 git -C sub1 cat-file -t $D &&
666 git checkout --recurse-submodules FETCH_HEAD
667 )
668 '
669
670 test_expect_success 'fetch new submodule commits on-demand without .gitmodules entry' '
671 # depends on the previous test for setup
672
673 git config -f .gitmodules --remove-section submodule.sub1 &&
674 git add .gitmodules &&
675 git commit -m "delete gitmodules file" &&
676 git checkout -B super &&
677 git -C downstream fetch &&
678 git -C downstream checkout origin/super &&
679
680 C=$(git -C submodule commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
681 git -C submodule update-ref refs/changes/7 $C &&
682 git update-index --cacheinfo 160000 $C submodule &&
683 test_tick &&
684
685 D=$(git -C sub1 commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) &&
686 git -C sub1 update-ref refs/changes/8 $D &&
687 git update-index --cacheinfo 160000 $D sub1 &&
688
689 git commit -m "updated submodules outside of refs/heads" &&
690 E=$(git rev-parse HEAD) &&
691 git update-ref refs/changes/9 $E &&
692 (
693 cd downstream &&
694 git fetch --recurse-submodules origin refs/changes/9 &&
695 git -C submodule cat-file -t $C &&
696 git -C sub1 cat-file -t $D &&
697 git checkout --recurse-submodules FETCH_HEAD
698 )
699 '
700
701 test_expect_success 'fetch new submodule commit intermittently referenced by superproject' '
702 # depends on the previous test for setup
703
704 D=$(git -C sub1 commit-tree -m "change 10 outside refs/heads" HEAD^{tree}) &&
705 E=$(git -C sub1 commit-tree -m "change 11 outside refs/heads" HEAD^{tree}) &&
706 F=$(git -C sub1 commit-tree -m "change 12 outside refs/heads" HEAD^{tree}) &&
707
708 git -C sub1 update-ref refs/changes/10 $D &&
709 git update-index --cacheinfo 160000 $D sub1 &&
710 git commit -m "updated submodules outside of refs/heads" &&
711
712 git -C sub1 update-ref refs/changes/11 $E &&
713 git update-index --cacheinfo 160000 $E sub1 &&
714 git commit -m "updated submodules outside of refs/heads" &&
715
716 git -C sub1 update-ref refs/changes/12 $F &&
717 git update-index --cacheinfo 160000 $F sub1 &&
718 git commit -m "updated submodules outside of refs/heads" &&
719
720 G=$(git rev-parse HEAD) &&
721 git update-ref refs/changes/13 $G &&
722 (
723 cd downstream &&
724 git fetch --recurse-submodules origin refs/changes/13 &&
725
726 git -C sub1 cat-file -t $D &&
727 git -C sub1 cat-file -t $E &&
728 git -C sub1 cat-file -t $F
729 )
730 '
731
732 add_commit_push () {
733 dir="$1" &&
734 msg="$2" &&
735 shift 2 &&
736 git -C "$dir" add "$@" &&
737 git -C "$dir" commit -a -m "$msg" &&
738 git -C "$dir" push
739 }
740
741 compare_refs_in_dir () {
742 fail= &&
743 if test "x$1" = 'x!'
744 then
745 fail='!' &&
746 shift
747 fi &&
748 git -C "$1" rev-parse --verify "$2" >expect &&
749 git -C "$3" rev-parse --verify "$4" >actual &&
750 eval $fail test_cmp expect actual
751 }
752
753
754 test_expect_success 'setup nested submodule fetch test' '
755 # does not depend on any previous test setups
756
757 for repo in outer middle inner
758 do
759 git init --bare $repo &&
760 git clone $repo ${repo}_content &&
761 echo "$repo" >"${repo}_content/file" &&
762 add_commit_push ${repo}_content "initial" file ||
763 return 1
764 done &&
765
766 git clone outer A &&
767 git -C A submodule add "$pwd/middle" &&
768 git -C A/middle/ submodule add "$pwd/inner" &&
769 add_commit_push A/middle/ "adding inner sub" .gitmodules inner &&
770 add_commit_push A/ "adding middle sub" .gitmodules middle &&
771
772 git clone outer B &&
773 git -C B/ submodule update --init middle &&
774
775 compare_refs_in_dir A HEAD B HEAD &&
776 compare_refs_in_dir A/middle HEAD B/middle HEAD &&
777 test_path_is_file B/file &&
778 test_path_is_file B/middle/file &&
779 test_path_is_missing B/middle/inner/file &&
780
781 echo "change on inner repo of A" >"A/middle/inner/file" &&
782 add_commit_push A/middle/inner "change on inner" file &&
783 add_commit_push A/middle "change on inner" inner &&
784 add_commit_push A "change on inner" middle
785 '
786
787 test_expect_success 'fetching a superproject containing an uninitialized sub/sub project' '
788 # depends on previous test for setup
789
790 git -C B/ fetch &&
791 compare_refs_in_dir A origin/HEAD B origin/HEAD
792 '
793
794 fetch_with_recursion_abort () {
795 # In a regression the following git call will run into infinite recursion.
796 # To handle that, we connect the sed command to the git call by a pipe
797 # so that sed can kill the infinite recursion when detected.
798 # The recursion creates git output like:
799 # Fetching submodule sub
800 # Fetching submodule sub/sub <-- [1]
801 # Fetching submodule sub/sub/sub
802 # ...
803 # [1] sed will stop reading and cause git to eventually stop and die
804
805 git -C "$1" fetch --recurse-submodules 2>&1 |
806 sed "/Fetching submodule $2[^$]/q" >out &&
807 ! grep "Fetching submodule $2[^$]" out
808 }
809
810 test_expect_success 'setup recursive fetch with uninit submodule' '
811 # does not depend on any previous test setups
812
813 test_create_repo super &&
814 test_commit -C super initial &&
815 test_create_repo sub &&
816 test_commit -C sub initial &&
817 git -C sub rev-parse HEAD >expect &&
818
819 git -C super submodule add ../sub &&
820 git -C super commit -m "add sub" &&
821
822 git clone super superclone &&
823 git -C superclone submodule status >out &&
824 sed -e "s/^-//" -e "s/ sub.*$//" out >actual &&
825 test_cmp expect actual
826 '
827
828 test_expect_success 'recursive fetch with uninit submodule' '
829 # depends on previous test for setup
830
831 fetch_with_recursion_abort superclone sub &&
832 git -C superclone submodule status >out &&
833 sed -e "s/^-//" -e "s/ sub$//" out >actual &&
834 test_cmp expect actual
835 '
836
837 test_expect_success 'recursive fetch after deinit a submodule' '
838 # depends on previous test for setup
839
840 git -C superclone submodule update --init sub &&
841 git -C superclone submodule deinit -f sub &&
842
843 fetch_with_recursion_abort superclone sub &&
844 git -C superclone submodule status >out &&
845 sed -e "s/^-//" -e "s/ sub$//" out >actual &&
846 test_cmp expect actual
847 '
848
849 test_done