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 "fetch --recurse-submodules -j2 has the same output behaviour" '
75 add_upstream_commit &&
78 GIT_TRACE=$(pwd)/../trace.out git fetch --recurse-submodules -j2 2>../actual.err
80 test_must_be_empty actual.out &&
81 test_i18ncmp expect.err actual.err &&
82 grep "2 tasks" trace.out
85 test_expect_success "fetch alone only fetches superproject" '
86 add_upstream_commit &&
89 git fetch >../actual.out 2>../actual.err
91 ! test -s actual.out &&
95 test_expect_success "fetch --no-recurse-submodules only fetches superproject" '
98 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
100 ! test -s actual.out &&
104 test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
107 git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
108 git fetch >../actual.out 2>../actual.err
110 test_must_be_empty actual.out &&
111 test_i18ncmp expect.err actual.err
114 test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
115 add_upstream_commit &&
118 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
120 ! test -s actual.out &&
124 test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
127 git config submodule.submodule.fetchRecurseSubmodules false &&
128 git fetch >../actual.out 2>../actual.err
130 ! test -s actual.out &&
134 test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
137 git fetch --recurse-submodules >../actual.out 2>../actual.err &&
138 git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
139 git config --unset submodule.submodule.fetchRecurseSubmodules
141 test_must_be_empty actual.out &&
142 test_i18ncmp expect.err actual.err
145 test_expect_success "--quiet propagates to submodules" '
148 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
150 ! test -s actual.out &&
154 test_expect_success "--quiet propagates to parallel submodules" '
157 git fetch --recurse-submodules -j 2 --quiet >../actual.out 2>../actual.err
159 ! test -s actual.out &&
163 test_expect_success "--dry-run propagates to submodules" '
164 add_upstream_commit &&
167 git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
169 test_must_be_empty actual.out &&
170 test_i18ncmp expect.err actual.err
173 test_expect_success "Without --dry-run propagates to submodules" '
176 git fetch --recurse-submodules >../actual.out 2>../actual.err
178 test_must_be_empty actual.out &&
179 test_i18ncmp expect.err actual.err
182 test_expect_success "recurseSubmodules=true propagates into submodules" '
183 add_upstream_commit &&
186 git config fetch.recurseSubmodules true
187 git fetch >../actual.out 2>../actual.err
189 test_must_be_empty actual.out &&
190 test_i18ncmp expect.err actual.err
193 test_expect_success "--recurse-submodules overrides config in submodule" '
194 add_upstream_commit &&
199 git config fetch.recurseSubmodules false
201 git fetch --recurse-submodules >../actual.out 2>../actual.err
203 test_must_be_empty actual.out &&
204 test_i18ncmp expect.err actual.err
207 test_expect_success "--no-recurse-submodules overrides config setting" '
208 add_upstream_commit &&
211 git config fetch.recurseSubmodules true
212 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
214 ! test -s actual.out &&
218 test_expect_success "Recursion doesn't happen when no new commits are fetched in the superproject" '
223 git config --unset fetch.recurseSubmodules
225 git config --unset fetch.recurseSubmodules
226 git fetch >../actual.out 2>../actual.err
228 ! test -s actual.out &&
232 test_expect_success "Recursion stops when no new submodule commits are fetched" '
233 head1=$(git rev-parse --short HEAD) &&
235 git commit -m "new submodule" &&
236 head2=$(git rev-parse --short HEAD) &&
237 echo "From $pwd/." > expect.err.sub &&
238 echo " $head1..$head2 master -> origin/master" >>expect.err.sub &&
239 head -3 expect.err >> expect.err.sub &&
242 git fetch >../actual.out 2>../actual.err
244 test_i18ncmp expect.err.sub actual.err &&
245 test_must_be_empty actual.out
248 test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
249 add_upstream_commit &&
250 head1=$(git rev-parse --short HEAD) &&
253 git commit -m "new file" &&
254 head2=$(git rev-parse --short HEAD) &&
255 echo "From $pwd/." > expect.err.file &&
256 echo " $head1..$head2 master -> origin/master" >> expect.err.file &&
259 git fetch >../actual.out 2>../actual.err
261 ! test -s actual.out &&
262 test_i18ncmp expect.err.file actual.err
265 test_expect_success "Recursion picks up config in submodule" '
268 git fetch --recurse-submodules &&
271 git config fetch.recurseSubmodules true
274 add_upstream_commit &&
275 head1=$(git rev-parse --short HEAD) &&
277 git commit -m "new submodule" &&
278 head2=$(git rev-parse --short HEAD) &&
279 echo "From $pwd/." > expect.err.sub &&
280 echo " $head1..$head2 master -> origin/master" >> expect.err.sub &&
281 cat expect.err >> expect.err.sub &&
284 git fetch >../actual.out 2>../actual.err &&
287 git config --unset fetch.recurseSubmodules
290 test_i18ncmp expect.err.sub actual.err &&
291 test_must_be_empty actual.out
294 test_expect_success "Recursion picks up all submodules when necessary" '
295 add_upstream_commit &&
299 cd subdir/deepsubmodule &&
301 git checkout -q FETCH_HEAD
303 head1=$(git rev-parse --short HEAD^) &&
304 git add subdir/deepsubmodule &&
305 git commit -m "new deepsubmodule"
306 head2=$(git rev-parse --short HEAD) &&
307 echo "Fetching submodule submodule" > ../expect.err.sub &&
308 echo "From $pwd/submodule" >> ../expect.err.sub &&
309 echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub
311 head1=$(git rev-parse --short HEAD) &&
313 git commit -m "new submodule" &&
314 head2=$(git rev-parse --short HEAD) &&
315 echo "From $pwd/." > expect.err.2 &&
316 echo " $head1..$head2 master -> origin/master" >> expect.err.2 &&
317 cat expect.err.sub >> expect.err.2 &&
318 tail -3 expect.err >> expect.err.2 &&
321 git fetch >../actual.out 2>../actual.err
323 test_i18ncmp expect.err.2 actual.err &&
324 test_must_be_empty actual.out
327 test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
328 add_upstream_commit &&
332 cd subdir/deepsubmodule &&
334 git checkout -q FETCH_HEAD
336 head1=$(git rev-parse --short HEAD^) &&
337 git add subdir/deepsubmodule &&
338 git commit -m "new deepsubmodule" &&
339 head2=$(git rev-parse --short HEAD) &&
340 echo Fetching submodule submodule > ../expect.err.sub &&
341 echo "From $pwd/submodule" >> ../expect.err.sub &&
342 echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub
346 git config fetch.recurseSubmodules true &&
347 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
348 git config --unset fetch.recurseSubmodules
350 ! test -s actual.out &&
354 test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
355 head1=$(git rev-parse --short HEAD) &&
357 git commit -m "new submodule" &&
358 head2=$(git rev-parse --short HEAD) &&
359 tail -3 expect.err > expect.err.deepsub &&
360 echo "From $pwd/." > expect.err &&
361 echo " $head1..$head2 master -> origin/master" >>expect.err &&
362 cat expect.err.sub >> expect.err &&
363 cat expect.err.deepsub >> expect.err &&
366 git config fetch.recurseSubmodules false &&
369 git config -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive false
371 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
372 git config --unset fetch.recurseSubmodules
375 git config --unset -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive
378 test_must_be_empty actual.out &&
379 test_i18ncmp expect.err actual.err
382 test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
383 add_upstream_commit &&
384 head1=$(git rev-parse --short HEAD) &&
387 git commit -m "new file" &&
388 head2=$(git rev-parse --short HEAD) &&
389 echo "From $pwd/." > expect.err.file &&
390 echo " $head1..$head2 master -> origin/master" >> expect.err.file &&
393 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
395 ! test -s actual.out &&
396 test_i18ncmp expect.err.file actual.err
399 test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" '
402 git fetch --recurse-submodules
404 add_upstream_commit &&
405 git config --global fetch.recurseSubmodules false &&
406 head1=$(git rev-parse --short HEAD) &&
408 git commit -m "new submodule" &&
409 head2=$(git rev-parse --short HEAD) &&
410 echo "From $pwd/." > expect.err.2 &&
411 echo " $head1..$head2 master -> origin/master" >>expect.err.2 &&
412 head -3 expect.err >> expect.err.2 &&
415 git config fetch.recurseSubmodules on-demand &&
416 git fetch >../actual.out 2>../actual.err
418 git config --global --unset fetch.recurseSubmodules &&
421 git config --unset fetch.recurseSubmodules
423 test_must_be_empty actual.out &&
424 test_i18ncmp expect.err.2 actual.err
427 test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
430 git fetch --recurse-submodules
432 add_upstream_commit &&
433 git config fetch.recurseSubmodules false &&
434 head1=$(git rev-parse --short HEAD) &&
436 git commit -m "new submodule" &&
437 head2=$(git rev-parse --short HEAD) &&
438 echo "From $pwd/." > expect.err.2 &&
439 echo " $head1..$head2 master -> origin/master" >>expect.err.2 &&
440 head -3 expect.err >> expect.err.2 &&
443 git config submodule.submodule.fetchRecurseSubmodules on-demand &&
444 git fetch >../actual.out 2>../actual.err
446 git config --unset fetch.recurseSubmodules &&
449 git config --unset submodule.submodule.fetchRecurseSubmodules
451 test_must_be_empty actual.out &&
452 test_i18ncmp expect.err.2 actual.err
455 test_expect_success "don't fetch submodule when newly recorded commits are already present" '
458 git checkout -q HEAD^^
460 head1=$(git rev-parse --short HEAD) &&
462 git commit -m "submodule rewound" &&
463 head2=$(git rev-parse --short HEAD) &&
464 echo "From $pwd/." > expect.err &&
465 echo " $head1..$head2 master -> origin/master" >> expect.err &&
468 git fetch >../actual.out 2>../actual.err
470 ! test -s actual.out &&
471 test_i18ncmp expect.err actual.err