git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH resend] make "git push" update origin and mirrors, "git push --mirror" update mirrors
@ 2008-04-26  7:31 Paolo Bonzini
  2008-04-26 17:01 ` Shawn O. Pearce
  2008-04-28 15:32 ` [PATCH 0/7] limit the usage of the default remote "origin" to the minimum Paolo Bonzini
  0 siblings, 2 replies; 74+ messages in thread
From: Paolo Bonzini @ 2008-04-26  7:31 UTC (permalink / raw)
  To: git; +Cc: gitster

This patch builds on the infrastructure for remote.<nick>.mirror and
tweaks the behavior of "git push".  The idea is that "git push",
"git push --all", "git push --mirror", instead of defaulting to origin,
become DWIM commands:

- "git push" pushes to origin *and* to all mirrors

- "git push --all" pushes to origin with --all.  I didn't make it push
  to mirrors because --all and --mirror are incompatible.

- "git push --mirror" only updates mirror repositories, without touching
  origin.

This is useful when a project has a public repository managed by the
integrator, but the integrator also wants to publish his own mirror
somewhere.  In this case, the integrator will just do "git push".
Similarly, if a developer uses the integrator's repository but
wishes to publish his own mirror somewhere, he can just do "git push
--mirror".

The code explicitly disables pushing to mirrors when a refspec is present.
This is just defensive, because right now refspecs cannot be specified
without giving a repository too.

Signed-off-by: Paolo Bonzini <bonzini@gnu.org>
---
 Documentation/git-push.txt |   17 ++++++---
 builtin-push.c             |   43 ++++++++++++++++------
 t/t5517-push-mirror.sh     |   86 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+), 16 deletions(-)

	Sent a week ago, no comments received.

diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index dc1d4b0..8195517 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -29,6 +29,11 @@ OPTIONS
 	The "remote" repository that is destination of a push
 	operation.  See the section <<URLS,GIT URLS>> below.

+	The default behavior of the command when no repository is specified
+	is to push to "origin" if \--all is given, to push to all mirror
+	remotes if \--mirror is given, and to do both actions if neither
+	\--all nor \--mirror is given.
+
 <refspec>::
 	The canonical format of a <refspec> parameter is
 	`+?<src>:<dst>`; that is, an optional plus `+`, followed
@@ -69,9 +74,11 @@ the remote repository.
 	be mirrored to the remote repository.  Newly created local
 	refs will be pushed to the remote end, locally updated refs
 	will be force updated on the remote end, and deleted refs
-	will be removed from the remote end.  This is the default
-	if the configuration option `remote.<remote>.mirror` is
-	set.
+	will be removed from the remote end.
+
+	When a <repository> is given on the command line, git looks up the
+	corresponding configuration option `remote.<repository>.mirror`
+	and enables mirror mode if it is set.

 \--dry-run::
 	Do everything except actually send the updates.
@@ -97,8 +104,8 @@ the remote repository.
 	remote repository to lose commits; use it with care.

 \--repo=<repo>::
-	When no repository is specified the command defaults to
-	"origin"; this overrides it.
+	Overrides the default behavior of the command when no repository
+	is specified, so that <repo> is used as the destination repository.

 \--thin, \--no-thin::
 	These options are passed to `git-send-pack`.  Thin
diff --git a/builtin-push.c b/builtin-push.c
index e992c37..3756d5e 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -48,14 +48,9 @@ static void set_refspecs(const char **refs, int nr)
 	}
 }

-static int do_push(const char *repo, int flags)
+static int do_push(struct remote *remote, int flags)
 {
 	int i, errs;
-	struct remote *remote = remote_get(repo);
-
-	if (!remote)
-		die("bad repository '%s'", repo);
-
 	if (remote->mirror)
 		flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);

@@ -99,6 +94,18 @@ static int do_push(const char *repo, int flags)
 	return !!errs;
 }

