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 "From $pwd/submodule" > ../expect.err &&
20 echo " $head1..$head2 master -> origin/master" >> ../expect.err
24 head1=$(git rev-parse --short HEAD) &&
25 echo new >> deepsubfile &&
27 git add deepsubfile &&
28 git commit -m new deepsubfile &&
29 head2=$(git rev-parse --short HEAD) &&
30 echo "From $pwd/deepsubmodule" >> ../expect.err &&
31 echo " $head1..$head2 master -> origin/master" >> ../expect.err
35 test_expect_success setup '
36 mkdir deepsubmodule &&
40 echo deepsubcontent > deepsubfile &&
41 git add deepsubfile &&
42 git commit -m new deepsubfile
48 echo subcontent > subfile &&
50 git submodule add "$pwd/deepsubmodule" deepsubmodule &&
53 git submodule add "$pwd/submodule" submodule &&
54 git commit -am initial &&
55 git clone . downstream &&
58 git submodule update --init --recursive
60 echo "Fetching submodule submodule" > expect.out &&
61 echo "Fetching submodule submodule/deepsubmodule" >> expect.out
64 test_expect_success "fetch --recurse-submodules recurses into submodules" '
65 add_upstream_commit &&
68 git fetch --recurse-submodules >../actual.out 2>../actual.err
72 test_expect_success C_LOCALE_OUTPUT "fetch --recurse-submodules recurses into submodules: output" '
73 test_cmp expect.out actual.out &&
74 test_cmp expect.err actual.err
77 test_expect_success "fetch alone only fetches superproject" '
78 add_upstream_commit &&
81 git fetch >../actual.out 2>../actual.err
83 ! test -s actual.out &&
87 test_expect_success "fetch --no-recurse-submodules only fetches superproject" '
90 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
92 ! test -s actual.out &&
96 test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
99 git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
100 git fetch >../actual.out 2>../actual.err
104 test_expect_success C_LOCALE_OUTPUT "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
105 test_cmp expect.out actual.out &&
106 test_cmp expect.err actual.err
109 test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
110 add_upstream_commit &&
113 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
115 ! test -s actual.out &&
119 test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
122 git config submodule.submodule.fetchRecurseSubmodules false &&
123 git fetch >../actual.out 2>../actual.err
125 ! test -s actual.out &&
129 test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
132 git fetch --recurse-submodules >../actual.out 2>../actual.err &&
133 git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
134 git config --unset submodule.submodule.fetchRecurseSubmodules
138 test_expect_success C_LOCALE_OUTPUT "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config: output" '
139 test_cmp expect.out actual.out &&
140 test_cmp expect.err actual.err
143 test_expect_success "--quiet propagates to submodules" '
146 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
148 ! test -s actual.out &&
152 test_expect_success "--dry-run propagates to submodules" '
153 add_upstream_commit &&
156 git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
160 test_expect_success C_LOCALE_OUTPUT "--dry-run propagates to submodules: output" '
161 test_cmp expect.out actual.out &&
162 test_cmp expect.err actual.err
165 test_expect_success "Without --dry-run propagates to submodules" '
168 git fetch --recurse-submodules >../actual.out 2>../actual.err
172 test_expect_success C_LOCALE_OUTPUT "Without --dry-run propagates to submodules: output" '
173 test_cmp expect.out actual.out &&
174 test_cmp expect.err actual.err
177 test_expect_success "recurseSubmodules=true propagates into submodules" '
178 add_upstream_commit &&
181 git config fetch.recurseSubmodules true
182 git fetch >../actual.out 2>../actual.err
186 test_expect_success C_LOCALE_OUTPUT "recurseSubmodules=true propagates into submodules: output" '
187 test_cmp expect.out actual.out &&
188 test_cmp expect.err actual.err
191 test_expect_success "--recurse-submodules overrides config in submodule" '
192 add_upstream_commit &&
197 git config fetch.recurseSubmodules false
199 git fetch --recurse-submodules >../actual.out 2>../actual.err
203 test_expect_success C_LOCALE_OUTPUT "--recurse-submodules overrides config in submodule: output" '
204 test_cmp expect.out actual.out &&
205 test_cmp expect.err actual.err
208 test_expect_success "--no-recurse-submodules overrides config setting" '
209 add_upstream_commit &&
212 git config fetch.recurseSubmodules true
213 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
215 ! test -s actual.out &&
219 test_expect_success "Recursion doesn't happen when no new commits are fetched in the superproject" '
224 git config --unset fetch.recurseSubmodules
226 git config --unset fetch.recurseSubmodules
227 git fetch >../actual.out 2>../actual.err
229 ! test -s actual.out &&
233 test_expect_success "Recursion stops when no new submodule commits are fetched" '
234 head1=$(git rev-parse --short HEAD) &&
236 git commit -m "new submodule" &&
237 head2=$(git rev-parse --short HEAD) &&
238 echo "Fetching submodule submodule" > expect.out.sub &&
239 echo "From $pwd/." > expect.err.sub &&
240 echo " $head1..$head2 master -> origin/master" >> expect.err.sub
241 head -2 expect.err >> expect.err.sub &&
244 git fetch >../actual.out 2>../actual.err
246 test_cmp expect.err.sub actual.err &&
247 test_cmp expect.out.sub actual.out
250 test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
251 add_upstream_commit &&
252 head1=$(git rev-parse --short HEAD) &&
255 git commit -m "new file" &&
256 head2=$(git rev-parse --short HEAD) &&
257 echo "From $pwd/." > expect.err.file &&
258 echo " $head1..$head2 master -> origin/master" >> expect.err.file &&
261 git fetch >../actual.out 2>../actual.err
263 ! test -s actual.out &&
264 test_cmp expect.err.file actual.err
267 test_expect_success "Recursion picks up config in submodule" '
270 git fetch --recurse-submodules &&
273 git config fetch.recurseSubmodules true
276 add_upstream_commit &&
277 head1=$(git rev-parse --short HEAD) &&
279 git commit -m "new submodule" &&
280 head2=$(git rev-parse --short HEAD) &&
281 echo "From $pwd/." > expect.err.sub &&
282 echo " $head1..$head2 master -> origin/master" >> expect.err.sub &&
283 cat expect.err >> expect.err.sub &&
286 git fetch >../actual.out 2>../actual.err &&
289 git config --unset fetch.recurseSubmodules
292 test_cmp expect.err.sub actual.err &&
293 test_cmp expect.out actual.out
296 test_expect_success "Recursion picks up all submodules when necessary" '
297 add_upstream_commit &&
303 git checkout -q FETCH_HEAD
305 head1=$(git rev-parse --short HEAD^) &&
306 git add deepsubmodule &&
307 git commit -m "new deepsubmodule"
308 head2=$(git rev-parse --short HEAD) &&
309 echo "From $pwd/submodule" > ../expect.err.sub &&
310 echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub
312 head1=$(git rev-parse --short HEAD) &&
314 git commit -m "new submodule" &&
315 head2=$(git rev-parse --short HEAD) &&
316 echo "From $pwd/." > expect.err.2 &&
317 echo " $head1..$head2 master -> origin/master" >> expect.err.2 &&
318 cat expect.err.sub >> expect.err.2 &&
319 tail -2 expect.err >> expect.err.2 &&
322 git fetch >../actual.out 2>../actual.err
324 test_cmp expect.err.2 actual.err &&
325 test_cmp expect.out actual.out
328 test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
329 add_upstream_commit &&
335 git checkout -q FETCH_HEAD
337 head1=$(git rev-parse --short HEAD^) &&
338 git add deepsubmodule &&
339 git commit -m "new deepsubmodule"
340 head2=$(git rev-parse --short HEAD) &&
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 -2 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.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.deepsubmodule.fetchRecursive
378 test_cmp expect.out actual.out &&
379 test_cmp 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_cmp 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 -2 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_cmp expect.out.sub actual.out &&
424 test_cmp 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 -2 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_cmp expect.out.sub actual.out &&
452 test_cmp 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_cmp expect.err actual.err