git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-push: add option --repo-all
@ 2009-09-18  7:17 Kirill A. Korinskiy
  2009-09-18  8:52 ` Jakub Narebski
  0 siblings, 1 reply; 6+ messages in thread
From: Kirill A. Korinskiy @ 2009-09-18  7:17 UTC (permalink / raw)
  To: gitster; +Cc: git, Kirill A. Korinskiy

Example of usage: I write some software on my laptop and some time
pushing to my home/private server for backup. Some time ago my
software is done and I openin it on github, but I'm don't like kill my
private repos. Now update a two remotes repo is'n sexy, because I'm
need using a some shell wrapper:

    git remote show | while read repo; do git push $repo; done
---
 Documentation/git-push.txt |    4 ++-
 builtin-push.c             |   34 +++++++++++++++++++++-----------
 t/t5523-push-repo-all.sh   |   46 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 13 deletions(-)
 create mode 100755 t/t5523-push-repo-all.sh

diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index ba6a8a2..734e745 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -10,7 +10,6 @@ SYNOPSIS
 --------
 [verse]
 'git push' [--all | --mirror | --tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
-	   [--repo=<repository>] [-f | --force] [-v | --verbose]
 	   [<repository> <refspec>...]
 
 DESCRIPTION
@@ -134,6 +133,9 @@ useful if you write an alias or script around 'git-push'.
 	transfer spends extra cycles to minimize the number of
 	objects to be sent and meant to be used on slower connection.
 
+--repo-all::
+	Send changes to all remote repos.
+
 -v::
 --verbose::
 	Run verbosely.
diff --git a/builtin-push.c b/builtin-push.c
index 3cb1ee4..2b25293 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -10,7 +10,7 @@
 #include "parse-options.h"
 
 static const char * const push_usage[] = {
-	"git push [--all | --mirror] [-n | --dry-run] [--porcelain] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]",
+	"git push [--all | --mirror] [-n | --dry-run] [--porcelain] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository> | --repo-all] [-f | --force] [-v] [<repository> <refspec>...]",
 	NULL,
 };
 
@@ -88,19 +88,13 @@ static void setup_default_push_refspecs(void)
 	}
 }
 
-static int do_push(const char *repo, int flags)
+static int do_push(struct remote *remote, void *priv)
 {
+	int flags = *((int *)priv);
 	int i, errs;
-	struct remote *remote = remote_get(repo);
 	const char **url;
 	int url_nr;
 
-	if (!remote) {
-		if (repo)
-			die("bad repository '%s'", repo);
-		die("No destination configured to push to.");
-	}
-
 	if (remote->mirror)
 		flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
 
@@ -171,13 +165,16 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 {
 	int flags = 0;
 	int tags = 0;
+	int repo_all = 0;
 	int rc;
+	struct remote *remote;
 	const char *repo = NULL;	/* default repository */
 
 	struct option options[] = {
 		OPT_BIT('q', "quiet", &flags, "be quiet", TRANSPORT_PUSH_QUIET),
 		OPT_BIT('v', "verbose", &flags, "be verbose", TRANSPORT_PUSH_VERBOSE),
 		OPT_STRING( 0 , "repo", &repo, "repository", "repository"),
+		OPT_BOOLEAN( 0 , "repo-all", &repo_all, "push to all remote repos"),
 		OPT_BIT( 0 , "all", &flags, "push all refs", TRANSPORT_PUSH_ALL),
 		OPT_BIT( 0 , "mirror", &flags, "mirror all refs",
 			    (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
@@ -197,11 +194,24 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 		add_refspec("refs/tags/*");
 
 	if (argc > 0) {
-		repo = argv[0];
-		set_refspecs(argv + 1, argc - 1);
+		if (repo_all) {
+			set_refspecs(argv, argc);
+		} else {
+			repo = argv[0];
+			set_refspecs(argv + 1, argc - 1);
+		}
 	}
 
-	rc = do_push(repo, flags);
+	remote = remote_get(repo);
+	if (!remote && !repo_all) {
+		if (repo)
+			die("bad repository '%s'", repo);
+		die("No destination configured to push to.");
+	}
+
+	rc = repo_all ?
+		for_each_remote(do_push, &flags) : do_push(remote, &flags);
+
 	if (rc == -1)
 		usage_with_options(push_usage, options);
 	else
diff --git a/t/t5523-push-repo-all.sh b/t/t5523-push-repo-all.sh
new file mode 100755
index 0000000..865b8a1
--- /dev/null
+++ b/t/t5523-push-repo-all.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+test_description='pushing to all remote repos repository'
+
+. ./test-lib.sh
+
+mk_repos () {
+	rm -rf maste mirror-1 mirror-2 &&
+	mkdir mirror-1 &&
+	(
+		cd mirror-1 &&
+		git init
+	) &&
+	mkdir mirror-2 &&
+	(
+		cd mirror-2 &&
+		git init
+	) &&
+	mkdir master &&
+	(
+		cd master &&
+		git init &&
+		git remote add mirror-1 ../mirror-1
+		git remote add mirror-2 ../mirror-2
+	)
+}
+
+
+test_expect_success 'push to mirrors' '
+
+	mk_repos &&
+	(
+		cd master &&
+		echo one >foo && git add foo && git commit -m one &&
+		git remote show &&
+		git push --all --repo-all -f
+	) &&
+	master_master=$(cd master && git show-ref -s --verify refs/heads/master) &&
+	mirror_1_master=$(cd mirror-1 && git show-ref -s --verify refs/heads/master) &&
+	mirror_2_master=$(cd mirror-2 && git show-ref -s --verify refs/heads/master) &&
+	test "$master_master" = "$mirror_1_master" &&
+	test "$master_master" = "$mirror_2_master"
+
+'
+
+test_done
-- 
1.6.2

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

* Re: [PATCH] git-push: add option --repo-all
  2009-09-18  7:17 [PATCH] git-push: add option --repo-all Kirill A. Korinskiy
@ 2009-09-18  8:52 ` Jakub Narebski
  2009-09-18 10:44   ` Kirill A. Korinskiy
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jakub Narebski @ 2009-09-18  8:52 UTC (permalink / raw)
  To: Kirill A. Korinskiy; +Cc: gitster, git

"Kirill A. Korinskiy" <catap@catap.ru> writes:

> Example of usage: I write some software on my laptop and some time
> pushing to my home/private server for backup. Some time ago my
> software is done and I openin it on github, but I'm don't like kill my
> private repos. Now update a two remotes repo is'n sexy, because I'm
> need using a some shell wrapper:
> 
>     git remote show | while read repo; do git push $repo; done

Signoff?

> ---
>  Documentation/git-push.txt |    4 ++-
>  builtin-push.c             |   34 +++++++++++++++++++++-----------
>  t/t5523-push-repo-all.sh   |   46 ++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 71 insertions(+), 13 deletions(-)
>  create mode 100755 t/t5523-push-repo-all.sh

I have created 'pushall' *alias* for that purpose, but I think that
such functionality would be better added to "git remote" rather than
to "git push".

-- 
Jakub Narebski
Poland
ShadeHawk on #git

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

* [PATCH] git-push: add option --repo-all
  2009-09-18  8:52 ` Jakub Narebski
