push: follow the "last one wins" convention for --recurse-submodules
Use the "last one wins" convention for --recurse-submodules rather than treating conflicting options as an error. Also, fix the declaration of the file-scope recurse_submodules global variable to put it on a separate line. Signed-off-by: Mike Crowe <mac@mcrowe.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Mike Crowe committed
Dec 3, 2015 at 13:10 UTC
d34141cd08fb1c6938eae329a7c3122b05e9eb01
2 files changed
+44
-9
builtin/push.c
+3
-9
@@ -21,7 +21,8 @@ static int thin = 1;
21
static int deleterefs;
22
static const char *receivepack;
23
static int verbosity;
24
-static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
24
+static int progress = -1;
25
+static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
26
27
static struct push_cas_option cas;
28
@@ -455,9 +456,6 @@ static int option_parse_recurse_submodules(const struct option *opt,
456
{
457
int *recurse_submodules = opt->value;
458
458
- if (*recurse_submodules != RECURSE_SUBMODULES_DEFAULT)
459
- die("%s can only be used once.", opt->long_name);
460
-
459
if (unset)
460
*recurse_submodules = RECURSE_SUBMODULES_OFF;
461
else if (arg)
@@ -532,7 +530,6 @@ int cmd_push(int argc, const char **argv, const char *prefix)
530
int flags = 0;
531
int tags = 0;
532
int push_cert = -1;
535
- int recurse_submodules_from_cmdline = RECURSE_SUBMODULES_DEFAULT;
533
int rc;
534
const char *repo = NULL; /* default repository */
535
struct option options[] = {
@@ -550,7 +547,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
547
0, CAS_OPT_NAME, &cas, N_("refname>:<expect"),
548
N_("require old value of ref to be at this value"),
549
PARSE_OPT_OPTARG, parseopt_push_cas_option },
553
- { OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules_from_cmdline, N_("check|on-demand|no"),
550
+ { OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules, N_("check|on-demand|no"),
551
N_("control recursive pushing of submodules"),
552
PARSE_OPT_OPTARG, option_parse_recurse_submodules },
553
OPT_BOOL( 0 , "thin", &thin, N_("use thin pack")),
@@ -581,9 +578,6 @@ int cmd_push(int argc, const char **argv, const char *prefix)
578
if (deleterefs && argc < 2)
579
die(_("--delete doesn't make sense without any refs"));
580
584
- if (recurse_submodules_from_cmdline != RECURSE_SUBMODULES_DEFAULT)
585
- recurse_submodules = recurse_submodules_from_cmdline;
586
-
581
if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
582
flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
583
else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
t/t5531-deep-submodule-push.sh
+41
@@ -171,6 +171,47 @@ test_expect_success 'push recurse-submodules on command line overrides config' '
171
)
172
'
173
174
+test_expect_success 'push recurse-submodules last one wins on command line' '
175
+ (
176
+ cd work/gar/bage &&
177
+ >recurse-check-on-command-line-overriding-earlier-command-line &&
178
+ git add recurse-check-on-command-line-overriding-earlier-command-line &&
179
+ git commit -m "Recurse on command-line overridiing earlier command-line junk"
180
+ ) &&
181
+ (
182
+ cd work &&
183
+ git add gar/bage &&
184
+ git commit -m "Recurse on command-line overriding earlier command-line for gar/bage" &&
185
+
186
+ # should result in "check"
187
+ test_must_fail git push --recurse-submodules=on-demand --recurse-submodules=check ../pub.git master &&
188
+ # Check that the supermodule commit did not get there
189
+ git fetch ../pub.git &&
190
+ git diff --quiet FETCH_HEAD master^ &&
191
+ # Check that the submodule commit did not get there
192
+ (cd gar/bage && git diff --quiet origin/master master^) &&
193
+
194
+ # should result in "no"
195
+ git push --recurse-submodules=on-demand --recurse-submodules=no ../pub.git master &&
196
+ # Check that the supermodule commit did get there
197
+ git fetch ../pub.git &&
198
+ git diff --quiet FETCH_HEAD master &&
199
+ # Check that the submodule commit did not get there
200
+ (cd gar/bage && git diff --quiet origin/master master^) &&
201
+
202
+ # should result in "no"
203
+ git push --recurse-submodules=on-demand --no-recurse-submodules ../pub.git master &&
204
+ # Check that the submodule commit did not get there
205
+ (cd gar/bage && git diff --quiet origin/master master^) &&
206
+
207
+ # But the options in the other order should push the submodule
208
+ git push --recurse-submodules=check --recurse-submodules=on-demand ../pub.git master &&
209
+ # Check that the submodule commit did get there
210
+ git fetch ../pub.git &&
211
+ (cd gar/bage && git diff --quiet origin/master master)
212
+ )
213
+'
214
+
215
test_expect_success 'push succeeds if submodule commit not on remote using on-demand from cmdline overriding config' '
216
(
217
cd work/gar/bage &&