721be32b020b88757c7acf5bfdc6998765cbe347
1#!/bin/sh
2
3test_description='unpack-objects'
4
5. ./test-lib.sh
6
7test_expect_success setup '
8 mkdir pub.git &&
9 GIT_DIR=pub.git git init --bare &&
10 GIT_DIR=pub.git git config receive.fsckobjects true &&
11 mkdir work &&
12 (
13 cd work &&
14 git init &&
15 git config push.default matching &&
16 mkdir -p gar/bage &&
17 (
18 cd gar/bage &&
19 git init &&
20 git config push.default matching &&
21 >junk &&
22 git add junk &&
23 git commit -m "Initial junk"
24 ) &&
25 git add gar/bage &&
26 git commit -m "Initial superproject"
27 )
28'
29
30test_expect_success push '
31 (
32 cd work &&
33 git push ../pub.git master
34 )
35'
36
37test_expect_success 'push if submodule has no remote' '
38 (
39 cd work/gar/bage &&
40 >junk2 &&
41 git add junk2 &&
42 git commit -m "Second junk"
43 ) &&
44 (
45 cd work &&
46 git add gar/bage &&
47 git commit -m "Second commit for gar/bage" &&
48 git push --recurse-submodules=check ../pub.git master
49 )
50'
51
52test_expect_success 'push fails if submodule commit not on remote' '
53 (
54 cd work/gar &&
55 git clone --bare bage ../../submodule.git &&
56 cd bage &&
57 git remote add origin ../../../submodule.git &&
58 git fetch &&
59 >junk3 &&
60 git add junk3 &&
61 git commit -m "Third junk"
62 ) &&
63 (
64 cd work &&
65 git add gar/bage &&
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 &&
70
71 # ...or if specified in the configuration..
72 test_must_fail git -c push.recurseSubmodules=check push ../pub.git master
73 )
74'
75
76test_expect_success 'push succeeds after commit was pushed to remote' '
77 (
78 cd work/gar/bage &&
79 git push origin master
80 ) &&
81 (
82 cd work &&
83 git push --recurse-submodules=check ../pub.git master
84 )
85'
86
87test_expect_success 'push succeeds if submodule commit not on remote but using on-demand on command line' '
88 (
89 cd work/gar/bage &&
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"
93 ) &&
94 (
95 cd work &&
96 git add gar/bage &&
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
103 cd gar/bage &&
104 git diff --quiet origin/master master
105 )
106'
107
108test_expect_success 'push succeeds if submodule commit not on remote but using on-demand from config' '
109 (
110 cd work/gar/bage &&
111 >recurse-on-demand-from-config &&
112 git add recurse-on-demand-from-config &&
113 git commit -m "Recurse on-demand from config junk"
114 ) &&
115 (
116 cd work &&
117 git add gar/bage &&
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
124 cd gar/bage &&
125 git diff --quiet origin/master master
126 )
127'
128
129test_expect_success 'push recurse-submodules on command line overrides config' '
130 (
131 cd work/gar/bage &&
132 >recurse-check-on-command-line-overriding-config &&
133 git add recurse-check-on-command-line-overriding-config &&
134 git commit -m "Recurse on command-line overriding config junk"
135 ) &&
136 (
137 cd work &&
138 git add gar/bage &&
139 git commit -m "Recurse on command-line overriding config for gar/bage" &&
140
141 # Ensure that we can override on-demand in the config
142 # to just check submodules
143 test_must_fail git -c push.recurseSubmodules=on-demand push --recurse-submodules=check ../pub.git master &&
144 # Check that the supermodule commit did not get there
145 git fetch ../pub.git &&
146 git diff --quiet FETCH_HEAD master^ &&
147 # Check that the submodule commit did not get there
148 (cd gar/bage && git diff --quiet origin/master master^) &&
149
150 # Ensure that we can override check in the config to
151 # disable submodule recursion entirely
152 (cd gar/bage && git diff --quiet origin/master master^) &&
153 git -c push.recurseSubmodules=on-demand push --recurse-submodules=no ../pub.git master &&
154 git fetch ../pub.git &&
155 git diff --quiet FETCH_HEAD master &&
156 (cd gar/bage && git diff --quiet origin/master master^) &&
157
158 # Ensure that we can override check in the config to
159 # disable submodule recursion entirely (alternative form)
160 git -c push.recurseSubmodules=on-demand push --no-recurse-submodules ../pub.git master &&
161 git fetch ../pub.git &&
162 git diff --quiet FETCH_HEAD master &&
163 (cd gar/bage && git diff --quiet origin/master master^) &&
164
165 # Ensure that we can override check in the config to
166 # push the submodule too
167 git -c push.recurseSubmodules=check push --recurse-submodules=on-demand ../pub.git master &&
168 git fetch ../pub.git &&
169 git diff --quiet FETCH_HEAD master &&
170 (cd gar/bage && git diff --quiet origin/master master)
171 )
172'
173
174test_expect_success 'push succeeds if submodule commit not on remote using on-demand from cmdline overriding config' '
175 (
176 cd work/gar/bage &&
177 >recurse-on-demand-on-command-line-overriding-config &&
178 git add recurse-on-demand-on-command-line-overriding-config &&
179 git commit -m "Recurse on-demand on command-line overriding config junk"
180 ) &&
181 (
182 cd work &&
183 git add gar/bage &&
184 git commit -m "Recurse on-demand on command-line overriding config for gar/bage" &&
185 git -c push.recurseSubmodules=check push --recurse-submodules=on-demand ../pub.git master &&
186 # Check that the supermodule commit got there
187 git fetch ../pub.git &&
188 git diff --quiet FETCH_HEAD master &&
189 # Check that the submodule commit got there
190 cd gar/bage &&
191 git diff --quiet origin/master master
192 )
193'
194
195test_expect_success 'push succeeds if submodule commit disabling recursion from cmdline overriding config' '
196 (
197 cd work/gar/bage &&
198 >recurse-disable-on-command-line-overriding-config &&
199 git add recurse-disable-on-command-line-overriding-config &&
200 git commit -m "Recurse disable on command-line overriding config junk"
201 ) &&
202 (
203 cd work &&
204 git add gar/bage &&
205 git commit -m "Recurse disable on command-line overriding config for gar/bage" &&
206 git -c push.recurseSubmodules=check push --recurse-submodules=no ../pub.git master &&
207 # Check that the supermodule commit got there
208 git fetch ../pub.git &&
209 git diff --quiet FETCH_HEAD master &&
210 # But that the submodule commit did not
211 ( cd gar/bage && git diff --quiet origin/master master^ ) &&
212 # Now push it to avoid confusing future tests
213 git push --recurse-submodules=on-demand ../pub.git master
214 )
215'
216
217test_expect_success 'push succeeds if submodule commit disabling recursion from cmdline (alternative form) overriding config' '
218 (
219 cd work/gar/bage &&
220 >recurse-disable-on-command-line-alt-overriding-config &&
221 git add recurse-disable-on-command-line-alt-overriding-config &&
222 git commit -m "Recurse disable on command-line alternative overriding config junk"
223 ) &&
224 (
225 cd work &&
226 git add gar/bage &&
227 git commit -m "Recurse disable on command-line alternative overriding config for gar/bage" &&
228 git -c push.recurseSubmodules=check push --no-recurse-submodules ../pub.git master &&
229 # Check that the supermodule commit got there
230 git fetch ../pub.git &&
231 git diff --quiet FETCH_HEAD master &&
232 # But that the submodule commit did not
233 ( cd gar/bage && git diff --quiet origin/master master^ ) &&
234 # Now push it to avoid confusing future tests
235 git push --recurse-submodules=on-demand ../pub.git master
236 )
237'
238
239test_expect_success 'push fails if recurse submodules option passed as yes' '
240 (
241 cd work/gar/bage &&
242 >recurse-push-fails-if-recurse-submodules-passed-as-yes &&
243 git add recurse-push-fails-if-recurse-submodules-passed-as-yes &&
244 git commit -m "Recurse push fails if recurse submodules option passed as yes"
245 ) &&
246 (
247 cd work &&
248 git add gar/bage &&
249 git commit -m "Recurse push fails if recurse submodules option passed as yes for gar/bage" &&
250 test_must_fail git push --recurse-submodules=yes ../pub.git master &&
251 test_must_fail git -c push.recurseSubmodules=yes push ../pub.git master &&
252 git push --recurse-submodules=on-demand ../pub.git master
253 )
254'
255
256test_expect_success 'push fails when commit on multiple branches if one branch has no remote' '
257 (
258 cd work/gar/bage &&
259 >junk4 &&
260 git add junk4 &&
261 git commit -m "Fourth junk"
262 ) &&
263 (
264 cd work &&
265 git branch branch2 &&
266 git add gar/bage &&
267 git commit -m "Fourth commit for gar/bage" &&
268 git checkout branch2 &&
269 (
270 cd gar/bage &&
271 git checkout HEAD~1
272 ) &&
273 >junk1 &&
274 git add junk1 &&
275 git commit -m "First junk" &&
276 test_must_fail git push --recurse-submodules=check ../pub.git
277 )
278'
279
280test_expect_success 'push succeeds if submodule has no remote and is on the first superproject commit' '
281 git init --bare a &&
282 git clone a a1 &&
283 (
284 cd a1 &&
285 git init b
286 (
287 cd b &&
288 >junk &&
289 git add junk &&
290 git commit -m "initial"
291 ) &&
292 git add b &&
293 git commit -m "added submodule" &&
294 git push --recurse-submodule=check origin master
295 )
296'
297
298test_expect_success 'push unpushed submodules when not needed' '
299 (
300 cd work &&
301 (
302 cd gar/bage &&
303 git checkout master &&
304 >junk5 &&
305 git add junk5 &&
306 git commit -m "Fifth junk" &&
307 git push &&
308 git rev-parse origin/master >../../../expected
309 ) &&
310 git checkout master &&
311 git add gar/bage &&
312 git commit -m "Fifth commit for gar/bage" &&
313 git push --recurse-submodules=on-demand ../pub.git master
314 ) &&
315 (
316 cd submodule.git &&
317 git rev-parse master >../actual
318 ) &&
319 test_cmp expected actual
320'
321
322test_expect_success 'push unpushed submodules when not needed 2' '
323 (
324 cd submodule.git &&
325 git rev-parse master >../expected
326 ) &&
327 (
328 cd work &&
329 (
330 cd gar/bage &&
331 >junk6 &&
332 git add junk6 &&
333 git commit -m "Sixth junk"
334 ) &&
335 >junk2 &&
336 git add junk2 &&
337 git commit -m "Second junk for work" &&
338 git push --recurse-submodules=on-demand ../pub.git master
339 ) &&
340 (
341 cd submodule.git &&
342 git rev-parse master >../actual
343 ) &&
344 test_cmp expected actual
345'
346
347test_expect_success 'push unpushed submodules recursively' '
348 (
349 cd work &&
350 (
351 cd gar/bage &&
352 git checkout master &&
353 > junk7 &&
354 git add junk7 &&
355 git commit -m "Seventh junk" &&
356 git rev-parse master >../../../expected
357 ) &&
358 git checkout master &&
359 git add gar/bage &&
360 git commit -m "Seventh commit for gar/bage" &&
361 git push --recurse-submodules=on-demand ../pub.git master
362 ) &&
363 (
364 cd submodule.git &&
365 git rev-parse master >../actual
366 ) &&
367 test_cmp expected actual
368'
369
370test_expect_success 'push unpushable submodule recursively fails' '
371 (
372 cd work &&
373 (
374 cd gar/bage &&
375 git rev-parse origin/master >../../../expected &&
376 git checkout master~0 &&
377 > junk8 &&
378 git add junk8 &&
379 git commit -m "Eighth junk"
380 ) &&
381 git add gar/bage &&
382 git commit -m "Eighth commit for gar/bage" &&
383 test_must_fail git push --recurse-submodules=on-demand ../pub.git master
384 ) &&
385 (
386 cd submodule.git &&
387 git rev-parse master >../actual
388 ) &&
389 test_cmp expected actual
390'
391
392test_done