@ 2009-09-18 10:44   ` Kirill A. Korinskiy
       [not found]   ` <877hvwzkw7.wl%catap@catap.ru>
  2009-09-18 16:42   ` Junio C Hamano
  2 siblings, 0 replies; 6+ messages in thread
From: Kirill A. Korinskiy @ 2009-09-18 10:44 UTC (permalink / raw)
  To: gitster; +Cc: git, Kirill A. Korinskiy

Example of usage: I write some software on my laptop and some time
pushing to my home/private server for backup. Some time ago my
software is done and I openin it on github, but I'm don't like kill my
private repos. Now update a two remotes repo is'n sexy, because I'm
need using a some shell wrapper:

    git remote show | while read repo; do git push $repo; done

Signed-off-by: Kirill A. Korinskiy <catap@catap.ru>
---
 Documentation/git-push.txt |    3 ++
 builtin-push.c             |   34 +++++++++++++++++++++-----------
 t/t5523-push-repo-all.sh   |   46 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 12 deletions(-)
 create mode 100755 t/t5523-push-repo-all.sh

diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index ba6a8a2..92e45c2 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -134,6 +134,9 @@ useful if you write an alias or script around 'git-push'.
 	transfer spends extra cycles to minimize the number of
 	objects to be sent and meant to be used on slower connection.
 
+--repo-all::
+	Send changes to all remote repos.
+
 -v::
 --verbose::
 	Run verbosely.
diff --git a/builtin-push.c b/builtin-push.c
index 3cb1ee4..2b25293 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -10,7 +10,7 @@
 #include "parse-options.h"
 
 static const char * const push_usage[] = {
-	"git push [--all | --mirror] [-n | --dry-run] [--porcelain] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]",
+	"git push [--all | --mirror] [-n | --dry-run] [--porcelain] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository> | --repo-all] [-f | --force] [-v] [<repository> <refspec>...]",
 	NULL,
 };
 
@@ -88,19 +88,13 @@ static void setup_default_push_refspecs(void)
 	}
 }
 
-static int do_push(const char *repo, int flags)
+static int do_push(struct remote *remote, void *priv)
 {
+	int flags = *((int *)priv);
 	int i, errs;
-	struct remote *remote = remote_get(repo);
 	const char **url;
 	int url_nr;
 
-	if (!remote) {
-		if (repo)
-			die("bad repository '%s'", repo);
-		die("No destination configured to push to.");
-	}
-
 	if (remote->mirror)
 		flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
 
@@ -171,13 +165,16 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 {
 	int flags = 0;
 	int tags = 0;
+	int repo_all = 0;
 	int rc;
+	struct remote *remote;
 	const char *repo = NULL;	/* default repository */
 
 	struct option options[] = {
 		OPT_BIT('q', "quiet", &flags, "be quiet", TRANSPORT_PUSH_QUIET),
 		OPT_BIT('v', "verbose", &flags, "be verbose", TRANSPORT_PUSH_VERBOSE),
 		OPT_STRING( 0 , "repo", &repo, "repository", "repository"),
+		OPT_BOOLEAN( 0 , "repo-all", &repo_all, "push to all remote repos"),
 		OPT_BIT( 0 , "all", &flags, "push all refs", TRANSPORT_PUSH_ALL),
 		OPT_BIT( 0 , "mirror", &flags, "mirror all refs",
 			    (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
@@ -197,11 +194,24 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 		add_refspec("refs/tags/*");
 
 	if (argc > 0) {
-		repo = argv[0];
-		set_refspecs(argv + 1, argc - 1);
+		if (repo_all) {
+			set_refspecs(argv, argc);
+		} else {
+			repo = argv[0];
+			set_refspecs(argv + 1, argc - 1);
+		}
 	}
 
-	rc = do_push(repo, flags);
+	remote = remote_get(repo);
+	if (!remote && !repo_all) {
+		if (repo)
+			die("bad repository '%s'", repo);
+		die("No destination configured to push to.");
+	}
+
+	rc = repo_all ?
+		for_each_remote(do_push, &flags) : do_push(remote, &flags);
+
 	if (rc == -1)
 		usage_with_options(push_usage, options);
 	else
diff --git a/t/t5523-push-repo-all.sh b/t/t5523-push-repo-all.sh
new file mode 100755
index 0000000..865b8a1
--- /dev/null
+++ b/t/t5523-push-repo-all.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+test_description='pushing to all remote repos repository'
+
+. ./test-lib.sh
+
+mk_repos () {
+	rm -rf maste mirror-1 mirror-2 &&
+	mkdir mirror-1 &&
+	(
+		cd mirror-1 &&
+		git init
+	) &&
+	mkdir mirror-2 &&
+	(
+		cd mirror-2 &&
+		git init
+	) &&
+	mkdir master &&
+	(
+		cd master &&
+		git init &&
+		git remote add mirror-1 ../mirror-1
+		git remote add mirror-2 ../mirror-2
+	)
+}
+
+
+test_expect_success 'push to mirrors' '
+
+	mk_repos &&
+	(
+		cd master &&
+		echo one >foo && git add foo && git commit -m one &&
+		git remote show &&
+		git push --all --repo-all -f
+	) &&
+	master_master=$(cd master && git show-ref -s --verify refs/heads/master) &&
+	mirror_1_master=$(cd mirror-1 && git show-ref -s --verify refs/heads/master) &&
+	mirror_2_master=$(cd mirror-2 && git show-ref -s --verify refs/heads/master) &&
+	test "$master_master" = "$mirror_1_master" &&
+	test "$master_master" = "$mirror_2_master"
+
+'
+
+test_done
-- 
1.6.2

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

* Re: [PATCH] git-push: add option --repo-all
       [not found]   ` <877hvwzkw7.wl%catap@catap.ru>