+static int push_to_mirrors(struct remote *remote, void *priv)
+{
+	int *p_flags = priv;
+	int rc = 0;
+	if (remote->mirror)
+		rc = do_push (remote, *p_flags);
+	
+	/* No command-line errors should occur.  */
+	assert (rc != -1);
+	return rc;
+}
+
 int cmd_push(int argc, const char **argv, const char *prefix)
 {
 	int flags = 0;
@@ -109,6 +116,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 	int tags = 0;
 	int rc;
 	const char *repo = NULL;	/* default repository */
+	struct remote *remote;

 	struct option options[] = {
 		OPT__VERBOSE(&verbose),
@@ -144,9 +152,22 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 		set_refspecs(argv + 1, argc - 1);
 	}

-	rc = do_push(repo, flags);
-	if (rc == -1)
-		usage_with_options(push_usage, options);
-	else
-		return rc;
+	/* "git push --mirror" will only push to mirrors.  */
+	if (repo || !mirror) {
+		remote = remote_get(repo);
+		if (!remote)
+			die("bad repository '%s'", repo);
+	
+		rc = do_push(remote, flags);
+		if (rc == -1)
+			usage_with_options(push_usage, options);
+	}
+
+	/* "git push" with only --force, --dry-run, --verbose, --mirror options
+	   will also (or, in the case of "git push --mirror", only) push to
+	   all mirrors.  */
+	if (!rc && !repo && !refspec && !all)
+		rc = for_each_remote (push_to_mirrors, &flags);
+	
+	return rc;
 }
diff --git a/t/t5517-push-mirror.sh b/t/t5517-push-mirror.sh
index ea49ded..beb71f4 100755
--- a/t/t5517-push-mirror.sh
+++ b/t/t5517-push-mirror.sh
@@ -29,6 +29,26 @@ mk_repo_pair () {
 	)
 }

+# a more complicated setup where we have also an origin repo
+mk_repo_threesome () {
+	rm -rf master mirror origin &&
+	mkdir mirror &&
+	(
+		cd mirror &&
+		git init
+	) &&
+	mkdir origin &&
+	(
+		cd origin &&
+		git init
+		echo one >foo && git add foo && git commit -m one
+	) &&
+	git clone origin master &&
+	(
+		cd master &&
+		git remote add --mirror up ../mirror
+	)
+}

 # BRANCH tests
 test_expect_success 'push mirror creates new branches' '
@@ -264,4 +284,70 @@ test_expect_success 'remote.foo.mirror=no has no effect' '

 '

+test_expect_success 'mirrors are updated by "git push"' '
+
+	mk_repo_threesome &&
+	(
+		cd master &&
+		git branch keep master &&
+		git branch remove master &&
+		git push &&
+		git branch -D remove
+		git push
+	) &&
+	(
+		cd mirror &&
+		git show-ref -s --verify refs/heads/keep &&
+		invert git show-ref -s --verify refs/heads/remove
+	) &&
+	(
+		cd origin &&
+		invert git show-ref -s --verify refs/heads/keep &&
+		invert git show-ref -s --verify refs/heads/remove
+	)
+
+'
+
+test_expect_success 'mirrors are not updated by "git push --all"' '
+
+	mk_repo_threesome &&
+	(
+		cd master &&
+		git branch b1 master &&
+		git push --all
+	) &&
+	(
+		cd mirror &&
+		invert git show-ref -s --verify refs/heads/b1
+	) &&
+	(
+		cd origin &&
+		git show-ref -s --verify refs/heads/b1
+	)
+
+'
+
+test_expect_success 'mirrors are not updated by "git push --repo" or "git push <repo>"' '
+
+	mk_repo_threesome &&
+	(
+		cd master &&
+		git branch b1 master &&
+		git push origin
+		git branch b2 master &&
+		git push --repo=origin
+	) &&
+	(
+		cd mirror &&
+		invert git show-ref -s --verify refs/heads/b1 &&
+		invert git show-ref -s --verify refs/heads/b2
+	) &&
+	(
+		cd origin &&
+		invert git show-ref -s --verify refs/heads/b1 &&
+		invert git show-ref -s --verify refs/heads/b2
+	)
+
+'
+
 test_done
-- 
1.5.5

^ permalink raw reply related	[flat|nested] 74+ messages in thread

end of thread, other threads:[~2008-05-14 19:41 UTC | newest]

