2 # Copyright (c) 2010, Jens Lehmann
4 test_description
='Recursive "git fetch" for submodules'
10 add_upstream_commit
() {
13 head1
=$
(git rev-parse
--short HEAD
) &&
14 echo new
>> subfile
&&
17 git commit
-m new subfile
&&
18 head2
=$
(git rev-parse
--short HEAD
) &&
19 echo "Fetching submodule submodule" > ..
/expect.err
&&
20 echo "From $pwd/submodule" >> ..
/expect.err
&&
21 echo " $head1..$head2 master -> origin/master" >> ..
/expect.err
25 head1
=$
(git rev-parse
--short HEAD
) &&
26 echo new
>> deepsubfile
&&
28 git add deepsubfile
&&
29 git commit
-m new deepsubfile
&&
30 head2
=$
(git rev-parse
--short HEAD
) &&
31 echo "Fetching submodule submodule/subdir/deepsubmodule" >> ..
/expect.err
32 echo "From $pwd/deepsubmodule" >> ..
/expect.err
&&
33 echo " $head1..$head2 master -> origin/master" >> ..
/expect.err
37 test_expect_success setup
'
38 mkdir deepsubmodule &&
42 echo deepsubcontent > deepsubfile &&
43 git add deepsubfile &&
44 git commit -m new deepsubfile
50 echo subcontent > subfile &&
52 git submodule add "$pwd/deepsubmodule" subdir/deepsubmodule &&
55 git submodule add "$pwd/submodule" submodule &&
56 git commit -am initial &&
57 git clone . downstream &&
60 git submodule update --init --recursive
64 test_expect_success
"fetch --recurse-submodules recurses into submodules" '
65 add_upstream_commit &&
68 git fetch --recurse-submodules >../actual.out 2>../actual.err
70 test_must_be_empty actual.out &&
71 test_i18ncmp expect.err actual.err
74 test_expect_success
"submodule.recurse option triggers recursive fetch" '
75 add_upstream_commit &&
78 git -c submodule.recurse fetch >../actual.out 2>../actual.err
80 test_must_be_empty actual.out &&
81 test_i18ncmp expect.err actual.err
84 test_expect_success
"fetch --recurse-submodules -j2 has the same output behaviour" '
85 add_upstream_commit &&
88 GIT_TRACE=$(pwd)/../trace.out git fetch --recurse-submodules -j2 2>../actual.err
90 test_must_be_empty actual.out &&
91 test_i18ncmp expect.err actual.err &&
92 grep "2 tasks" trace.out
95 test_expect_success
"fetch alone only fetches superproject" '
96 add_upstream_commit &&
99 git fetch >../actual.out 2>../actual.err
101 ! test -s actual.out &&
105 test_expect_success
"fetch --no-recurse-submodules only fetches superproject" '
108 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
110 ! test -s actual.out &&
114 test_expect_success
"using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
117 git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
118 git fetch >../actual.out 2>../actual.err
120 test_must_be_empty actual.out &&
121 test_i18ncmp expect.err actual.err
124 test_expect_success
"--no-recurse-submodules overrides .gitmodules config" '
125 add_upstream_commit &&
128 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
130 ! test -s actual.out &&
134 test_expect_success
"using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
137 git config submodule.submodule.fetchRecurseSubmodules false &&
138 git fetch >../actual.out 2>../actual.err
140 ! test -s actual.out &&
144 test_expect_success
"--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
147 git fetch --recurse-submodules >../actual.out 2>../actual.err &&
148 git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
149 git config --unset submodule.submodule.fetchRecurseSubmodules
151 test_must_be_empty actual.out &&
152 test_i18ncmp expect.err actual.err
155 test_expect_success
"--quiet propagates to submodules" '
158 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
160 ! test -s actual.out &&
164 test_expect_success
"--quiet propagates to parallel submodules" '
167 git fetch --recurse-submodules -j 2 --quiet >../actual.out 2>../actual.err
169 ! test -s actual.out &&
173 test_expect_success
"--dry-run propagates to submodules" '
174 add_upstream_commit &&
177 git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
179 test_must_be_empty actual.out &&
180 test_i18ncmp expect.err actual.err
183 test_expect_success
"Without --dry-run propagates to submodules" '
186 git fetch --recurse-submodules >../actual.out 2>../actual.err
188 test_must_be_empty actual.out &&
189 test_i18ncmp expect.err actual.err
192 test_expect_success
"recurseSubmodules=true propagates into submodules" '
193 add_upstream_commit &&
196 git config fetch.recurseSubmodules true &&
197 git fetch >../actual.out 2>../actual.err
199 test_must_be_empty actual.out &&
200 test_i18ncmp expect.err actual.err
203 test_expect_success
"--recurse-submodules overrides config in submodule" '
204 add_upstream_commit &&
209 git config fetch.recurseSubmodules false
211 git fetch --recurse-submodules >../actual.out 2>../actual.err
213 test_must_be_empty actual.out &&
214 test_i18ncmp expect.err actual.err
217 test_expect_success
"--no-recurse-submodules overrides config setting" '
218 add_upstream_commit &&
221 git config fetch.recurseSubmodules true &&
222 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
224 ! test -s actual.out &&
228 test_expect_success
"Recursion doesn't happen when no new commits are fetched in the superproject" '
233 git config --unset fetch.recurseSubmodules
235 git config --unset fetch.recurseSubmodules &&
236 git fetch >../actual.out 2>../actual.err
238 ! test -s actual.out &&
242 test_expect_success
"Recursion stops when no new submodule commits are fetched" '
243 head1=$(git rev-parse --short HEAD) &&
245 git commit -m "new submodule" &&
246 head2=$(git rev-parse --short HEAD) &&
247 echo "From $pwd/." > expect.err.sub &&
248 echo " $head1..$head2 master -> origin/master" >>expect.err.sub &&
249 head -3 expect.err >> expect.err.sub &&
252 git fetch >../actual.out 2>../actual.err
254 test_i18ncmp expect.err.sub actual.err &&
255 test_must_be_empty actual.out
258 test_expect_success
"Recursion doesn't happen when new superproject commits don't change any submodules" '
259 add_upstream_commit &&
260 head1=$(git rev-parse --short HEAD) &&
263 git commit -m "new file" &&
264 head2=$(git rev-parse --short HEAD) &&
265 echo "From $pwd/." > expect.err.file &&
266 echo " $head1..$head2 master -> origin/master" >> expect.err.file &&
269 git fetch >../actual.out 2>../actual.err
271 ! test -s actual.out &&
272 test_i18ncmp expect.err.file actual.err
275 test_expect_success
"Recursion picks up config in submodule" '
278 git fetch --recurse-submodules &&
281 git config fetch.recurseSubmodules true
284 add_upstream_commit &&
285 head1=$(git rev-parse --short HEAD) &&
287 git commit -m "new submodule" &&
288 head2=$(git rev-parse --short HEAD) &&
289 echo "From $pwd/." > expect.err.sub &&
290 echo " $head1..$head2 master -> origin/master" >> expect.err.sub &&
291 cat expect.err >> expect.err.sub &&
294 git fetch >../actual.out 2>../actual.err &&
297 git config --unset fetch.recurseSubmodules
300 test_i18ncmp expect.err.sub actual.err &&
301 test_must_be_empty actual.out
304 test_expect_success
"Recursion picks up all submodules when necessary" '
305 add_upstream_commit &&
309 cd subdir/deepsubmodule &&
311 git checkout -q FETCH_HEAD
313 head1=$(git rev-parse --short HEAD^) &&
314 git add subdir/deepsubmodule &&
315 git commit -m "new deepsubmodule" &&
316 head2=$(git rev-parse --short HEAD) &&
317 echo "Fetching submodule submodule" > ../expect.err.sub &&
318 echo "From $pwd/submodule" >> ../expect.err.sub &&
319 echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub
321 head1=$(git rev-parse --short HEAD) &&
323 git commit -m "new submodule" &&
324 head2=$(git rev-parse --short HEAD) &&
325 echo "From $pwd/." > expect.err.2 &&
326 echo " $head1..$head2 master -> origin/master" >> expect.err.2 &&
327 cat expect.err.sub >> expect.err.2 &&
328 tail -3 expect.err >> expect.err.2 &&
331 git fetch >../actual.out 2>../actual.err
333 test_i18ncmp expect.err.2 actual.err &&
334 test_must_be_empty actual.out
337 test_expect_success
"'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
338 add_upstream_commit &&
342 cd subdir/deepsubmodule &&
344 git checkout -q FETCH_HEAD
346 head1=$(git rev-parse --short HEAD^) &&
347 git add subdir/deepsubmodule &&
348 git commit -m "new deepsubmodule" &&
349 head2=$(git rev-parse --short HEAD) &&
350 echo Fetching submodule submodule > ../expect.err.sub &&
351 echo "From $pwd/submodule" >> ../expect.err.sub &&
352 echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub
356 git config fetch.recurseSubmodules true &&
357 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
358 git config --unset fetch.recurseSubmodules
360 ! test -s actual.out &&
364 test_expect_success
"'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
365 head1=$(git rev-parse --short HEAD) &&
367 git commit -m "new submodule" &&
368 head2=$(git rev-parse --short HEAD) &&
369 tail -3 expect.err > expect.err.deepsub &&
370 echo "From $pwd/." > expect.err &&
371 echo " $head1..$head2 master -> origin/master" >>expect.err &&
372 cat expect.err.sub >> expect.err &&
373 cat expect.err.deepsub >> expect.err &&
376 git config fetch.recurseSubmodules false &&
379 git config -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive false
381 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
382 git config --unset fetch.recurseSubmodules
385 git config --unset -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive
388 test_must_be_empty actual.out &&
389 test_i18ncmp expect.err actual.err
392 test_expect_success
"'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
393 add_upstream_commit &&
394 head1=$(git rev-parse --short HEAD) &&
397 git commit -m "new file" &&
398 head2=$(git rev-parse --short HEAD) &&
399 echo "From $pwd/." > expect.err.file &&
400 echo " $head1..$head2 master -> origin/master" >> expect.err.file &&
403 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
405 ! test -s actual.out &&
406 test_i18ncmp expect.err.file actual.err
409 test_expect_success
"'fetch.recurseSubmodules=on-demand' overrides global config" '
412 git fetch --recurse-submodules
414 add_upstream_commit &&
415 git config --global fetch.recurseSubmodules false &&
416 head1=$(git rev-parse --short HEAD) &&
418 git commit -m "new submodule" &&
419 head2=$(git rev-parse --short HEAD) &&
420 echo "From $pwd/." > expect.err.2 &&
421 echo " $head1..$head2 master -> origin/master" >>expect.err.2 &&
422 head -3 expect.err >> expect.err.2 &&
425 git config fetch.recurseSubmodules on-demand &&
426 git fetch >../actual.out 2>../actual.err
428 git config --global --unset fetch.recurseSubmodules &&
431 git config --unset fetch.recurseSubmodules
433 test_must_be_empty actual.out &&
434 test_i18ncmp expect.err.2 actual.err
437 test_expect_success
"'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
440 git fetch --recurse-submodules
442 add_upstream_commit &&
443 git config fetch.recurseSubmodules false &&
444 head1=$(git rev-parse --short HEAD) &&
446 git commit -m "new submodule" &&
447 head2=$(git rev-parse --short HEAD) &&
448 echo "From $pwd/." > expect.err.2 &&
449 echo " $head1..$head2 master -> origin/master" >>expect.err.2 &&
450 head -3 expect.err >> expect.err.2 &&
453 git config submodule.submodule.fetchRecurseSubmodules on-demand &&
454 git fetch >../actual.out 2>../actual.err
456 git config --unset fetch.recurseSubmodules &&
459 git config --unset submodule.submodule.fetchRecurseSubmodules
461 test_must_be_empty actual.out &&
462 test_i18ncmp expect.err.2 actual.err
465 test_expect_success
"don't fetch submodule when newly recorded commits are already present" '
468 git checkout -q HEAD^^
470 head1=$(git rev-parse --short HEAD) &&
472 git commit -m "submodule rewound" &&
473 head2=$(git rev-parse --short HEAD) &&
474 echo "From $pwd/." > expect.err &&
475 echo " $head1..$head2 master -> origin/master" >> expect.err &&
478 git fetch >../actual.out 2>../actual.err
480 ! test -s actual.out &&
481 test_i18ncmp expect.err actual.err
484 test_expect_success
'fetching submodules respects parallel settings' '
485 git config fetch.recurseSubmodules true &&
488 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
489 grep "7 tasks" trace.out &&
490 git config submodule.fetchJobs 8 &&
491 GIT_TRACE=$(pwd)/trace.out git fetch &&
492 grep "8 tasks" trace.out &&
493 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
494 grep "9 tasks" trace.out
498 test_expect_success
'fetching submodule into a broken repository' '
499 # Prepare src and src/sub nested in it
504 git -C sub commit --allow-empty -m "initial in sub" &&
505 git submodule add -- ./sub sub &&
506 git commit -m "initial in top"
509 # Clone the old-fashoned way
511 git -C dst clone ../src/sub sub &&
513 # Make sure that old-fashoned layout is still supported
516 # "diff" would find no change
517 git -C dst diff --exit-code &&
519 # Recursive-fetch works fine
520 git -C dst fetch --recurse-submodules &&
522 # Break the receiving submodule
523 rm -f dst/sub/.git/HEAD &&
525 # NOTE: without the fix the following tests will recurse forever!
526 # They should terminate with an error.
528 test_must_fail git -C dst status &&
529 test_must_fail git -C dst diff &&
530 test_must_fail git -C dst fetch --recurse-submodules