git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Crowe <mac@mcrowe.com>
To: git@vger.kernel.org
Cc: Mike Crowe <mac@mcrowe.com>, Jeff King <peff@peff.net>
Subject: [PATCH] push: Improve --recurse-submodules support
Date: Wed,  2 Dec 2015 09:56:12 +0000	[thread overview]
Message-ID: <1449050172-1119-1-git-send-email-mac@mcrowe.com> (raw)
In-Reply-To: <20151202095451.GA22568@mcrowe.com>

b33a15b08131514b593015cb3e719faf9db20208 added support for the
push.recurseSubmodules config option. After it was merged Junio C Hamano
suggested some improvements:

 - Declare recurse_submodules on a separate line.

 - Accept multiple --recurse-submodules options on command line with the
   last one winning. (This simplified the implementation too.)

Also slightly improve one of the tests added in
b33a15b08131514b593015cb3e719faf9db20208.

Signed-off-by: Mike Crowe <mac@mcrowe.com>
---

 builtin/push.c                 | 12 +++---------
 t/t5531-deep-submodule-push.sh | 36 +++++++++++++++++++++++++++++++++---
 2 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/builtin/push.c b/builtin/push.c
index f9b59b4..cc29277 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -21,7 +21,8 @@ static int thin = 1;
 static int deleterefs;
 static const char *receivepack;
 static int verbosity;
-static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
+static int progress = -1;
+static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
 
 static struct push_cas_option cas;
 
@@ -455,9 +456,6 @@ static int option_parse_recurse_submodules(const struct option *opt,
 {
 	int *recurse_submodules = opt->value;
 
-	if (*recurse_submodules != RECURSE_SUBMODULES_DEFAULT)
-		die("%s can only be used once.", opt->long_name);
-
 	if (unset)
 		*recurse_submodules = RECURSE_SUBMODULES_OFF;
 	else if (arg)
@@ -532,7 +530,6 @@ 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[] = {
@@ -550,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", &recurse_submodules_from_cmdline, N_("check|on-demand|no"),
+		{ 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")),
@@ -581,9 +578,6 @@ 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)
diff --git a/t/t5531-deep-submodule-push.sh b/t/t5531-deep-submodule-push.sh
index 9fda7b0..9a637f5 100755
--- a/t/t5531-deep-submodule-push.sh
+++ b/t/t5531-deep-submodule-push.sh
@@ -126,7 +126,7 @@ test_expect_success 'push succeeds if submodule commit not on remote but using o
 	)
 '
 
-test_expect_success 'push fails if submodule commit not on remote using check from cmdline overriding config' '
+test_expect_success 'push recurse-submodules cmdline overrides config' '
 	(
 		cd work/gar/bage &&
 		>recurse-check-on-command-line-overriding-config &&
@@ -142,8 +142,38 @@ test_expect_success 'push fails if submodule commit not on remote using check fr
 		git fetch ../pub.git &&
 		git diff --quiet FETCH_HEAD master^ &&
 		# Check that the submodule commit did not get there
-		cd gar/bage &&
-		git diff --quiet origin/master master^
+		(cd gar/bage && git diff --quiet origin/master master^) &&
+		# Now try the reverse which should succeed
+		git -c push.recurseSubmodules=check push --recurse-submodules=on-demand ../pub.git master &&
+		git fetch ../pub.git &&
+		git diff --quiet FETCH_HEAD master &&
+		(cd gar/bage && git diff --quiet origin/master master)
+	)
+'
+
+test_expect_success 'push recurse-submodules on cmdline overrides earlier cmdline' '
+	(
+		cd work/gar/bage &&
+		>recurse-check-on-command-line-overriding-earlier-command-line &&
+		git add recurse-check-on-command-line-overriding-earlier-command-line &&
+		git commit -m "Recurse on command-line overridiing earlier command-line junk"
+	) &&
+	(
+		cd work &&
+		git add gar/bage &&
+		git commit -m "Recurse on command-line overriding earlier command-line for gar/bage" &&
+		test_must_fail git push --recurse-submodules=on-demand --recurse-submodules=check ../pub.git master &&
+		# Check that the supermodule commit did not get there
+		git fetch ../pub.git &&
+		git diff FETCH_HEAD master^ &&
+		git diff --quiet FETCH_HEAD master^ &&
+		# Check that the submodule commit did not get there
+		(cd gar/bage && git diff --quiet origin/master master^) &&
+		# But the options in the other order should push the submodule
+		git push --recurse-submodules=check --recurse-submodules=on-demand ../pub.git master &&
+		# Check that the submodule commit did get there
+		git fetch ../pub.git &&
+		(cd gar/bage && git diff --quiet origin/master master)
 	)
 '
 
-- 
2.1.4

  reply	other threads:[~2015-12-02  9:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-01 11:49 [PATCH v3] push: add recurseSubmodules config option Mike Crowe
2015-12-02  0:40 ` Jeff King
2015-12-02  9:54   ` Mike Crowe
2015-12-02  9:56     ` Mike Crowe [this message]
2015-12-02 23:21       ` [PATCH] push: Improve --recurse-submodules support Junio C Hamano
2015-12-03 13:10         ` Mike Crowe
2015-12-03 13:10           ` [PATCH 1/2] push: Fully test --recurse-submodules on command line overrides config Mike Crowe
2015-12-03 13:10             ` [PATCH 2/2] push: Use "last one wins" convention for --recurse-submodules Mike Crowe
2015-12-04 21:04               ` Junio C Hamano
2015-12-10 23:31               ` Stefan Beller
2015-12-10 23:38                 ` Junio C Hamano
2015-12-10 23:44                   ` Stefan Beller
2015-12-16 20:48             ` [PATCH 1/2] push: Fully test --recurse-submodules on command line overrides config Stefan Beller
2015-12-16 22:41               ` Junio C Hamano
2015-12-16 22:46                 ` Stefan Beller
2015-12-17 16:41                   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1449050172-1119-1-git-send-email-mac@mcrowe.com \
    --to=mac@mcrowe.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).