Skip to content

Commit 5d35d72

Browse files
committed
Merge branch 'mc/push-recurse-submodules-config'
Add new config to avoid typing "--recurse-submodules" on each push. * mc/push-recurse-submodules-config: push: follow the "last one wins" convention for --recurse-submodules push: test that --recurse-submodules on command line overrides config push: add recurseSubmodules config option
2 parents c3ee2e2 + d34141c commit 5d35d72

File tree

7 files changed

+294
-27
lines changed

7 files changed

+294
-27
lines changed

Documentation/config.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,20 @@ push.gpgSign::
22292229
override a value from a lower-priority config file. An explicit
22302230
command-line flag always overrides this config option.
22312231

2232+
push.recurseSubmodules::
2233+
Make sure all submodule commits used by the revisions to be pushed
2234+
are available on a remote-tracking branch. If the value is 'check'
2235+
then Git will verify that all submodule commits that changed in the
2236+
revisions to be pushed are available on at least one remote of the
2237+
submodule. If any commits are missing, the push will be aborted and
2238+
exit with non-zero status. If the value is 'on-demand' then all
2239+
submodules that changed in the revisions to be pushed will be
2240+
pushed. If on-demand was not able to push all necessary revisions
2241+
it will also be aborted and exit with non-zero status. If the value
2242+
is 'no' then default behavior of ignoring submodules when pushing
2243+
is retained. You may override this configuration at time of push by
2244+
specifying '--recurse-submodules=check|on-demand|no'.
2245+
22322246
rebase.stat::
22332247
Whether to show a diffstat of what changed upstream since the last
22342248
rebase. False by default.

