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
70 test_i18ncmp expect.out actual.out &&
71 test_i18ncmp expect.err actual.err
74 test_expect_success
"fetch alone only fetches superproject" '
75 add_upstream_commit &&
78 git fetch >../actual.out 2>../actual.err
80 ! test -s actual.out &&
84 test_expect_success
"fetch --no-recurse-submodules only fetches superproject" '
87 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
89 ! test -s actual.out &&
93 test_expect_success
"using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
96 git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
97 git fetch >../actual.out 2>../actual.err
99 test_i18ncmp expect.out actual.out &&
100 test_i18ncmp expect.err actual.err
103 test_expect_success
"--no-recurse-submodules overrides .gitmodules config" '
104 add_upstream_commit &&
107 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
109 ! test -s actual.out &&
113 test_expect_success
"using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
116 git config submodule.submodule.fetchRecurseSubmodules false &&
117 git fetch >../actual.out 2>../actual.err
119 ! test -s actual.out &&
123 test_expect_success
"--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
126 git fetch --recurse-submodules >../actual.out 2>../actual.err &&
127 git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
128 git config --unset submodule.submodule.fetchRecurseSubmodules
130 test_i18ncmp expect.out actual.out &&
131 test_i18ncmp expect.err actual.err
134 test_expect_success
"--quiet propagates to submodules" '
137 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
139 ! test -s actual.out &&
143 test_expect_success
"--dry-run propagates to submodules" '
144 add_upstream_commit &&
147 git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
149 test_i18ncmp expect.out actual.out &&
150 test_i18ncmp expect.err actual.err
153 test_expect_success
"Without --dry-run propagates to submodules" '
156 git fetch --recurse-submodules >../actual.out 2>../actual.err
158 test_i18ncmp expect.out actual.out &&
159 test_i18ncmp expect.err actual.err
162 test_expect_success
"recurseSubmodules=true propagates into submodules" '
163 add_upstream_commit &&
166 git config fetch.recurseSubmodules true
167 git fetch >../actual.out 2>../actual.err
169 test_i18ncmp expect.out actual.out &&
170 test_i18ncmp expect.err actual.err
173 test_expect_success
"--recurse-submodules overrides config in submodule" '
174 add_upstream_commit &&
179 git config fetch.recurseSubmodules false
181 git fetch --recurse-submodules >../actual.out 2>../actual.err
183 test_i18ncmp expect.out actual.out &&
184 test_i18ncmp expect.err actual.err
187 test_expect_success
"--no-recurse-submodules overrides config setting" '
188 add_upstream_commit &&
191 git config fetch.recurseSubmodules true
192 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
194 ! test -s actual.out &&
198 test_expect_success
"Recursion doesn't happen when no new commits are fetched in the superproject" '
203 git config --unset fetch.recurseSubmodules
205 git config --unset fetch.recurseSubmodules
206 git fetch >../actual.out 2>../actual.err
208 ! test -s actual.out &&
212 test_expect_success
"Recursion stops when no new submodule commits are fetched" '
213 head1=$(git rev-parse --short HEAD) &&
215 git commit -m "new submodule" &&
216 head2=$(git rev-parse --short HEAD) &&
217 echo "Fetching submodule submodule" > expect.out.sub &&
218 echo "From $pwd/." > expect.err.sub &&
219 echo " $head1..$head2 master -> origin/master" >> expect.err.sub
220 head -2 expect.err >> expect.err.sub &&
223 git fetch >../actual.out 2>../actual.err
225 test_i18ncmp expect.err.sub actual.err &&
226 test_i18ncmp expect.out.sub actual.out
229 test_expect_success
"Recursion doesn't happen when new superproject commits don't change any submodules" '
230 add_upstream_commit &&
231 head1=$(git rev-parse --short HEAD) &&
234 git commit -m "new file" &&
235 head2=$(git rev-parse --short HEAD) &&
236 echo "From $pwd/." > expect.err.file &&
237 echo " $head1..$head2 master -> origin/master" >> expect.err.file &&
240 git fetch >../actual.out 2>../actual.err
242 ! test -s actual.out &&
243 test_i18ncmp expect.err.file actual.err
246 test_expect_success
"Recursion picks up config in submodule" '
249 git fetch --recurse-submodules &&
252 git config fetch.recurseSubmodules true
255 add_upstream_commit &&
256 head1=$(git rev-parse --short HEAD) &&
258 git commit -m "new submodule" &&
259 head2=$(git rev-parse --short HEAD) &&
260 echo "From $pwd/." > expect.err.sub &&
261 echo " $head1..$head2 master -> origin/master" >> expect.err.sub &&
262 cat expect.err >> expect.err.sub &&
265 git fetch >../actual.out 2>../actual.err &&
268 git config --unset fetch.recurseSubmodules
271 test_i18ncmp expect.err.sub actual.err &&
272 test_i18ncmp expect.out actual.out
275 test_expect_success
"Recursion picks up all submodules when necessary" '
276 add_upstream_commit &&
282 git checkout -q FETCH_HEAD
284 head1=$(git rev-parse --short HEAD^) &&
285 git add deepsubmodule &&
286 git commit -m "new deepsubmodule"
287 head2=$(git rev-parse --short HEAD) &&
288 echo "From $pwd/submodule" > ../expect.err.sub &&
289 echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub
291 head1=$(git rev-parse --short HEAD) &&
293 git commit -m "new submodule" &&
294 head2=$(git rev-parse --short HEAD) &&
295 echo "From $pwd/." > expect.err.2 &&
296 echo " $head1..$head2 master -> origin/master" >> expect.err.2 &&
297 cat expect.err.sub >> expect.err.2 &&
298 tail -2 expect.err >> expect.err.2 &&
301 git fetch >../actual.out 2>../actual.err
303 test_i18ncmp expect.err.2 actual.err &&
304 test_i18ncmp expect.out actual.out
307 test_expect_success
"'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
308 add_upstream_commit &&
314 git checkout -q FETCH_HEAD
316 head1=$(git rev-parse --short HEAD^) &&
317 git add deepsubmodule &&
318 git commit -m "new deepsubmodule"
319 head2=$(git rev-parse --short HEAD) &&
320 echo "From $pwd/submodule" > ../expect.err.sub &&
321 echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub
325 git config fetch.recurseSubmodules true &&
326 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
327 git config --unset fetch.recurseSubmodules
329 ! test -s actual.out &&
333 test_expect_success
"'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
334 head1=$(git rev-parse --short HEAD) &&
336 git commit -m "new submodule" &&
337 head2=$(git rev-parse --short HEAD) &&
338 tail -2 expect.err > expect.err.deepsub &&
339 echo "From $pwd/." > expect.err &&
340 echo " $head1..$head2 master -> origin/master" >> expect.err
341 cat expect.err.sub >> expect.err &&
342 cat expect.err.deepsub >> expect.err &&
345 git config fetch.recurseSubmodules false &&
348 git config -f .gitmodules submodule.deepsubmodule.fetchRecursive false
350 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
351 git config --unset fetch.recurseSubmodules
354 git config --unset -f .gitmodules submodule.deepsubmodule.fetchRecursive
357 test_i18ncmp expect.out actual.out &&
358 test_i18ncmp expect.err actual.err
361 test_expect_success
"'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
362 add_upstream_commit &&
363 head1=$(git rev-parse --short HEAD) &&
366 git commit -m "new file" &&
367 head2=$(git rev-parse --short HEAD) &&
368 echo "From $pwd/." > expect.err.file &&
369 echo " $head1..$head2 master -> origin/master" >> expect.err.file &&
372 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
374 ! test -s actual.out &&
375 test_i18ncmp expect.err.file actual.err
378 test_expect_success
"'fetch.recurseSubmodules=on-demand' overrides global config" '
381 git fetch --recurse-submodules
383 add_upstream_commit &&
384 git config --global fetch.recurseSubmodules false &&
385 head1=$(git rev-parse --short HEAD) &&
387 git commit -m "new submodule" &&
388 head2=$(git rev-parse --short HEAD) &&
389 echo "From $pwd/." > expect.err.2 &&
390 echo " $head1..$head2 master -> origin/master" >> expect.err.2
391 head -2 expect.err >> expect.err.2 &&
394 git config fetch.recurseSubmodules on-demand &&
395 git fetch >../actual.out 2>../actual.err
397 git config --global --unset fetch.recurseSubmodules &&
400 git config --unset fetch.recurseSubmodules
402 test_i18ncmp expect.out.sub actual.out &&
403 test_i18ncmp expect.err.2 actual.err
406 test_expect_success
"'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
409 git fetch --recurse-submodules
411 add_upstream_commit &&
412 git config fetch.recurseSubmodules false &&
413 head1=$(git rev-parse --short HEAD) &&
415 git commit -m "new submodule" &&
416 head2=$(git rev-parse --short HEAD) &&
417 echo "From $pwd/." > expect.err.2 &&
418 echo " $head1..$head2 master -> origin/master" >> expect.err.2
419 head -2 expect.err >> expect.err.2 &&
422 git config submodule.submodule.fetchRecurseSubmodules on-demand &&
423 git fetch >../actual.out 2>../actual.err
425 git config --unset fetch.recurseSubmodules &&
428 git config --unset submodule.submodule.fetchRecurseSubmodules
430 test_i18ncmp expect.out.sub actual.out &&
431 test_i18ncmp expect.err.2 actual.err
434 test_expect_success
"don't fetch submodule when newly recorded commits are already present" '
437 git checkout -q HEAD^^
439 head1=$(git rev-parse --short HEAD) &&
441 git commit -m "submodule rewound" &&
442 head2=$(git rev-parse --short HEAD) &&
443 echo "From $pwd/." > expect.err &&
444 echo " $head1..$head2 master -> origin/master" >> expect.err &&
447 git fetch >../actual.out 2>../actual.err
449 ! test -s actual.out &&
450 test_i18ncmp expect.err actual.err