Skip to content

Commit

Permalink
Merge branch 'mc/push-recurse-submodules-config'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Dec 21, 2015
2 parents c3ee2e2 + d34141c commit 5d35d72
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 27 deletions.
14 changes: 14 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,20 @@ push.gpgSign::
override a value from a lower-priority config file. An explicit
command-line flag always overrides this config option.

push.recurseSubmodules::
Make sure all submodule commits used by the revisions to be pushed
are available on a remote-tracking branch. If the value is 'check'
then Git will verify that all submodule commits that changed in the
revisions to be pushed are available on at least one remote of the
submodule. If any commits are missing, the push will be aborted and
exit with non-zero status. If the value is 'on-demand' then all
submodules that changed in the revisions to be pushed will be
pushed. If on-demand was not able to push all necessary revisions
it will also be aborted and exit with non-zero status. If the value
is 'no' then default behavior of ignoring submodules when pushing
is retained. You may override this configuration at time of push by
specifying '--recurse-submodules=check|on-demand|no'.

rebase.stat::
Whether to show a diffstat of what changed upstream since the last
rebase. False by default.
Expand Down
24 changes: 14 additions & 10 deletions Documentation/git-push.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,20 @@ origin +master` to force a push to the `master` branch). See the
is specified. This flag forces progress status even if the
standard error stream is not directed to a terminal.

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

--[no-]verify::
Toggle the pre-push hook (see linkgit:githooks[5]). The
Expand Down
35 changes: 19 additions & 16 deletions builtin/push.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "transport.h"
#include "parse-options.h"
#include "submodule.h"
#include "submodule-config.h"
#include "send-pack.h"

static const char * const push_usage[] = {
Expand All @@ -21,6 +22,7 @@ static int deleterefs;
static const char *receivepack;
static int verbosity;
static int progress = -1;
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;

static struct push_cas_option cas;

Expand Down Expand Up @@ -452,22 +454,14 @@ static int do_push(const char *repo, int flags)
static int option_parse_recurse_submodules(const struct option *opt,
const char *arg, int unset)
{
int *flags = opt->value;
int *recurse_submodules = opt->value;

if (*flags & (TRANSPORT_RECURSE_SUBMODULES_CHECK |
TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND))
die("%s can only be used once.", opt->long_name);

if (arg) {
if (!strcmp(arg, "check"))
*flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
else if (!strcmp(arg, "on-demand"))
*flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
else
die("bad %s argument: %s", opt->long_name, arg);
} else
die("option %s needs an argument (check|on-demand)",
opt->long_name);
if (unset)
*recurse_submodules = RECURSE_SUBMODULES_OFF;
else if (arg)
*recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
else
die("%s missing parameter", opt->long_name);

return 0;
}
Expand Down Expand Up @@ -522,6 +516,10 @@ static int git_push_config(const char *k, const char *v, void *cb)
return error("Invalid value for '%s'", k);
}
}
} else if (!strcmp(k, "push.recursesubmodules")) {
const char *value;
if (!git_config_get_value("push.recursesubmodules", &value))
recurse_submodules = parse_push_recurse_submodules_arg(k, value);
}

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

if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;

if (tags)
add_refspec("refs/tags/*");

Expand Down
29 changes: 29 additions & 0 deletions submodule-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,35 @@ int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg)
return parse_fetch_recurse(opt, arg, 1);
}

static int parse_push_recurse(const char *opt, const char *arg,
int die_on_error)
{
switch (git_config_maybe_bool(opt, arg)) {
case 1:
/* There's no simple "on" value when pushing */
if (die_on_error)
die("bad %s argument: %s", opt, arg);
else
return RECURSE_SUBMODULES_ERROR;
case 0:
return RECURSE_SUBMODULES_OFF;
default:
if (!strcmp(arg, "on-demand"))
return RECURSE_SUBMODULES_ON_DEMAND;
else if (!strcmp(arg, "check"))
return RECURSE_SUBMODULES_CHECK;
else if (die_on_error)
die("bad %s argument: %s", opt, arg);
else
return RECURSE_SUBMODULES_ERROR;
}
}

int parse_push_recurse_submodules_arg(const char *opt, const char *arg)
{
return parse_push_recurse(opt, arg, 1);
}

static void warn_multiple_config(const unsigned char *commit_sha1,
const char *name, const char *option)
{
Expand Down
1 change: 1 addition & 0 deletions submodule-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct submodule {
};

int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
int parse_submodule_config_option(const char *var, const char *value);
const struct submodule *submodule_from_name(const unsigned char *commit_sha1,
const char *name);
Expand Down
1 change: 1 addition & 0 deletions submodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct diff_options;
struct argv_array;

enum {
RECURSE_SUBMODULES_CHECK = -4,
RECURSE_SUBMODULES_ERROR = -3,
RECURSE_SUBMODULES_NONE = -2,
RECURSE_SUBMODULES_ON_DEMAND = -1,
Expand Down
Loading

0 comments on commit 5d35d72

Please sign in to comment.