Thread overview: 74+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-26  7:31 [PATCH resend] make "git push" update origin and mirrors, "git push --mirror" update mirrors Paolo Bonzini
2008-04-26 17:01 ` Shawn O. Pearce
2008-04-26 17:46   ` Junio C Hamano
2008-04-27  4:30     ` Shawn O. Pearce
2008-04-27  4:40       ` Shawn O. Pearce
2008-04-27  5:23         ` Junio C Hamano
2008-04-27 17:34           ` Shawn O. Pearce
2008-04-27 20:13             ` Junio C Hamano
2008-04-27 20:22               ` Paolo Bonzini
2008-04-28  1:26                 ` Jeff King
2008-04-28  5:07                   ` Paolo Bonzini
2008-04-28  9:09                     ` Jeff King
2008-04-28  9:11                       ` Jeff King
2008-04-28  9:19                         ` Paolo Bonzini
2008-04-28 10:33                           ` Johannes Schindelin
2008-04-28 11:24                             ` Paolo Bonzini
2008-04-28 11:57                               ` Johannes Schindelin
2008-04-28  3:32               ` Shawn O. Pearce
2008-04-28  5:03                 ` Paolo Bonzini
2008-04-28  6:08                 ` Stephen R. van den Berg
2008-04-28  1:21             ` Jeff King
2008-04-27  9:03         ` Paolo Bonzini
2008-04-27  7:23   ` Paolo Bonzini
2008-04-28 15:32 ` [PATCH 0/7] limit the usage of the default remote "origin" to the minimum Paolo Bonzini
2008-04-28 15:32   ` [PATCH 1/7] add special "matching refs" refspec Paolo Bonzini
2008-04-28 15:32     ` [PATCH 2/7] add push line in git-clone Paolo Bonzini
2008-04-28 15:32       ` [PATCH 3/7] Add a --push option to "git-remote add" Paolo Bonzini
2008-04-28 15:32         ` [PATCH 4/7] make "git push" update all push repositories Paolo Bonzini
2008-04-28 15:32           ` [PATCH 5/7] don't rely on zero-argument "git fetch" from within git pull Paolo Bonzini
2008-04-28 15:32             ` [PATCH 6/7] warn on "git pull" without a given branch.<name>.remote value Paolo Bonzini
2008-04-28 15:32               ` [PATCH 7/7] make "git fetch" update all fetch repositories Paolo Bonzini
2008-04-28 18:10                 ` Alex Riesen
2008-04-28 18:19                   ` Paolo Bonzini
2008-04-28 21:33                     ` Alex Riesen
2008-04-29  4:52                       ` Paolo Bonzini
2008-04-29  5:38                         ` Alex Riesen
2008-04-29  6:05                           ` Andreas Ericsson
2008-04-29  6:55                             ` Paolo Bonzini
2008-04-29 16:13                               ` Johannes Schindelin
2008-04-29 16:40                                 ` Paolo Bonzini
2008-04-29 20:34                                   ` Alex Riesen
2008-04-29  6:50                           ` Paolo Bonzini
2008-04-29  7:16                             ` Andreas Ericsson
2008-04-29  7:57                               ` Paolo Bonzini
2008-04-29  8:48                                 ` Andreas Ericsson
2008-04-29  9:02                                   ` Paolo Bonzini
2008-04-29 21:08                                   ` しらいしななこ
     [not found]                                   ` <200804292108.m3TL8moV011790@mi1.bluebottle.com>
2008-04-29 21:21                                     ` Paolo Bonzini
2008-04-29 22:21                                       ` Johannes Schindelin
2008-04-29 20:44                                 ` Alex Riesen
2008-04-29 21:15                                   ` Paolo Bonzini
2008-04-29 21:33                                     ` Alex Riesen
2008-04-29 21:41                                       ` Paolo Bonzini
2008-04-29 21:53                                         ` Alex Riesen
2008-04-29 22:26                                         ` Johannes Schindelin
2008-04-29 23:02                                           ` Jeff King
2008-04-29 23:17                                             ` Junio C Hamano
2008-04-30  5:28                                               ` Paolo Bonzini
2008-04-29 21:39                                   ` Johannes Schindelin
2008-04-29 20:24                             ` Alex Riesen
2008-05-01  6:28       ` [PATCH 2/7] add push line in git-clone Junio C Hamano
2008-05-06  8:37         ` Paolo Bonzini
2008-05-14 15:20           ` Paolo Bonzini
2008-05-14 18:16             ` Junio C Hamano
2008-05-14 19:07               ` Paolo Bonzini
2008-05-14 19:23                 ` Junio C Hamano
2008-05-14 19:40                   ` Paolo Bonzini
2008-04-30  9:23     ` [PATCH 1/7] add special "matching refs" refspec Junio C Hamano
2008-04-30  9:35       ` Paolo Bonzini
2008-04-29 19:35   ` [PATCH 0/7] limit the usage of the default remote "origin" to the minimum Jeff King
2008-04-29 21:42     ` Alex Riesen
2008-04-29 21:56     ` Junio C Hamano
2008-04-29 23:12       ` Jeff King
2008-04-30  5:24         ` Paolo Bonzini

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).