@ 2009-09-18 11:02     ` Jakub Narebski
  2009-09-18 11:15       ` Paolo Bonzini
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Narebski @ 2009-09-18 11:02 UTC (permalink / raw)
  To: Kirill A. Korinskiy; +Cc: git

Kirill A. Korinskiy wrote:
> At Fri, 18 Sep 2009 01:52:49 -0700 (PDT),
> Jakub Narebski <jnareb@gmail.com> wrote:
> > "Kirill A. Korinskiy" <catap@catap.ru> writes:

> > > ---
> > >  Documentation/git-push.txt |    4 ++-
> > >  builtin-push.c             |   34 +++++++++++++++++++++-----------
> > >  t/t5523-push-repo-all.sh   |   46 ++++++++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 71 insertions(+), 13 deletions(-)
> > >  create mode 100755 t/t5523-push-repo-all.sh
> > 
> > I have created 'pushall' *alias* for that purpose, but I think that
> > such functionality would be better added to "git remote" rather than
> > to "git push".
> 
> not sure, because git remote make interface for managment remotes
> repos and push make interface for pushing to remote repo. I just add a
> pushing to all repos.
> 
> I thought about pushing to some remotes repos, yes, but could not come
> up with a good symantics.

Well, git-remote has "git remote update" subcommand for fetching from
a group of remote repositories, so it is not only about managing remotes.
I think "git remote push" (or something like that) would fit in 
git-remote area of competence.

