git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brandon Williams <bmwill@google.com>
To: git@vger.kernel.org
Cc: sbeller@google.com, Brandon Williams <bmwill@google.com>
Subject: [PATCH 3/3] push: add option to push only submodules
Date: Mon, 19 Dec 2016 10:25:33 -0800	[thread overview]
Message-ID: <1482171933-180601-4-git-send-email-bmwill@google.com> (raw)
In-Reply-To: <1482171933-180601-1-git-send-email-bmwill@google.com>

Teach push the --recurse-submodules=only option.  This enables push to
recursively push all unpushed submodules while leaving the superproject
unpushed.

This is a desirable feature in a scenario where updates to the
superproject are handled automatically by some other means, perhaps a
code review tool.  In this scenario a developer could make a change
which spans multiple submodules and then push their commits for code
review.  Upon completion of the code review, their commits can be
accepted and applied to their respective submodules while the code
review tool can then automatically update the superproject to the most
recent SHA1 of each submodule.  This would eliminate the merge conflicts
in the superproject that could occur if multiple people are contributing
to the same submodule.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 builtin/push.c                 |  2 ++
 t/t5531-deep-submodule-push.sh | 21 +++++++++++++++++++++
 transport.c                    | 15 +++++++++++----
 transport.h                    |  1 +
 4 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/builtin/push.c b/builtin/push.c
index 3bb9d6b..9433797 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -565,6 +565,8 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 		flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
 	else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
 		flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
+	else if (recurse_submodules == RECURSE_SUBMODULES_ONLY)
+		flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY;
 
 	if (tags)
 		add_refspec("refs/tags/*");
diff --git a/t/t5531-deep-submodule-push.sh b/t/t5531-deep-submodule-push.sh
index 1524ff5..676d686 100755
--- a/t/t5531-deep-submodule-push.sh
+++ b/t/t5531-deep-submodule-push.sh
@@ -454,4 +454,25 @@ test_expect_success 'push --dry-run does not recursively update submodules' '
 	test_cmp expected_submodule actual_submodule
 '
 
+test_expect_success 'push --dry-run does not recursively update submodules' '
+	git -C work push --dry-run --recurse-submodules=only ../pub.git master &&
+
+	git -C submodule.git rev-parse master >actual_submodule &&
+	git -C pub.git rev-parse master >actual_pub &&
+	test_cmp expected_pub actual_pub &&
+	test_cmp expected_submodule actual_submodule
+'
+
+test_expect_success 'push only unpushed submodules recursively' '
+	git -C pub.git rev-parse master >expected_pub &&
+	git -C work/gar/bage rev-parse master >expected_submodule &&
+
+	git -C work push --recurse-submodules=only ../pub.git master &&
+
+	git -C submodule.git rev-parse master >actual_submodule &&
+	git -C pub.git rev-parse master >actual_pub &&
+	test_cmp expected_submodule actual_submodule &&
+	test_cmp expected_pub actual_pub
+'
+
 test_done
diff --git a/transport.c b/transport.c
index 04e5d66..20ebee8 100644
--- a/transport.c
+++ b/transport.c
@@ -947,7 +947,9 @@ int transport_push(struct transport *transport,
 			if (run_pre_push_hook(transport, remote_refs))
 				return -1;
 
-		if ((flags & TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND) && !is_bare_repository()) {
+		if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
+			      TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
+		    !is_bare_repository()) {
 			struct ref *ref = remote_refs;
 			struct sha1_array commits = SHA1_ARRAY_INIT;
 
@@ -965,7 +967,8 @@ int transport_push(struct transport *transport,
 		}
 
 		if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) ||
-		     ((flags & TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND) &&
+		     ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
+				TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
 		      !pretend)) && !is_bare_repository()) {
 			struct ref *ref = remote_refs;
 			struct string_list needs_pushing = STRING_LIST_INIT_DUP;
@@ -984,7 +987,10 @@ int transport_push(struct transport *transport,
 			sha1_array_clear(&commits);
 		}
 
-		push_ret = transport->push_refs(transport, remote_refs, flags);
+		if (!(flags & TRANSPORT_RECURSE_SUBMODULES_ONLY))
+			push_ret = transport->push_refs(transport, remote_refs, flags);
+		else
+			push_ret = 0;
 		err = push_had_errors(remote_refs);
 		ret = push_ret | err;
 
@@ -996,7 +1002,8 @@ int transport_push(struct transport *transport,
 		if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
 			set_upstreams(transport, remote_refs, pretend);
 
-		if (!(flags & TRANSPORT_PUSH_DRY_RUN)) {
+		if (!(flags & (TRANSPORT_PUSH_DRY_RUN |
+			       TRANSPORT_RECURSE_SUBMODULES_ONLY))) {
 			struct ref *ref;
 			for (ref = remote_refs; ref; ref = ref->next)
 				transport_update_tracking_ref(transport->remote, ref, verbose);
diff --git a/transport.h b/transport.h
index 1b65458..efd5fb6 100644
--- a/transport.h
+++ b/transport.h
@@ -146,6 +146,7 @@ struct transport {
 #define TRANSPORT_PUSH_CERT_IF_ASKED		(1<<12)
 #define TRANSPORT_PUSH_ATOMIC			(1<<13)
 #define TRANSPORT_PUSH_OPTIONS			(1<<14)
+#define TRANSPORT_RECURSE_SUBMODULES_ONLY	(1<<15)
 
 extern int transport_summary_width(const struct ref *refs);
 
-- 
2.8.0.rc3.226.g39d4020


  parent reply	other threads:[~2016-12-19 18:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-19 18:25 [PATCH 0/3] push only submodules Brandon Williams
2016-12-19 18:25 ` [PATCH 1/3] transport: refactor flag #defines to be more readable Brandon Williams
2016-12-19 18:25 ` [PATCH 2/3] submodules: add RECURSE_SUBMODULES_ONLY value Brandon Williams
2016-12-19 18:25 ` Brandon Williams [this message]
2016-12-19 18:56   ` [PATCH 3/3] push: add option to push only submodules Stefan Beller
2016-12-19 18:41 ` [PATCH 0/3] " Junio C Hamano
2016-12-20 19:25 ` 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=1482171933-180601-4-git-send-email-bmwill@google.com \
    --to=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=sbeller@google.com \
    /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).