sequencer: allow to --skip current commit
[git] / t / t5531-deep-submodule-push.sh
1 #!/bin/sh
2
3 test_description='unpack-objects'
4
5 . ./test-lib.sh
6
7 test_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
30 test_expect_success push '
31         (
32                 cd work &&
33                 git push ../pub.git master
34         )
35 '
36
37 test_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
52 test_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. "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 &&
74
75                 # ...or if specified in the configuration..
76                 test_must_fail git -c push.recurseSubmodules=check push ../pub.git master
77         )
78 '
79
80 test_expect_success 'push succeeds after commit was pushed to remote' '
81         (
82                 cd work/gar/bage &&
83                 git push origin master
84         ) &&
85         (
86                 cd work &&
87                 git push --recurse-submodules=check ../pub.git master
88         )
89 '
90
91 test_expect_success 'push succeeds if submodule commit not on remote but using on-demand on command line' '
92         (
93                 cd work/gar/bage &&
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"
97         ) &&
98         (
99                 cd work &&
100                 git add gar/bage &&
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
107                 cd gar/bage &&
108                 git diff --quiet origin/master master
109         )
110 '
111
112 test_expect_success 'push succeeds if submodule commit not on remote but using on-demand from config' '
113         (
114                 cd work/gar/bage &&
115                 >recurse-on-demand-from-config &&
116                 git add recurse-on-demand-from-config &&
117                 git commit -m "Recurse on-demand from config junk"
118         ) &&
119         (
120                 cd work &&
121                 git add gar/bage &&
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
128                 cd gar/bage &&
129                 git diff --quiet origin/master master
130         )
131 '
132
133 test_expect_success 'push recurse-submodules on command line overrides config' '
134         (
135                 cd work/gar/bage &&
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"
139         ) &&
140         (
141                 cd work &&
142                 git add gar/bage &&
143                 git commit -m "Recurse on command-line overriding config for gar/bage" &&
144
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^) &&
153
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^) &&
161
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^) &&
168
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)
175         )
176 '
177
178 test_expect_success 'push recurse-submodules last one wins on command line' '
179         (
180                 cd work/gar/bage &&
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"
184         ) &&
185         (
186                 cd work &&
187                 git add gar/bage &&
188                 git commit -m "Recurse on command-line overriding earlier command-line for gar/bage" &&
189
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^) &&
197
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^) &&
205
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^) &&
210
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)
216         )
217 '
218
219 test_expect_success 'push succeeds if submodule commit not on remote using on-demand from cmdline overriding config' '
220         (
221                 cd work/gar/bage &&
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"
225         ) &&
226         (
227                 cd work &&
228                 git add gar/bage &&
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
235                 cd gar/bage &&
236                 git diff --quiet origin/master master
237         )
238 '
239
240 test_expect_success 'push succeeds if submodule commit disabling recursion from cmdline overriding config' '
241         (
242                 cd work/gar/bage &&
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"
246         ) &&
247         (
248                 cd work &&
249                 git add gar/bage &&
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
259         )
260 '
261
262 test_expect_success 'push succeeds if submodule commit disabling recursion from cmdline (alternative form) overriding config' '
263         (
264                 cd work/gar/bage &&
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"
268         ) &&
269         (
270                 cd work &&
271                 git add gar/bage &&
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
281         )
282 '
283
284 test_expect_success 'push fails if recurse submodules option passed as yes' '
285         (
286                 cd work/gar/bage &&
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"
290         ) &&
291         (
292                 cd work &&
293                 git add gar/bage &&
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
298         )
299 '
300
301 test_expect_success 'push fails when commit on multiple branches if one branch has no remote' '
302         (
303                 cd work/gar/bage &&
304                 >junk4 &&
305                 git add junk4 &&
306                 git commit -m "Fourth junk"
307         ) &&
308         (
309                 cd work &&
310                 git branch branch2 &&
311                 git add gar/bage &&
312                 git commit -m "Fourth commit for gar/bage" &&
313                 git checkout branch2 &&
314                 (
315                         cd gar/bage &&
316                         git checkout HEAD~1
317                 ) &&
318                 >junk1 &&
319                 git add junk1 &&
320                 git commit -m "First junk" &&
321                 test_must_fail git push --recurse-submodules=check ../pub.git
322         )
323 '
324
325 test_expect_success 'push succeeds if submodule has no remote and is on the first superproject commit' '
326         git init --bare a &&
327         git clone a a1 &&
328         (
329                 cd a1 &&
330                 git init b
331                 (
332                         cd b &&
333                         >junk &&
334                         git add junk &&
335                         git commit -m "initial"
336                 ) &&
337                 git add b &&
338                 git commit -m "added submodule" &&
339                 git push --recurse-submodule=check origin master
340         )
341 '
342
343 test_expect_success 'push unpushed submodules when not needed' '
344         (
345                 cd work &&
346                 (
347                         cd gar/bage &&
348                         git checkout master &&
349                         >junk5 &&
350                         git add junk5 &&
351                         git commit -m "Fifth junk" &&
352                         git push &&
353                         git rev-parse origin/master >../../../expected
354                 ) &&
355                 git checkout master &&
356                 git add gar/bage &&
357                 git commit -m "Fifth commit for gar/bage" &&
358                 git push --recurse-submodules=on-demand ../pub.git master
359         ) &&
360         (
361                 cd submodule.git &&
362                 git rev-parse master >../actual
363         ) &&
364         test_cmp expected actual
365 '
366
367 test_expect_success 'push unpushed submodules when not needed 2' '
368         (
369                 cd submodule.git &&
370                 git rev-parse master >../expected
371         ) &&
372         (
373                 cd work &&
374                 (
375                         cd gar/bage &&
376                         >junk6 &&
377                         git add junk6 &&
378                         git commit -m "Sixth junk"
379                 ) &&
380                 >junk2 &&
381                 git add junk2 &&
382                 git commit -m "Second junk for work" &&
383                 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
392 test_expect_success 'push unpushed submodules recursively' '
393         (
394                 cd work &&
395                 (
396                         cd gar/bage &&
397                         git checkout master &&
398                         > junk7 &&
399                         git add junk7 &&
400                         git commit -m "Seventh junk" &&
401                         git rev-parse master >../../../expected
402                 ) &&
403                 git checkout master &&
404                 git add gar/bage &&
405                 git commit -m "Seventh commit for gar/bage" &&
406                 git push --recurse-submodules=on-demand ../pub.git master
407         ) &&
408         (
409                 cd submodule.git &&
410                 git rev-parse master >../actual
411         ) &&
412         test_cmp expected actual
413 '
414
415 test_expect_success 'push unpushable submodule recursively fails' '
416         (
417                 cd work &&
418                 (
419                         cd gar/bage &&
420                         git rev-parse origin/master >../../../expected &&
421                         git checkout master~0 &&
422                         > junk8 &&
423                         git add junk8 &&
424                         git commit -m "Eighth junk"
425                 ) &&
426                 git add gar/bage &&
427                 git commit -m "Eighth commit for gar/bage" &&
428                 test_must_fail git push --recurse-submodules=on-demand ../pub.git master
429         ) &&
430         (
431                 cd submodule.git &&
432                 git rev-parse master >../actual
433         ) &&
434         test_when_finished git -C work reset --hard master^ &&
435         test_cmp expected actual
436 '
437
438 test_expect_success 'push --dry-run does not recursively update submodules' '
439         (
440                 cd work/gar/bage &&
441                 git checkout master &&
442                 git rev-parse master >../../../expected_submodule &&
443                 > junk9 &&
444                 git add junk9 &&
445                 git commit -m "Ninth junk" &&
446
447                 # Go up to 'work' directory
448                 cd ../.. &&
449                 git checkout master &&
450                 git rev-parse master >../expected_pub &&
451                 git add gar/bage &&
452                 git commit -m "Ninth commit for gar/bage" &&
453                 git push --dry-run --recurse-submodules=on-demand ../pub.git master
454         ) &&
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
459 '
460
461 test_done