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_cmp expect.out actual.out &&
71 test_cmp 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_cmp expect.out actual.out &&
100 test_cmp 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_cmp expect.out actual.out &&
131 test_cmp 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_cmp expect.out actual.out &&
150 test_cmp expect.err actual.err &&
153 git fetch --recurse-submodules >../actual.out 2>../actual.err
155 test_cmp expect.out actual.out &&
156 test_cmp expect.err actual.err
159 test_expect_success
"recurseSubmodules=true propagates into submodules" '
160 add_upstream_commit &&
163 git config fetch.recurseSubmodules true
164 git fetch >../actual.out 2>../actual.err
166 test_cmp expect.out actual.out &&
167 test_cmp expect.err actual.err
170 test_expect_success
"--recurse-submodules overrides config in submodule" '
171 add_upstream_commit &&
176 git config fetch.recurseSubmodules false
178 git fetch --recurse-submodules >../actual.out 2>../actual.err
180 test_cmp expect.out actual.out &&
181 test_cmp expect.err actual.err
184 test_expect_success
"--no-recurse-submodules overrides config setting" '
185 add_upstream_commit &&
188 git config fetch.recurseSubmodules true
189 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
191 ! test -s actual.out &&
195 test_expect_success
"Recursion doesn't happen when no new commits are fetched in the superproject" '
200 git config --unset fetch.recurseSubmodules
202 git config --unset fetch.recurseSubmodules
203 git fetch >../actual.out 2>../actual.err
205 ! test -s actual.out &&
209 test_expect_success
"Recursion stops when no new submodule commits are fetched" '
210 head1=$(git rev-parse --short HEAD) &&
212 git commit -m "new submodule" &&
213 head2=$(git rev-parse --short HEAD) &&
214 echo "Fetching submodule submodule" > expect.out.sub &&
215 echo "From $pwd/." > expect.err.sub &&
216 echo " $head1..$head2 master -> origin/master" >> expect.err.sub
217 head -2 expect.err >> expect.err.sub &&
220 git fetch >../actual.out 2>../actual.err
222 test_cmp expect.err.sub actual.err &&
223 test_cmp expect.out.sub actual.out
226 test_expect_success
"Recursion doesn't happen when new superproject commits don't change any submodules" '
227 add_upstream_commit &&
228 head1=$(git rev-parse --short HEAD) &&
231 git commit -m "new file" &&
232 head2=$(git rev-parse --short HEAD) &&
233 echo "From $pwd/." > expect.err.file &&
234 echo " $head1..$head2 master -> origin/master" >> expect.err.file &&
237 git fetch >../actual.out 2>../actual.err
239 ! test -s actual.out &&
240 test_cmp expect.err.file actual.err
243 test_expect_success
"Recursion picks up config in submodule" '
246 git fetch --recurse-submodules &&
249 git config fetch.recurseSubmodules true
252 add_upstream_commit &&
253 head1=$(git rev-parse --short HEAD) &&
255 git commit -m "new submodule" &&
256 head2=$(git rev-parse --short HEAD) &&
257 echo "From $pwd/." > expect.err.sub &&
258 echo " $head1..$head2 master -> origin/master" >> expect.err.sub &&
259 cat expect.err >> expect.err.sub &&
262 git fetch >../actual.out 2>../actual.err &&
265 git config --unset fetch.recurseSubmodules
268 test_cmp expect.err.sub actual.err &&
269 test_cmp expect.out actual.out
272 test_expect_success
"Recursion picks up all submodules when necessary" '
273 add_upstream_commit &&
279 git checkout -q FETCH_HEAD
281 head1=$(git rev-parse --short HEAD^) &&
282 git add deepsubmodule &&
283 git commit -m "new deepsubmodule"
284 head2=$(git rev-parse --short HEAD) &&
285 echo "From $pwd/submodule" > ../expect.err.sub &&
286 echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub
288 head1=$(git rev-parse --short HEAD) &&
290 git commit -m "new submodule" &&
291 head2=$(git rev-parse --short HEAD) &&
292 echo "From $pwd/." > expect.err.2 &&
293 echo " $head1..$head2 master -> origin/master" >> expect.err.2 &&
294 cat expect.err.sub >> expect.err.2 &&
295 tail -2 expect.err >> expect.err.2 &&
298 git fetch >../actual.out 2>../actual.err
300 test_cmp expect.err.2 actual.err &&
301 test_cmp expect.out actual.out
304 test_expect_success
"'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
305 add_upstream_commit &&
311 git checkout -q FETCH_HEAD
313 head1=$(git rev-parse --short HEAD^) &&
314 git add deepsubmodule &&
315 git commit -m "new deepsubmodule"
316 head2=$(git rev-parse --short HEAD) &&
317 echo "From $pwd/submodule" > ../expect.err.sub &&
318 echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub
322 git config fetch.recurseSubmodules true &&
323 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
324 git config --unset fetch.recurseSubmodules
326 ! test -s actual.out &&
330 test_expect_success
"'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
331 head1=$(git rev-parse --short HEAD) &&
333 git commit -m "new submodule" &&
334 head2=$(git rev-parse --short HEAD) &&
335 tail -2 expect.err > expect.err.deepsub &&
336 echo "From $pwd/." > expect.err &&
337 echo " $head1..$head2 master -> origin/master" >> expect.err
338 cat expect.err.sub >> expect.err &&
339 cat expect.err.deepsub >> expect.err &&
342 git config fetch.recurseSubmodules false &&
345 git config -f .gitmodules submodule.deepsubmodule.fetchRecursive false
347 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
348 git config --unset fetch.recurseSubmodules
351 git config --unset -f .gitmodules submodule.deepsubmodule.fetchRecursive
354 test_cmp expect.out actual.out &&
355 test_cmp expect.err actual.err
358 test_expect_success
"'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
359 add_upstream_commit &&
360 head1=$(git rev-parse --short HEAD) &&
363 git commit -m "new file" &&
364 head2=$(git rev-parse --short HEAD) &&
365 echo "From $pwd/." > expect.err.file &&
366 echo " $head1..$head2 master -> origin/master" >> expect.err.file &&
369 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
371 ! test -s actual.out &&
372 test_cmp expect.err.file actual.err
375 test_expect_success
"'fetch.recurseSubmodules=on-demand' overrides global config" '
378 git fetch --recurse-submodules
380 add_upstream_commit &&
381 git config --global fetch.recurseSubmodules false &&
382 head1=$(git rev-parse --short HEAD) &&
384 git commit -m "new submodule" &&
385 head2=$(git rev-parse --short HEAD) &&
386 echo "From $pwd/." > expect.err.2 &&
387 echo " $head1..$head2 master -> origin/master" >> expect.err.2
388 head -2 expect.err >> expect.err.2 &&
391 git config fetch.recurseSubmodules on-demand &&
392 git fetch >../actual.out 2>../actual.err
394 git config --global --unset fetch.recurseSubmodules &&
397 git config --unset fetch.recurseSubmodules
399 test_cmp expect.out.sub actual.out &&
400 test_cmp expect.err.2 actual.err
403 test_expect_success
"'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
406 git fetch --recurse-submodules
408 add_upstream_commit &&
409 git config fetch.recurseSubmodules false &&
410 head1=$(git rev-parse --short HEAD) &&
412 git commit -m "new submodule" &&
413 head2=$(git rev-parse --short HEAD) &&
414 echo "From $pwd/." > expect.err.2 &&
415 echo " $head1..$head2 master -> origin/master" >> expect.err.2
416 head -2 expect.err >> expect.err.2 &&
419 git config submodule.submodule.fetchRecurseSubmodules on-demand &&
420 git fetch >../actual.out 2>../actual.err
422 git config --unset fetch.recurseSubmodules &&
425 git config --unset submodule.submodule.fetchRecurseSubmodules
427 test_cmp expect.out.sub actual.out &&
428 test_cmp expect.err.2 actual.err
431 test_expect_success
"don't fetch submodule when newly recorded commits are already present" '
434 git checkout -q HEAD^^
436 head1=$(git rev-parse --short HEAD) &&
438 git commit -m "submodule rewound" &&
439 head2=$(git rev-parse --short HEAD) &&
440 echo "From $pwd/." > expect.err &&
441 echo " $head1..$head2 master -> origin/master" >> expect.err &&
444 git fetch >../actual.out 2>../actual.err
446 ! test -s actual.out &&
447 test_cmp expect.err actual.err