From: "Kirill A. Korinskiy" <catap@catap.ru>
To: gitster@pobox.com
Cc: git@vger.kernel.org, "Kirill A. Korinskiy" <catap@catap.ru>
Subject: [PATCH] git-push: add option --repo-all
Date: Fri, 18 Sep 2009 14:44:03 +0400 [thread overview]
Message-ID: <1253270643-20262-1-git-send-email-catap@catap.ru> (raw)
In-Reply-To: <m3r5u43a8h.fsf@localhost.localdomain>
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
next prev parent reply other threads:[~2009-09-18 10:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
[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
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=1253270643-20262-1-git-send-email-catap@catap.ru \
--to=catap@catap.ru \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).