Skip to contentSkip to conversation

push: add recurseSubmodules config option

PATCH Superseded Mike Crowe 5 participants 7 messages Jun 15, 2016 Documentation

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Mike Crowe

author
#0 lore raw

PATCH 1/1 push: add recurseSubmodules config option

The --recurse-submodules command line parameter has existed for some time but it has no config file equivalent.

Following the style of the corresponding parameter for git fetch, let's invent push.recurseSubmodules to provide a default for this parameter. This also requires the addition of --recurse-submodules=no to allow the configuration to be overridden on the command line when required.

The most straightforward way to implement this appears to be to make push use code in submodule-config in a similar way to fetch.

---
 Documentation/config.txt       |  13 +++++
 Documentation/git-push.txt     |   4 +-
 builtin/push.c                 |  37 ++++++++-----
 submodule-config.c             |  20 +++++++
 submodule-config.h             |   1 +
 submodule.h                    |   1 +
 t/t5531-deep-submodule-push.sh | 123 ++++++++++++++++++++++++++++++++++++++++-
 7 files changed, 182 insertions(+), 17 deletions(-)
Documentation/config.txt +13 -0
index 391a0c3..0546da5 100644
@@ -2226,6 +2226,19 @@ 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. 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.
Documentation/git-push.txt +3 -1
index 85a4d7d..fb0e9b7 100644
@@ -257,7 +257,7 @@ 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::
+--recurse-submodules=check|on-demand|no::
 	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
