3 test_description='unpack-objects'
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 '
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. "check" is the default for repos in
69 # which submodules are detected by existence of config,
70 # .gitmodules file or an internal .git/modules/<submodule-repo>
71 git submodule add -f ../submodule.git gar/bage &&
72 test_must_fail git push ../pub.git master &&
73 test_must_fail git push --recurse-submodules=check ../pub.git master &&
75 # ...or if specified in the configuration..
76 test_must_fail git -c push.recurseSubmodules=check push ../pub.git master
80 test_expect_success 'push succeeds after commit was pushed to remote' '
83 git push origin master
87 git push --recurse-submodules=check ../pub.git master
91 test_expect_success 'push succeeds if submodule commit not on remote but using on-demand on command line' '
94 >recurse-on-demand-on-command-line &&
95 git add recurse-on-demand-on-command-line &&
96 git commit -m "Recurse on-demand on command line junk"
101 git commit -m "Recurse on-demand on command line for gar/bage" &&
102 git push --recurse-submodules=on-demand ../pub.git master &&
103 # Check that the supermodule commit got there
104 git fetch ../pub.git &&
105 git diff --quiet FETCH_HEAD master &&
106 # Check that the submodule commit got there too
108 git diff --quiet origin/master master
112 test_expect_success 'push succeeds if submodule commit not on remote but using on-demand from config' '
115 >recurse-on-demand-from-config &&
116 git add recurse-on-demand-from-config &&
117 git commit -m "Recurse on-demand from config junk"
122 git commit -m "Recurse on-demand from config for gar/bage" &&
123 git -c push.recurseSubmodules=on-demand push ../pub.git master &&
124 # Check that the supermodule commit got there
125 git fetch ../pub.git &&
126 git diff --quiet FETCH_HEAD master &&
127 # Check that the submodule commit got there too
129 git diff --quiet origin/master master
133 test_expect_success 'push recurse-submodules on command line overrides config' '
136 >recurse-check-on-command-line-overriding-config &&
137 git add recurse-check-on-command-line-overriding-config &&
138 git commit -m "Recurse on command-line overriding config junk"
143 git commit -m "Recurse on command-line overriding config for gar/bage" &&
145 # Ensure that we can override on-demand in the config
146 # to just check submodules
147 test_must_fail git -c push.recurseSubmodules=on-demand push --recurse-submodules=check ../pub.git master &&
148 # Check that the supermodule commit did not get there
149 git fetch ../pub.git &&
150 git diff --quiet FETCH_HEAD master^ &&
151 # Check that the submodule commit did not get there
152 (cd gar/bage && git diff --quiet origin/master master^) &&
154 # Ensure that we can override check in the config to
155 # disable submodule recursion entirely
156 (cd gar/bage && git diff --quiet origin/master master^) &&
157 git -c push.recurseSubmodules=on-demand push --recurse-submodules=no ../pub.git master &&
158 git fetch ../pub.git &&
159 git diff --quiet FETCH_HEAD master &&
160 (cd gar/bage && git diff --quiet origin/master master^) &&
162 # Ensure that we can override check in the config to
163 # disable submodule recursion entirely (alternative form)
164 git -c push.recurseSubmodules=on-demand push --no-recurse-submodules ../pub.git master &&
165 git fetch ../pub.git &&
166 git diff --quiet FETCH_HEAD master &&
167 (cd gar/bage && git diff --quiet origin/master master^) &&
169 # Ensure that we can override check in the config to
170 # push the submodule too
171 git -c push.recurseSubmodules=check push --recurse-submodules=on-demand ../pub.git master &&
172 git fetch ../pub.git &&
173 git diff --quiet FETCH_HEAD master &&
174 (cd gar/bage && git diff --quiet origin/master master)
178 test_expect_success 'push recurse-submodules last one wins on command line' '
181 >recurse-check-on-command-line-overriding-earlier-command-line &&
182 git add recurse-check-on-command-line-overriding-earlier-command-line &&
183 git commit -m "Recurse on command-line overridiing earlier command-line junk"
188 git commit -m "Recurse on command-line overriding earlier command-line for gar/bage" &&
190 # should result in "check"
191 test_must_fail git push --recurse-submodules=on-demand --recurse-submodules=check ../pub.git master &&
192 # Check that the supermodule commit did not get there
193 git fetch ../pub.git &&
194 git diff --quiet FETCH_HEAD master^ &&
195 # Check that the submodule commit did not get there
196 (cd gar/bage && git diff --quiet origin/master master^) &&
198 # should result in "no"
199 git push --recurse-submodules=on-demand --recurse-submodules=no ../pub.git master &&
200 # Check that the supermodule commit did get there
201 git fetch ../pub.git &&
202 git diff --quiet FETCH_HEAD master &&
203 # Check that the submodule commit did not get there
204 (cd gar/bage && git diff --quiet origin/master master^) &&
206 # should result in "no"
207 git push --recurse-submodules=on-demand --no-recurse-submodules ../pub.git master &&
208 # Check that the submodule commit did not get there
209 (cd gar/bage && git diff --quiet origin/master master^) &&
211 # But the options in the other order should push the submodule
212 git push --recurse-submodules=check --recurse-submodules=on-demand ../pub.git master &&
213 # Check that the submodule commit did get there
214 git fetch ../pub.git &&
215 (cd gar/bage && git diff --quiet origin/master master)
219 test_expect_success 'push succeeds if submodule commit not on remote using on-demand from cmdline overriding config' '
222 >recurse-on-demand-on-command-line-overriding-config &&
223 git add recurse-on-demand-on-command-line-overriding-config &&
224 git commit -m "Recurse on-demand on command-line overriding config junk"
229 git commit -m "Recurse on-demand on command-line overriding config for gar/bage" &&
230 git -c push.recurseSubmodules=check push --recurse-submodules=on-demand ../pub.git master &&
231 # Check that the supermodule commit got there
232 git fetch ../pub.git &&
233 git diff --quiet FETCH_HEAD master &&
234 # Check that the submodule commit got there
236 git diff --quiet origin/master master
240 test_expect_success 'push succeeds if submodule commit disabling recursion from cmdline overriding config' '
243 >recurse-disable-on-command-line-overriding-config &&
244 git add recurse-disable-on-command-line-overriding-config &&
245 git commit -m "Recurse disable on command-line overriding config junk"
250 git commit -m "Recurse disable on command-line overriding config for gar/bage" &&
251 git -c push.recurseSubmodules=check push --recurse-submodules=no ../pub.git master &&
252 # Check that the supermodule commit got there
253 git fetch ../pub.git &&
254 git diff --quiet FETCH_HEAD master &&
255 # But that the submodule commit did not
256 ( cd gar/bage && git diff --quiet origin/master master^ ) &&
257 # Now push it to avoid confusing future tests
258 git push --recurse-submodules=on-demand ../pub.git master
262 test_expect_success 'push succeeds if submodule commit disabling recursion from cmdline (alternative form) overriding config' '
265 >recurse-disable-on-command-line-alt-overriding-config &&
266 git add recurse-disable-on-command-line-alt-overriding-config &&
267 git commit -m "Recurse disable on command-line alternative overriding config junk"
272 git commit -m "Recurse disable on command-line alternative overriding config for gar/bage" &&
273 git -c push.recurseSubmodules=check push --no-recurse-submodules ../pub.git master &&
274 # Check that the supermodule commit got there
275 git fetch ../pub.git &&
276 git diff --quiet FETCH_HEAD master &&
277 # But that the submodule commit did not
278 ( cd gar/bage && git diff --quiet origin/master master^ ) &&
279 # Now push it to avoid confusing future tests
280 git push --recurse-submodules=on-demand ../pub.git master
284 test_expect_success 'push fails if recurse submodules option passed as yes' '
287 >recurse-push-fails-if-recurse-submodules-passed-as-yes &&
288 git add recurse-push-fails-if-recurse-submodules-passed-as-yes &&
289 git commit -m "Recurse push fails if recurse submodules option passed as yes"
294 git commit -m "Recurse push fails if recurse submodules option passed as yes for gar/bage" &&
295 test_must_fail git push --recurse-submodules=yes ../pub.git master &&
296 test_must_fail git -c push.recurseSubmodules=yes push ../pub.git master &&
297 git push --recurse-submodules=on-demand ../pub.git master
301 test_expect_success 'push fails when commit on multiple branches if one branch has no remote' '
306 git commit -m "Fourth junk"
310 git branch branch2 &&
312 git commit -m "Fourth commit for gar/bage" &&
313 git checkout branch2 &&
320 git commit -m "First junk" &&
321 test_must_fail git push --recurse-submodules=check ../pub.git
325 test_expect_success 'push succeeds if submodule has no remote and is on the first superproject commit' '
335 git commit -m "initial"
338 git commit -m "added submodule" &&
339 git push --recurse-submodule=check origin master
343 test_expect_success 'push unpushed submodules when not needed' '
348 git checkout master &&
351 git commit -m "Fifth junk" &&
353 git rev-parse origin/master >../../../expected
355 git checkout master &&
357 git commit -m "Fifth commit for gar/bage" &&
358 git push --recurse-submodules=on-demand ../pub.git master
362 git rev-parse master >../actual
364 test_cmp expected actual
367 test_expect_success 'push unpushed submodules when not needed 2' '
370 git rev-parse master >../expected
378 git commit -m "Sixth junk"
382 git commit -m "Second junk for work" &&
383 git push --recurse-submodules=on-demand ../pub.git master
387 git rev-parse master >../actual
389 test_cmp expected actual
392 test_expect_success 'push unpushed submodules recursively' '
397 git checkout master &&
400 git commit -m "Seventh junk" &&
401 git rev-parse master >../../../expected
403 git checkout master &&
405 git commit -m "Seventh commit for gar/bage" &&
406 git push --recurse-submodules=on-demand ../pub.git master
410 git rev-parse master >../actual
412 test_cmp expected actual
415 test_expect_success 'push unpushable submodule recursively fails' '
420 git rev-parse origin/master >../../../expected &&
421 git checkout master~0 &&
424 git commit -m "Eighth junk"
427 git commit -m "Eighth commit for gar/bage" &&
428 test_must_fail git push --recurse-submodules=on-demand ../pub.git master
432 git rev-parse master >../actual
434 test_when_finished git -C work reset --hard master^ &&
435 test_cmp expected actual
438 test_expect_success 'push --dry-run does not recursively update submodules' '
441 git checkout master &&
442 git rev-parse master >../../../expected_submodule &&
445 git commit -m "Ninth junk" &&
447 # Go up to 'work' directory
449 git checkout master &&
450 git rev-parse master >../expected_pub &&
452 git commit -m "Ninth commit for gar/bage" &&
453 git push --dry-run --recurse-submodules=on-demand ../pub.git master
455 git -C submodule.git rev-parse master >actual_submodule &&
456 git -C pub.git rev-parse master >actual_pub &&
457 test_cmp expected_pub actual_pub &&
458 test_cmp expected_submodule actual_submodule