Documentation/git-push.txt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,20 @@ origin +master` to force a push to the `master` branch). See the
257257
is specified. This flag forces progress status even if the
258258
standard error stream is not directed to a terminal.
259259

260-
--recurse-submodules=check|on-demand::
261-
Make sure all submodule commits used by the revisions to be
262-
pushed are available on a remote-tracking branch. If 'check' is
263-
used Git will verify that all submodule commits that changed in
264-
the revisions to be pushed are available on at least one remote
265-
of the submodule. If any commits are missing the push will be
266-
aborted and exit with non-zero status. If 'on-demand' is used
267-
all submodules that changed in the revisions to be pushed will
268-
be pushed. If on-demand was not able to push all necessary
269-
revisions it will also be aborted and exit with non-zero status.
260+
--no-recurse-submodules::
261+
--recurse-submodules=check|on-demand|no::
262+
May be used to make sure all submodule commits used by the
263+
revisions to be pushed are available on a remote-tracking branch.
264+
If 'check' is used Git will verify that all submodule commits that
265+
changed in the revisions to be pushed are available on at least one
266+
remote of the submodule. If any commits are missing the push will
267+
be aborted and exit with non-zero status. If 'on-demand' is used
268+
all submodules that changed in the revisions to be pushed will be
269+
pushed. If on-demand was not able to push all necessary revisions
270+
it will also be aborted and exit with non-zero status. A value of
271+
'no' or using '--no-recurse-submodules' can be used to override the
272+
push.recurseSubmodules configuration variable when no submodule
273+
recursion is required.
270274

271275
--[no-]verify::
272276
Toggle the pre-push hook (see linkgit:githooks[5]). The

builtin/push.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "transport.h"
1010
#include "parse-options.h"
1111
#include "submodule.h"
12+
#include "submodule-config.h"
1213
#include "send-pack.h"
1314

1415
static const char * const push_usage[] = {
@@ -21,6 +22,7 @@ static int deleterefs;
2122
static const char *receivepack;
2223
static int verbosity;
2324
static int progress = -1;
25+
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
2426

2527
static struct push_cas_option cas;
2628

@@ -452,22 +454,14 @@ static int do_push(const char *repo, int flags)
452454
static int option_parse_recurse_submodules(const struct option *opt,
453455
const char *arg, int unset)
454456
{
455-
int *flags = opt->value;
457+
int *recurse_submodules = opt->value;
456458

457-
if (*flags & (TRANSPORT_RECURSE_SUBMODULES_CHECK |
458-
TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND))
459-
die("%s can only be used once.", opt->long_name);
460-
461-
if (arg) {
462-
if (!strcmp(arg, "check"))
463-
*flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
464-
else if (!strcmp(arg, "on-demand"))
465-
*flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
466-
else
467-
die("bad %s argument: %s", opt->long_name, arg);
468-
} else
469-
die("option %s needs an argument (check|on-demand)",
470-
opt->long_name);
459+
if (unset)
460+
*recurse_submodules = RECURSE_SUBMODULES_OFF;
461+
else if (arg)
462+
*recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
463+
else
464+
die("%s missing parameter", opt->long_name);
471465

472466
return 0;
473467
}
@@ -522,6 +516,10 @@ static int git_push_config(const char *k, const char *v, void *cb)
522516
return error("Invalid value for '%s'", k);
523517
}
524518
}
519+
} else if (!strcmp(k, "push.recursesubmodules")) {
520+
const char *value;
521+
if (!git_config_get_value("push.recursesubmodules", &value))
522+
recurse_submodules = parse_push_recurse_submodules_arg(k, value);
525523
}
526524

527525
return git_default_config(k, v, NULL);
@@ -549,7 +547,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
549547
0, CAS_OPT_NAME, &cas, N_("refname>:<expect"),
550548
N_("require old value of ref to be at this value"),
551549
PARSE_OPT_OPTARG, parseopt_push_cas_option },
552-
{ OPTION_CALLBACK, 0, "recurse-submodules", &flags, "check|on-demand",
550+
{ OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules, N_("check|on-demand|no"),
553551
N_("control recursive pushing of submodules"),
554552
PARSE_OPT_OPTARG, option_parse_recurse_submodules },
555553
OPT_BOOL( 0 , "thin", &thin, N_("use thin pack")),
@@ -580,6 +578,11 @@ int cmd_push(int argc, const char **argv, const char *prefix)
580578
if (deleterefs && argc < 2)
581579
die(_("--delete doesn't make sense without any refs"));
582580

581+
if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
582+
flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
583+
else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
584+
flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
585+
583586
if (tags)
584587
add_refspec("refs/tags/*");
585588

submodule-config.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,35 @@ int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg)
228228
return parse_fetch_recurse(opt, arg, 1);
229229
}
230230

231+
static int parse_push_recurse(const char *opt, const char *arg,
232+
int die_on_error)
233+
{
234+
switch (git_config_maybe_bool(opt, arg)) {
235+
case 1:
236+
/* There's no simple "on" value when pushing */
237+
if (die_on_error)
238+
die("bad %s argument: %s", opt, arg);
239+
else
240+
return RECURSE_SUBMODULES_ERROR;
241+
case 0:
242+
return RECURSE_SUBMODULES_OFF;
243+
default:
244+
if (!strcmp(arg, "on-demand"))
245+
return RECURSE_SUBMODULES_ON_DEMAND;
246+
else if (!strcmp(arg, "check"))
247+
return RECURSE_SUBMODULES_CHECK;
248+
else if (die_on_error)
249+
die("bad %s argument: %s", opt, arg);
250+
else
251+
return RECURSE_SUBMODULES_ERROR;
252+
}
253+
}
254+
255+
int parse_push_recurse_submodules_arg(const char *opt, const char *arg)
256+
{
257+
return parse_push_recurse(opt, arg, 1);
258+
}
259+
231260
static void warn_multiple_config(const unsigned char *commit_sha1,
232261
const char *name, const char *option)
233262
{

submodule-config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct submodule {
1919
};
2020

2121
int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
22+
int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
2223
int parse_submodule_config_option(const char *var, const char *value);
2324
const struct submodule *submodule_from_name(const unsigned char *commit_sha1,
2425
const char *name);

submodule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ struct diff_options;
55
struct argv_array;
66

77
enum {
8+
RECURSE_SUBMODULES_CHECK = -4,
89
RECURSE_SUBMODULES_ERROR = -3,
910
RECURSE_SUBMODULES_NONE = -2,
1011
RECURSE_SUBMODULES_ON_DEMAND = -1,

0 commit comments

Comments
 (0)