@@ -267,6 +267,8 @@ origin +master` to force a push to the `master` branch). See the
 	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' is used to override the push.recurseSubmodules
+	variable when no submodule recursion is required.
 
 --[no-]verify::
 	Toggle the pre-push hook (see linkgit:githooks[5]).  The
builtin/push.c +22 -15
index 3bda430..dfced74 100644
@@ -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[] = {
@@ -20,7 +21,7 @@ static int thin = 1;
 static int deleterefs;
 static const char *receivepack;
 static int verbosity;
-static int progress = -1;
+static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
 
 static struct push_cas_option cas;
 
@@ -452,22 +453,15 @@ 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))
+	if (*recurse_submodules != RECURSE_SUBMODULES_DEFAULT)
 		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 (arg)
+		*recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
+	else
+		die("%s missing parameter", opt->long_name);
 
 	return 0;
 }
@@ -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);
@@ -532,6 +530,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 	int flags = 0;
 	int tags = 0;
 	int push_cert = -1;
+	int recurse_submodules_from_cmdline = RECURSE_SUBMODULES_DEFAULT;
 	int rc;
 	const char *repo = NULL;	/* default repository */
 	struct option options[] = {
@@ -549,7 +548,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_from_cmdline, 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")),
@@ -580,6 +579,14 @@ 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_from_cmdline != RECURSE_SUBMODULES_DEFAULT)
+		recurse_submodules = recurse_submodules_from_cmdline;
+
+	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/*");
 
submodule-config.c +20 -0
index afe0ea8..33d8790 100644
@@ -228,6 +228,26 @@ 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)
+{
+    if (!strcmp(arg, "on-demand"))
+	return RECURSE_SUBMODULES_ON_DEMAND;
+    else if (!strcmp(arg, "check"))
+	return RECURSE_SUBMODULES_CHECK;
+    else if (!strcmp(arg, "no"))
+	return RECURSE_SUBMODULES_OFF;
+    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)
 {
submodule-config.h +1 -0
index 9061e4e..9bfa65a 100644
@@ -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);
submodule.h +1 -0
index 5507c3d..ddff512 100644
@@ -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,
t/t5531-deep-submodule-push.sh +122 -1

135 lines not on this page · raw message

Signature · 1 line
2.1.4
#1 lore raw
Quoted 9 lines · Mike Crowe

The --recurse-submodules command line parameter has existed for some time but it has no config file equivalent.

Following the style of the corresponding parameter for git fetch, let's invent push.recurseSubmodules to provide a default for this parameter. This also requires the addition of --recurse-submodules=no to allow the configuration to be overridden on the command line when required.

Quoted 5 lines

The most straightforward way to implement this appears to be to make push use code in submodule-config in a similar way to fetch.

---

The code itself looks good to me, one nit in the tests though.

Quoted 9 lines
t/t5531-deep-submodule-push.sh +5 -0
@@ -79,6 +87,119 @@ test_expect_success 'push succeeds after commit was pushed to remote' '
        )
 '
 
+test_expect_success 'push succeeds if submodule commit not on remote but using on-demand on command line' '
+       (
+               cd work/gar/bage &&
+               >recurse-on-demand-on-command-line &&
+               git add recurse-on-demand-on-command-line &&

t/t5531-deep-submodule-push.sh test_expect_success 'push succeeds after commit was pushed to remote' ' · line 104

Quoted 10 lines
t/t5531-deep-submodule-push.sh +10 -0
+               git commit -m "Recurse on-demand on command line junk"
+       ) &&
+       (
+               cd work &&
+               git add gar/bage &&
+               git commit -m "Recurse on-demand on command line for gar/bage" &&
+               git push --recurse-submodules=on-demand ../pub.git master &&
+               # Check that the supermodule commit got there
+               git fetch ../pub.git &&
+               git diff --quiet FETCH_HEAD master

Missing && chain here.

Quoted 6 lines
t/t5531-deep-submodule-push.sh +6 -0
+               # Check that the submodule commit got there too
+               cd gar/bage &&
+               git diff --quiet origin/master master
+       )
+'
+
author
#2 lore raw
Quoted 15 lines · Stefan Beller

The code itself looks good to me, one nit in the tests though.

Quoted 13 lines
t/t5531-deep-submodule-push.sh +9 -0
@@ -79,6 +87,119 @@ test_expect_success 'push succeeds after commit was pushed to remote' '
        )
 '
 
+test_expect_success 'push succeeds if submodule commit not on remote but using on-demand on command line' '
+       (
+               cd work/gar/bage &&
+               >recurse-on-demand-on-command-line &&
+               git add recurse-on-demand-on-command-line &&
+               git commit -m "Recurse on-demand on command line junk"
+       ) &&
+       (
+               cd work &&
Quoted 8 lines

t/t5531-deep-submodule-push.sh test_expect_success 'push succeeds after commit was pushed to remote' ' · line 104

Quoted 6 lines
t/t5531-deep-submodule-push.sh +6 -0
+               git add gar/bage &&
+               git commit -m "Recurse on-demand on command line for gar/bage" &&
+               git push --recurse-submodules=on-demand ../pub.git master &&
+               # Check that the supermodule commit got there
+               git fetch ../pub.git &&
+               git diff --quiet FETCH_HEAD master

Missing && chain here.

Oh, well spotted! I'll provide an updated version.

Thanks.

Mike.

#3 lore raw

Am 16.11.2015 um 19:31 schrieb Mike Crowe:

Quoted 25 lines · Stefan Beller
Quoted 15 lines

The code itself looks good to me, one nit in the tests though.

Quoted 13 lines
t/t5531-deep-submodule-push.sh +9 -0
@@ -79,6 +87,119 @@ test_expect_success 'push succeeds after commit was pushed to remote' '
         )
  '
 
+test_expect_success 'push succeeds if submodule commit not on remote but using on-demand on command line' '
+       (
+               cd work/gar/bage &&
+               >recurse-on-demand-on-command-line &&
+               git add recurse-on-demand-on-command-line &&
+               git commit -m "Recurse on-demand on command line junk"
+       ) &&
+       (
+               cd work &&
Quoted 8 lines

t/t5531-deep-submodule-push.sh test_expect_success 'push succeeds after commit was pushed to remote' ' · line 104

Quoted 6 lines
t/t5531-deep-submodule-push.sh +6 -0
+               git add gar/bage &&
+               git commit -m "Recurse on-demand on command line for gar/bage" &&
+               git push --recurse-submodules=on-demand ../pub.git master &&
+               # Check that the supermodule commit got there
+               git fetch ../pub.git &&
+               git diff --quiet FETCH_HEAD master

Missing && chain here.

Quoted 1 line

Oh, well spotted! I'll provide an updated version.

Looking good for me too!

Cool, another issue from my Wiki that's being worked on!

#4 lore raw
In reply to Mike Crowe
Quoted 18 lines · Mike Crowe

The --recurse-submodules command line parameter has existed for some time but it has no config file equivalent.

Following the style of the corresponding parameter for git fetch, let's invent push.recurseSubmodules to provide a default for this parameter. This also requires the addition of --recurse-submodules=no to allow the configuration to be overridden on the command line when required.

The most straightforward way to implement this appears to be to make push use code in submodule-config in a similar way to fetch.

---

Documentation/config.txt +2 -0
@@ -2226,6 +2226,19 @@ push.gpgSign::
+push.recurseSubmodules::
+       Make sure all submodule commits used by the revisions to be pushed

Documentation/config.txt push.gpgSign:: · line 2237

Quoted 10 lines
Documentation/config.txt +10 -0
+       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. You may
+       override this configuration at time of push by specifying
+       '--recurse-submodules=check|on-demand|no'.

Does this configuration variable also support 'no' as a value? If so, then it probably ought to be documented. If not, shouldn't it do so to allow a configuration file to override a 'check' or 'on-demand' value specified in a more global git configuration file?

Quoted 11 lines
Documentation/config.txt +0 -0
 rebase.stat::
        Whether to show a diffstat of what changed upstream since the last
        rebase. False by default.
Documentation/git-push.txt +1 -1
@@ -257,7 +257,7 @@ origin +master` to force a push to the `master` branch). See the
---recurse-submodules=check|on-demand::
+--recurse-submodules=check|on-demand|no::
        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

