Skip to content

Commit d34141c

Browse files
mikecrowegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f5c7cd9 commit d34141c

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

builtin/push.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ static int thin = 1;
2121
static int deleterefs;
2222
static const char *receivepack;
2323
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;
2526

2627
static struct push_cas_option cas;
2728

@@ -455,9 +456,6 @@ static int option_parse_recurse_submodules(const struct option *opt,
455456
{
456457
int *recurse_submodules = opt->value;
457458

458-
if (*recurse_submodules != RECURSE_SUBMODULES_DEFAULT)
459-
die("%s can only be used once.", opt->long_name);
460-
461459
if (unset)
462460
*recurse_submodules = RECURSE_SUBMODULES_OFF;
463461
else if (arg)
@@ -532,7 +530,6 @@ int cmd_push(int argc, const char **argv, const char *prefix)
532530
int flags = 0;
533531
int tags = 0;
534532
int push_cert = -1;
535-
int recurse_submodules_from_cmdline = RECURSE_SUBMODULES_DEFAULT;
536533
int rc;
537534
const char *repo = NULL; /* default repository */
538535
struct option options[] = {
@@ -550,7 +547,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
550547
0, CAS_OPT_NAME, &cas, N_("refname>:<expect"),
551548
N_("require old value of ref to be at this value"),
552549
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"),
554551
N_("control recursive pushing of submodules"),
555552
PARSE_OPT_OPTARG, option_parse_recurse_submodules },
556553
OPT_BOOL( 0 , "thin", &thin, N_("use thin pack")),
@@ -581,9 +578,6 @@ int cmd_push(int argc, const char **argv, const char *prefix)
581578
if (deleterefs && argc < 2)
582579
die(_("--delete doesn't make sense without any refs"));
583580

584-
if (recurse_submodules_from_cmdline != RECURSE_SUBMODULES_DEFAULT)
585-
recurse_submodules = recurse_submodules_from_cmdline;
586-
587581
if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
588582
flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
589583
else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)

t/t5531-deep-submodule-push.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,47 @@ test_expect_success 'push recurse-submodules on command line overrides config' '
171171
)
172172
'
173173

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+
174215
test_expect_success 'push succeeds if submodule commit not on remote using on-demand from cmdline overriding config' '
175216
(
176217
cd work/gar/bage &&

0 commit comments

Comments
 (0)