Skip to contentSkip to conversation

git-push: add option --repo-all

PATCH In review Kirill A. Korinskiy 4 participants 6 messages Jun 15, 2016 1 message not in the archive Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-push: add option --repo-all

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
Documentation/git-push.txt +3 -1
index ba6a8a2..734e745 100644
@@ -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.
builtin-push.c +22 -12
index 3cb1ee4..2b25293 100644
@@ -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
t/t5523-push-repo-all.sh new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
1.6.2
#1 lore raw
Quoted 7 lines · 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

Signoff?

Quoted 6 lines
---
 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".

Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#2 lore raw

PATCH 1/1 git-push: add option --repo-all

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 |    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
Documentation/git-push.txt +3 -0
index ba6a8a2..92e45c2 100644
@@ -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.
builtin-push.c +22 -12
index 3cb1ee4..2b25293 100644
@@ -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
t/t5523-push-repo-all.sh new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
1.6.2
#3 lore raw
In reply to Jakub Narebski
Quoted 3 lines · Jakub Narebski

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.

A message that is not in the archive (sent off-list or not yet received): 877hvwzkw7.wl%[email protected]

#5 lore raw
Quoted 15 lines · Kirill A. Korinskiy

At Fri, 18 Sep 2009 01:52:49 -0700 (PDT),

Quoted 9 lines · Jakub Narebski
Quoted 6 lines · Kirill A. Korinskiy
---
 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
Quoted 3 lines

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

Quoted 6 lines

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.

Signature · 2 lines
Jakub Narebski
Poland
#6 lore raw
Quoted 8 lines

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