Documentation/git-push.txt origin +master` to force a push to the `master` branch). See the · line 271

Quoted 5 lines
Documentation/git-push.txt +2 -0
@@ -267,6 +267,8 @@ origin +master` to force a push to the `master` branch). See the
        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' is used to override the push.recurseSubmodules
+       variable when no submodule recursion is required.

Does this deserve a --no-recurse-submodules alias for consistency with how other options are turned off?

Quoted 7 lines
Documentation/git-push.txt +0 -0
 --[no-]verify::
        Toggle the pre-push hook (see linkgit:githooks[5]).  The
t/t5531-deep-submodule-push.sh +0 -0
@@ -64,7 +64,15 @@ test_expect_success 'push fails if submodule commit not on remote' '
                cd work &&
                git add gar/bage &&
                git commit -m "Third commit for gar/bage" &&

t/t5531-deep-submodule-push.sh test_expect_success 'push fails if submodule commit not on remote' ' · line 75

Quoted 10 lines
t/t5531-deep-submodule-push.sh +9 -1
-               test_must_fail git push --recurse-submodules=check ../pub.git master
+               # the push should fail with --recurse-submodules=check
+               # on the command line...
+               test_must_fail git push --recurse-submodules=check ../pub.git master &&
+
+               # ...or if specified in the configuration..
+               git config push.recurseSubmodules check &&
+               test_must_fail git push ../pub.git master &&
+
+               git config --unset push.recurseSubmodules

If something above this line fails, then 'git config --unset' will not be invoked, so the expected cleanup won't happen. Typically, to ensure cleanup, you'd use test_config(), however that function doesn't work in subshells. Probably the easiest fix, in this case, is to set the config variable as a one-shot and drop 'git config' and 'git config --unset' altogether:

test_must_fail git -c push.recurseSubmodules check \
push ../pub.git master

Quoted 8 lines
t/t5531-deep-submodule-push.sh +4 -0
        )
 '
 