Besides git-remote understands groups of remote repositories for fetch
(update), which would be (I think) a good idea also for push.

-- 
Jakub Narebski
Poland

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

* Re: [PATCH] git-push: add option --repo-all
  2009-09-18 11:02     ` Jakub Narebski
@ 2009-09-18 11:15       ` Paolo Bonzini
  0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2009-09-18 11:15 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: Kirill A. Korinskiy, git


> Well, git-remote has "git remote update" subcommand for fetching from
> a group of remote repositories, so it is not only about managing remotes.
> I think "git remote push" (or something like that) would fit in
> git-remote area of competence.
>
> Besides git-remote understands groups of remote repositories for fetch
> (update), which would be (I think) a good idea also for push.

Agreed.

Paolo

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

* Re: [PATCH] git-push: add option --repo-all
  2009-09-18  8:52 ` Jakub Narebski
  2009-09-18 10:44   ` Kirill A. Korinskiy
       [not found]   ` <877hvwzkw7.wl%catap@catap.ru>
@ 2009-09-18 16:42   ` Junio C Hamano
  2 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2009-09-18 16:42 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: Kirill A. Korinskiy, git

Jakub Narebski <jnareb@gmail.com> writes:

> I have created 'pushall' *alias* for that purpose, but I think that
> such functionality would be better added to "git remote" rather than
> to "git push".

Also Linus added a mystery feature that you can have more than one pushURL
to a [remote "there"] section to push to multiple places quite a while
ago, so use of it is another possibile solution for what Kirill wants to
solve.

I do not think it is such a useful command line option that can be used to
only say "everything"; your suggestion to hook into the grouping mechanism
"git remote" has sounds much nicer.

Thanks.

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

end of thread, other threads:[~2009-09-18 16:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-18  7:17 [PATCH] git-push: add option --repo-all Kirill A. Korinskiy
2009-09-18  8:52 ` Jakub Narebski
2009-09-18 10:44   ` Kirill A. Korinskiy
     [not found]   ` <877hvwzkw7.wl%catap@catap.ru>
2009-09-18 11:02     ` Jakub Narebski
2009-09-18 11:15       ` Paolo Bonzini
2009-09-18 16:42   ` Junio C Hamano

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