3 test_description='test push with submodules'
7 test_expect_success setup '
9 GIT_DIR=pub.git git init --bare &&
10 GIT_DIR=pub.git git config receive.fsckobjects true &&
15 git config push.default matching &&
20 git config push.default matching &&
23 git commit -m "Initial junk"
26 git commit -m "Initial superproject"
30 test_expect_success 'push works with recorded gitlink' '
33 git push ../pub.git master
37 test_expect_success 'push if submodule has no remote' '
42 git commit -m "Second junk"
47 git commit -m "Second commit for gar/bage" &&
48 git push --recurse-submodules=check ../pub.git master
52 test_expect_success 'push fails if submodule commit not on remote' '
55 git clone --bare bage ../../submodule.git &&
57 git remote add origin ../../../submodule.git &&
61 git commit -m "Third junk"
66 git commit -m "Third commit for gar/bage" &&
67 # the push should fail with --recurse-submodules=check
68 # on the command line...
69 test_must_fail git push --recurse-submodules=check ../pub.git master &&
71 # ...or if specified in the configuration..
72 test_must_fail git -c push.recurseSubmodules=check push ../pub.git master
76 test_expect_success 'push succeeds after commit was pushed to remote' '
79 git push origin master
83 git push --recurse-submodules=check ../pub.git master
87 test_expect_success 'push succeeds if submodule commit not on remote but using on-demand on command line' '
90 >recurse-on-demand-on-command-line &&
91 git add recurse-on-demand-on-command-line &&
92 git commit -m "Recurse on-demand on command line junk"
97 git commit -m "Recurse on-demand on command line for gar/bage" &&
98 git push --recurse-submodules=on-demand ../pub.git master &&
99 # Check that the supermodule commit got there
100 git fetch ../pub.git &&
101 git diff --quiet FETCH_HEAD master &&
102 # Check that the submodule commit got there too
104 git diff --quiet origin/master master
108 test_expect_success 'push succeeds if submodule commit not on remote but using on-demand from config' '
111 >recurse-on-demand-from-config &&
112 git add recurse-on-demand-from-config &&
113 git commit -m "Recurse on-demand from config junk"
118 git commit -m "Recurse on-demand from config for gar/bage" &&
119 git -c push.recurseSubmodules=on-demand push ../pub.git master &&
120 # Check that the supermodule commit got there
121 git fetch ../pub.git &&
122 git diff --quiet FETCH_HEAD master &&
123 # Check that the submodule commit got there too
125 git diff --quiet origin/master master
129 test_expect_success 'push succeeds if submodule commit not on remote but using auto-on-demand via submodule.recurse config' '
132 >recurse-on-demand-from-submodule-recurse-config &&
133 git add recurse-on-demand-from-submodule-recurse-config &&
134 git commit -m "Recurse submodule.recurse from config junk"
139 git commit -m "Recurse submodule.recurse from config for gar/bage" &&
140 git -c submodule.recurse push ../pub.git master &&
141 # Check that the supermodule commit got there
142 git fetch ../pub.git &&
143 git diff --quiet FETCH_HEAD master &&
144 # Check that the submodule commit got there too
146 git diff --quiet origin/master master
150 test_expect_success 'push recurse-submodules on command line overrides config' '
153 >recurse-check-on-command-line-overriding-config &&
154 git add recurse-check-on-command-line-overriding-config &&
155 git commit -m "Recurse on command-line overriding config junk"
160 git commit -m "Recurse on command-line overriding config for gar/bage" &&
162 # Ensure that we can override on-demand in the config
163 # to just check submodules
164 test_must_fail git -c push.recurseSubmodules=on-demand push --recurse-submodules=check ../pub.git master &&
165 # Check that the supermodule commit did not get there
166 git fetch ../pub.git &&
167 git diff --quiet FETCH_HEAD master^ &&
168 # Check that the submodule commit did not get there
169 (cd gar/bage && git diff --quiet origin/master master^) &&
171 # Ensure that we can override check in the config to
172 # disable submodule recursion entirely
173 (cd gar/bage && git diff --quiet origin/master master^) &&
174 git -c push.recurseSubmodules=on-demand push --recurse-submodules=no ../pub.git master &&
175 git fetch ../pub.git &&
176 git diff --quiet FETCH_HEAD master &&
177 (cd gar/bage && git diff --quiet origin/master master^) &&
179 # Ensure that we can override check in the config to
180 # disable submodule recursion entirely (alternative form)
181 git -c push.recurseSubmodules=on-demand push --no-recurse-submodules ../pub.git master &&
182 git fetch ../pub.git &&
183 git diff --quiet FETCH_HEAD master &&
184 (cd gar/bage && git diff --quiet origin/master master^) &&
186 # Ensure that we can override check in the config to
187 # push the submodule too
188 git -c push.recurseSubmodules=check push --recurse-submodules=on-demand ../pub.git master &&
189 git fetch ../pub.git &&
190 git diff --quiet FETCH_HEAD master &&
191 (cd gar/bage && git diff --quiet origin/master master)
195 test_expect_success 'push recurse-submodules last one wins on command line' '
198 >recurse-check-on-command-line-overriding-earlier-command-line &&
199 git add recurse-check-on-command-line-overriding-earlier-command-line &&
200 git commit -m "Recurse on command-line overridiing earlier command-line junk"
205 git commit -m "Recurse on command-line overriding earlier command-line for gar/bage" &&
207 # should result in "check"
208 test_must_fail git push --recurse-submodules=on-demand --recurse-submodules=check ../pub.git master &&
209 # Check that the supermodule commit did not get there
210 git fetch ../pub.git &&
211 git diff --quiet FETCH_HEAD master^ &&
212 # Check that the submodule commit did not get there
213 (cd gar/bage && git diff --quiet origin/master master^) &&
215 # should result in "no"
216 git push --recurse-submodules=on-demand --recurse-submodules=no ../pub.git master &&
217 # Check that the supermodule commit did get there
218 git fetch ../pub.git &&
219 git diff --quiet FETCH_HEAD master &&
220 # Check that the submodule commit did not get there
221 (cd gar/bage && git diff --quiet origin/master master^) &&
223 # should result in "no"
224 git push --recurse-submodules=on-demand --no-recurse-submodules ../pub.git master &&
225 # Check that the submodule commit did not get there
226 (cd gar/bage && git diff --quiet origin/master master^) &&
228 # But the options in the other order should push the submodule
229 git push --recurse-submodules=check --recurse-submodules=on-demand ../pub.git master &&
230 # Check that the submodule commit did get there
231 git fetch ../pub.git &&
232 (cd gar/bage && git diff --quiet origin/master master)
236 test_expect_success 'push succeeds if submodule commit not on remote using on-demand from cmdline overriding config' '
239 >recurse-on-demand-on-command-line-overriding-config &&
240 git add recurse-on-demand-on-command-line-overriding-config &&
241 git commit -m "Recurse on-demand on command-line overriding config junk"
246 git commit -m "Recurse on-demand on command-line overriding config for gar/bage" &&
247 git -c push.recurseSubmodules=check push --recurse-submodules=on-demand ../pub.git master &&
248 # Check that the supermodule commit got there
249 git fetch ../pub.git &&
250 git diff --quiet FETCH_HEAD master &&
251 # Check that the submodule commit got there
253 git diff --quiet origin/master master
257 test_expect_success 'push succeeds if submodule commit disabling recursion from cmdline overriding config' '
260 >recurse-disable-on-command-line-overriding-config &&
261 git add recurse-disable-on-command-line-overriding-config &&
262 git commit -m "Recurse disable on command-line overriding config junk"
267 git commit -m "Recurse disable on command-line overriding config for gar/bage" &&
268 git -c push.recurseSubmodules=check push --recurse-submodules=no ../pub.git master &&
269 # Check that the supermodule commit got there
270 git fetch ../pub.git &&
271 git diff --quiet FETCH_HEAD master &&
272 # But that the submodule commit did not
273 ( cd gar/bage && git diff --quiet origin/master master^ ) &&
274 # Now push it to avoid confusing future tests
275 git push --recurse-submodules=on-demand ../pub.git master
279 test_expect_success 'push succeeds if submodule commit disabling recursion from cmdline (alternative form) overriding config' '
282 >recurse-disable-on-command-line-alt-overriding-config &&
283 git add recurse-disable-on-command-line-alt-overriding-config &&
284 git commit -m "Recurse disable on command-line alternative overriding config junk"
289 git commit -m "Recurse disable on command-line alternative overriding config for gar/bage" &&
290 git -c push.recurseSubmodules=check push --no-recurse-submodules ../pub.git master &&
291 # Check that the supermodule commit got there
292 git fetch ../pub.git &&
293 git diff --quiet FETCH_HEAD master &&
294 # But that the submodule commit did not
295 ( cd gar/bage && git diff --quiet origin/master master^ ) &&
296 # Now push it to avoid confusing future tests
297 git push --recurse-submodules=on-demand ../pub.git master
301 test_expect_success 'push fails if recurse submodules option passed as yes' '
304 >recurse-push-fails-if-recurse-submodules-passed-as-yes &&
305 git add recurse-push-fails-if-recurse-submodules-passed-as-yes &&
306 git commit -m "Recurse push fails if recurse submodules option passed as yes"
311 git commit -m "Recurse push fails if recurse submodules option passed as yes for gar/bage" &&
312 test_must_fail git push --recurse-submodules=yes ../pub.git master &&
313 test_must_fail git -c push.recurseSubmodules=yes push ../pub.git master &&
314 git push --recurse-submodules=on-demand ../pub.git master
318 test_expect_success 'push fails when commit on multiple branches if one branch has no remote' '
323 git commit -m "Fourth junk"
327 git branch branch2 &&
329 git commit -m "Fourth commit for gar/bage" &&
330 git checkout branch2 &&
337 git commit -m "First junk" &&
338 test_must_fail git push --recurse-submodules=check ../pub.git
342 test_expect_success 'push succeeds if submodule has no remote and is on the first superproject commit' '
352 git commit -m "initial"
355 git commit -m "added submodule" &&
356 git push --recurse-submodule=check origin master
360 test_expect_success 'push unpushed submodules when not needed' '
365 git checkout master &&
368 git commit -m "Fifth junk" &&
370 git rev-parse origin/master >../../../expected
372 git checkout master &&
374 git commit -m "Fifth commit for gar/bage" &&
375 git push --recurse-submodules=on-demand ../pub.git master
379 git rev-parse master >../actual
381 test_cmp expected actual
384 test_expect_success 'push unpushed submodules when not needed 2' '
387 git rev-parse master >../expected
395 git commit -m "Sixth junk"
399 git commit -m "Second junk for work" &&
400 git push --recurse-submodules=on-demand ../pub.git master
404 git rev-parse master >../actual
406 test_cmp expected actual
409 test_expect_success 'push unpushed submodules recursively' '
414 git checkout master &&
417 git commit -m "Seventh junk" &&
418 git rev-parse master >../../../expected
420 git checkout master &&
422 git commit -m "Seventh commit for gar/bage" &&
423 git push --recurse-submodules=on-demand ../pub.git master
427 git rev-parse master >../actual
429 test_cmp expected actual
432 test_expect_success 'push unpushable submodule recursively fails' '
437 git rev-parse origin/master >../../../expected &&
438 git checkout master~0 &&
441 git commit -m "Eighth junk"
444 git commit -m "Eighth commit for gar/bage" &&
445 test_must_fail git push --recurse-submodules=on-demand ../pub.git master
449 git rev-parse master >../actual
451 test_when_finished git -C work reset --hard master^ &&
452 test_cmp expected actual
455 test_expect_success 'push --dry-run does not recursively update submodules' '
458 git checkout master &&
459 git rev-parse master >../../../expected_submodule &&
462 git commit -m "Ninth junk" &&
464 # Go up to 'work' directory
466 git checkout master &&
467 git rev-parse master >../expected_pub &&
469 git commit -m "Ninth commit for gar/bage" &&
470 git push --dry-run --recurse-submodules=on-demand ../pub.git master
472 git -C submodule.git rev-parse master >actual_submodule &&
473 git -C pub.git rev-parse master >actual_pub &&
474 test_cmp expected_pub actual_pub &&
475 test_cmp expected_submodule actual_submodule
478 test_expect_success 'push --dry-run does not recursively update submodules' '
479 git -C work push --dry-run --recurse-submodules=only ../pub.git master &&
481 git -C submodule.git rev-parse master >actual_submodule &&
482 git -C pub.git rev-parse master >actual_pub &&
483 test_cmp expected_pub actual_pub &&
484 test_cmp expected_submodule actual_submodule
487 test_expect_success 'push only unpushed submodules recursively' '
488 git -C work/gar/bage rev-parse master >expected_submodule &&
489 git -C pub.git rev-parse master >expected_pub &&
491 git -C work push --recurse-submodules=only ../pub.git master &&
493 git -C submodule.git rev-parse master >actual_submodule &&
494 git -C pub.git rev-parse master >actual_pub &&
495 test_cmp expected_submodule actual_submodule &&
496 test_cmp expected_pub actual_pub
499 test_expect_success 'push propagating the remotes name to a submodule' '
500 git -C work remote add origin ../pub.git &&
501 git -C work remote add pub ../pub.git &&
503 > work/gar/bage/junk10 &&
504 git -C work/gar/bage add junk10 &&
505 git -C work/gar/bage commit -m "Tenth junk" &&
506 git -C work add gar/bage &&
507 git -C work commit -m "Tenth junk added to gar/bage" &&
509 # Fails when submodule does not have a matching remote
510 test_must_fail git -C work push --recurse-submodules=on-demand pub master &&
511 # Succeeds when submodules has matching remote and refspec
512 git -C work push --recurse-submodules=on-demand origin master &&
514 git -C submodule.git rev-parse master >actual_submodule &&
515 git -C pub.git rev-parse master >actual_pub &&
516 git -C work/gar/bage rev-parse master >expected_submodule &&
517 git -C work rev-parse master >expected_pub &&
518 test_cmp expected_submodule actual_submodule &&
519 test_cmp expected_pub actual_pub
522 test_expect_success 'push propagating refspec to a submodule' '
523 > work/gar/bage/junk11 &&
524 git -C work/gar/bage add junk11 &&
525 git -C work/gar/bage commit -m "Eleventh junk" &&
527 git -C work checkout branch2 &&
528 git -C work add gar/bage &&
529 git -C work commit -m "updating gar/bage in branch2" &&
531 # Fails when submodule does not have a matching branch
532 test_must_fail git -C work push --recurse-submodules=on-demand origin branch2 &&
533 # Fails when refspec includes an object id
534 test_must_fail git -C work push --recurse-submodules=on-demand origin \
535 "$(git -C work rev-parse branch2):refs/heads/branch2" &&
536 # Fails when refspec includes 'HEAD' as it is unsupported at this time
537 test_must_fail git -C work push --recurse-submodules=on-demand origin \
538 HEAD:refs/heads/branch2 &&
540 git -C work/gar/bage branch branch2 master &&
541 git -C work push --recurse-submodules=on-demand origin branch2 &&
543 git -C submodule.git rev-parse branch2 >actual_submodule &&
544 git -C pub.git rev-parse branch2 >actual_pub &&
545 git -C work/gar/bage rev-parse branch2 >expected_submodule &&
546 git -C work rev-parse branch2 >expected_pub &&
547 test_cmp expected_submodule actual_submodule &&
548 test_cmp expected_pub actual_pub