@@ -79,6 +87,119 @@ test_expect_success 'push succeeds after commit was pushed to remote' '
+test_expect_success 'push succeeds if submodule commit not on remote but using on-demand from config' '
+       (
+               cd work/gar/bage &&
+               >recurse-on-demand-from-config &&

t/t5531-deep-submodule-push.sh test_expect_success 'push succeeds after commit was pushed to remote' ' · line 100

Quoted 10 lines
t/t5531-deep-submodule-push.sh +10 -0
+               git add recurse-on-demand-from-config &&
+               git commit -m "Recurse on-demand from config junk"
+       ) &&
+       (
+               cd work &&
+               git add gar/bage &&
+               git commit -m "Recurse on-demand on command line for gar/bage" &&
+               git config push.recurseSubmodules on-demand &&
+               git push ../pub.git master &&
+               git config --unset push.recurseSubmodules &&

Ditto regarding 'git config --unset' cleanup not being run there is a failure above this. Same for following tests.

Quoted 8 lines
t/t5531-deep-submodule-push.sh +8 -0
+               # Check that the supermodule commit got there
+               git fetch ../pub.git &&
+               git diff --quiet FETCH_HEAD master
+               # Check that the submodule commit got there too
+               cd gar/bage &&
+               git diff --quiet origin/master master
+       )
+'
#5 lore raw
In reply to Mike Crowe
Quoted 13 lines · Mike Crowe
builtin/push.c +1 -0
index 3bda430..dfced74 100644
@@ -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[] = {

builtin/push.c static int thin = 1; · line 24

Quoted 5 lines
builtin/push.c +1 -1
@@ -20,7 +21,7 @@ static int thin = 1;
 static int deleterefs;
 static const char *receivepack;
 static int verbosity;
-static int progress = -1;
+static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;

One variable per line, please. Especially when the two variables do not have anything to do with each other, and do not have any logical similarity between them.

builtin/push.c static int do_push(const char *repo, int flags) · line 459

Quoted 11 lines
builtin/push.c +2 -3
@@ -452,22 +453,15 @@ 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))
+	if (*recurse_submodules != RECURSE_SUBMODULES_DEFAULT)
 		die("%s can only be used once.", opt->long_name);

The usual convention thoughout Git user experience is "the last one wins" (both in the configuration and in the command line options). Is there a good reason to deviate from that here?

author
#6 lore raw
Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Mike Crowe
builtin/push.c +1 -0
index 3bda430..dfced74 100644
@@ -9,6 +9,7 @@
 #include "transport.h"
 #include "parse-options.h"
 #include "submodule.h"
+#include "submodule-config.h"
 #include "send-pack.h"
 
Quoted 11 lines

builtin/push.c static int thin = 1; · line 24

Quoted 7 lines
builtin/push.c +1 -1
 static const char * const push_usage[] = {
@@ -20,7 +21,7 @@ static int thin = 1;
 static int deleterefs;
 static const char *receivepack;
 static int verbosity;
-static int progress = -1;
+static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;

One variable per line, please. Especially when the two variables do not have anything to do with each other, and do not have any logical similarity between them.

I wouldn't normally have done that either, but I was mirroring the equivalent code in fetch.c. I will change it.

Quoted 7 lines
Quoted 7 lines
builtin/push.c +1 -1
@@ -452,22 +453,15 @@ 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;
 
Quoted 8 lines

builtin/push.c static int do_push(const char *repo, int flags) · line 459

Quoted 4 lines
builtin/push.c +1 -2
-	if (*flags & (TRANSPORT_RECURSE_SUBMODULES_CHECK |
-		      TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND))
+	if (*recurse_submodules != RECURSE_SUBMODULES_DEFAULT)
 		die("%s can only be used once.", opt->long_name);

The usual convention thoughout Git user experience is "the last one wins" (both in the configuration and in the command line options). Is there a good reason to deviate from that here?

I was aiming to retain the existing behaviour, which was to complain if conflicting options were supplied on the command line. Making the last one win would have been rather simpler. I can change this too, unless someone knows why complaining about conflicting options would be useful.

Note that I previously sent an updated patch as <[email protected]> but I believe that your criticisms still apply.

Thanks for the review.

Mike.