userdiff/perl: match full line of POD headers
[git/gitweb.git] / t / t5526-fetch-submodules.sh
blobaf78e21ba913b465e7bf2e4149549d32de9d4240
1 #!/bin/sh
2 # Copyright (c) 2010, Jens Lehmann
4 test_description='Recursive "git fetch" for submodules'
6 . ./test-lib.sh
8 pwd=$(pwd)
10 add_upstream_commit() {
12 cd submodule &&
13 head1=$(git rev-parse --short HEAD) &&
14 echo new >> subfile &&
15 test_tick &&
16 git add 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
21 ) &&
23 cd deepsubmodule &&
24 head1=$(git rev-parse --short HEAD) &&
25 echo new >> deepsubfile &&
26 test_tick &&
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 &&
38 cd deepsubmodule &&
39 git init &&
40 echo deepsubcontent > deepsubfile &&
41 git add deepsubfile &&
42 git commit -m new deepsubfile
43 ) &&
44 mkdir submodule &&
46 cd submodule &&
47 git init &&
48 echo subcontent > subfile &&
49 git add subfile &&
50 git submodule add "$pwd/deepsubmodule" deepsubmodule &&
51 git commit -a -m new
52 ) &&
53 git submodule add "$pwd/submodule" submodule &&
54 git commit -am initial &&
55 git clone . downstream &&
57 cd downstream &&
58 git submodule update --init --recursive
59 ) &&
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 &&
67 cd downstream &&
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 &&
80 cd downstream &&
81 git fetch >../actual.out 2>../actual.err
82 ) &&
83 ! test -s actual.out &&
84 ! test -s actual.err
87 test_expect_success "fetch --no-recurse-submodules only fetches superproject" '
89 cd downstream &&
90 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
91 ) &&
92 ! test -s actual.out &&
93 ! test -s actual.err
96 test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
98 cd downstream &&
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 &&
112 cd downstream &&
113 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
114 ) &&
115 ! test -s actual.out &&
116 ! test -s actual.err
119 test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
121 cd downstream &&
122 git config submodule.submodule.fetchRecurseSubmodules false &&
123 git fetch >../actual.out 2>../actual.err
124 ) &&
125 ! test -s actual.out &&
126 ! test -s actual.err
129 test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
131 cd downstream &&
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" '
145 cd downstream &&
146 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
147 ) &&
148 ! test -s actual.out &&
149 ! test -s actual.err
152 test_expect_success "--dry-run propagates to submodules" '
153 add_upstream_commit &&
155 cd downstream &&
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" '
167 cd downstream &&
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 &&
180 cd downstream &&
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 &&
194 cd downstream &&
196 cd submodule &&
197 git config fetch.recurseSubmodules false
198 ) &&
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 &&
211 cd downstream &&
212 git config fetch.recurseSubmodules true
213 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
214 ) &&
215 ! test -s actual.out &&
216 ! test -s actual.err
219 test_expect_success "Recursion doesn't happen when no new commits are fetched in the superproject" '
221 cd downstream &&
223 cd submodule &&
224 git config --unset fetch.recurseSubmodules
225 ) &&
226 git config --unset fetch.recurseSubmodules
227 git fetch >../actual.out 2>../actual.err
228 ) &&
229 ! test -s actual.out &&
230 ! test -s actual.err
233 test_expect_success "Recursion stops when no new submodule commits are fetched" '
234 head1=$(git rev-parse --short HEAD) &&
235 git add submodule &&
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 &&
243 cd downstream &&
244 git fetch >../actual.out 2>../actual.err
245 ) &&
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) &&
253 echo a > file &&
254 git add file &&
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 &&
260 cd downstream &&
261 git fetch >../actual.out 2>../actual.err
262 ) &&
263 ! test -s actual.out &&
264 test_cmp expect.err.file actual.err
267 test_expect_success "Recursion picks up config in submodule" '
269 cd downstream &&
270 git fetch --recurse-submodules &&
272 cd submodule &&
273 git config fetch.recurseSubmodules true
275 ) &&
276 add_upstream_commit &&
277 head1=$(git rev-parse --short HEAD) &&
278 git add submodule &&
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 &&
285 cd downstream &&
286 git fetch >../actual.out 2>../actual.err &&
288 cd submodule &&
289 git config --unset fetch.recurseSubmodules
291 ) &&
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 &&
299 cd submodule &&
301 cd deepsubmodule &&
302 git fetch &&
303 git checkout -q FETCH_HEAD
304 ) &&
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
311 ) &&
312 head1=$(git rev-parse --short HEAD) &&
313 git add submodule &&
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 &&
321 cd downstream &&
322 git fetch >../actual.out 2>../actual.err
323 ) &&
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 &&
331 cd submodule &&
333 cd deepsubmodule &&
334 git fetch &&
335 git checkout -q FETCH_HEAD
336 ) &&
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
343 ) &&
345 cd downstream &&
346 git config fetch.recurseSubmodules true &&
347 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
348 git config --unset fetch.recurseSubmodules
349 ) &&
350 ! test -s actual.out &&
351 ! test -s actual.err
354 test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
355 head1=$(git rev-parse --short HEAD) &&
356 git add submodule &&
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 &&
365 cd downstream &&
366 git config fetch.recurseSubmodules false &&
368 cd submodule &&
369 git config -f .gitmodules submodule.deepsubmodule.fetchRecursive false
370 ) &&
371 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
372 git config --unset fetch.recurseSubmodules
374 cd submodule &&
375 git config --unset -f .gitmodules submodule.deepsubmodule.fetchRecursive
377 ) &&
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) &&
385 echo a >> file &&
386 git add file &&
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 &&
392 cd downstream &&
393 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
394 ) &&
395 ! test -s actual.out &&
396 test_cmp expect.err.file actual.err
399 test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" '
401 cd downstream &&
402 git fetch --recurse-submodules
403 ) &&
404 add_upstream_commit &&
405 git config --global fetch.recurseSubmodules false &&
406 head1=$(git rev-parse --short HEAD) &&
407 git add submodule &&
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 &&
414 cd downstream &&
415 git config fetch.recurseSubmodules on-demand &&
416 git fetch >../actual.out 2>../actual.err
417 ) &&
418 git config --global --unset fetch.recurseSubmodules &&
420 cd downstream &&
421 git config --unset fetch.recurseSubmodules
422 ) &&
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" '
429 cd downstream &&
430 git fetch --recurse-submodules
431 ) &&
432 add_upstream_commit &&
433 git config fetch.recurseSubmodules false &&
434 head1=$(git rev-parse --short HEAD) &&
435 git add submodule &&
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 &&
442 cd downstream &&
443 git config submodule.submodule.fetchRecurseSubmodules on-demand &&
444 git fetch >../actual.out 2>../actual.err
445 ) &&
446 git config --unset fetch.recurseSubmodules &&
448 cd downstream &&
449 git config --unset submodule.submodule.fetchRecurseSubmodules
450 ) &&
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" '
457 cd submodule &&
458 git checkout -q HEAD^^
459 ) &&
460 head1=$(git rev-parse --short HEAD) &&
461 git add submodule &&
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 &&
467 cd downstream &&
468 git fetch >../actual.out 2>../actual.err
469 ) &&
470 ! test -s actual.out &&
471 test_cmp expect.err actual.err
474 test_done