From: Finn Arne Gangstad <finnag@pvv.org>
To: git@vger.kernel.org
Subject: [PATCH 3/7] git push: New options --matching and --current
Date: Mon, 9 Mar 2009 23:35:47 +0100 [thread overview]
Message-ID: <1236638151-6465-4-git-send-email-finnag@pvv.org> (raw)
In-Reply-To: <1236638151-6465-1-git-send-email-finnag@pvv.org>
--matching: Push all branches that already exist with the same name in
the remote
--current: Push the current branch to whatever it is tracking
Signed-off-by: Finn Arne Gangstad <finnag@pvv.org>
---
Documentation/git-push.txt | 10 +++++-
builtin-push.c | 87 +++++++++++++++++++++++++++++++++++---------
transport.h | 9 +++++
3 files changed, 87 insertions(+), 19 deletions(-)
diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 4e7e5a7..cb7b3d2 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -9,7 +9,8 @@ git-push - Update remote refs along with associated objects
SYNOPSIS
--------
[verse]
-'git push' [--all | --mirror | --tags] [--dry-run] [--receive-pack=<git-receive-pack>]
+'git push' [--all | --mirror | --tags | --matching | --current]
+ [--dry-run] [--receive-pack=<git-receive-pack>]
[--repo=<repository>] [-f | --force] [-v | --verbose]
[<repository> <refspec>...]
@@ -82,6 +83,13 @@ nor in any Push line of the corresponding remotes file---see below).
if the configuration option `remote.<remote>.mirror` is
set.
+--matching::
+ For every branch on the local side, the remote side is updated if
+ a branch of the same name already exists there.
+
+--current::
+ Push the current branch to the branch it is tracking on the remote.
+
--dry-run::
Do everything except actually send the updates.
diff --git a/builtin-push.c b/builtin-push.c
index 122fdcf..5706c99 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] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]",
+ "git push [--all | --mirror | --current | --matching] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]",
NULL,
};
@@ -48,6 +48,53 @@ static void set_refspecs(const char **refs, int nr)
}
}
+static const char *make_push_ref(const char *a, const char *b)
+{
+ char *buf = xmalloc(strlen(a) + strlen(b) + 2);
+ strcpy(buf, a);
+ strcat(buf, ":");
+ strcat(buf, b);
+ return buf;
+}
+
+static void setup_push_current(struct remote *remote)
+{
+ int n;
+ struct branch *branch = branch_get(NULL);
+ if (!branch)
+ die("You are not currently on a branch.");
+ if (!branch->merge_nr)
+ die("The current branch %s is not tracking anything.",
+ branch->name);
+ if (branch->remote != remote)
+ die("The current branch is tracking \"%s\", not \"%s\"!",
+ branch->remote->name, remote->name);
+ for (n = 0; n < branch->merge_nr; n++)
+ add_refspec(make_push_ref(branch->name,
+ branch->merge[n]->src));
+}
+
+static void handle_default_push(struct remote *remote, int *flags)
+{
+ git_config(git_default_config, NULL);
+ switch (push_default) {
+ case PUSH_DEFAULT_UNSPECIFIED:
+ /* fallthrough */
+
+ case PUSH_DEFAULT_MATCHING:
+ add_refspec(":");
+ break;
+
+ case PUSH_DEFAULT_CURRENT:
+ setup_push_current(remote);
+ break;
+
+ case PUSH_DEFAULT_NOTHING:
+ die("No refspec given, and none configured.");
+ break;
+ }
+}
+
static int do_push(const char *repo, int flags)
{
int i, errs;
@@ -59,29 +106,29 @@ static int do_push(const char *repo, int flags)
if (remote->mirror)
flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
- if ((flags & TRANSPORT_PUSH_ALL) && refspec) {
+ if ((flags & TRANSPORT_PUSH_MODE_MASK) && refspec) {
if (!strcmp(*refspec, "refs/tags/*"))
- return error("--all and --tags are incompatible");
- return error("--all can't be combined with refspecs");
+ return error("--tags cannot be combined with a push mode");
+ return error("push modes cannot be combined with explicit refspecs");
}
- if ((flags & TRANSPORT_PUSH_MIRROR) && refspec) {
- if (!strcmp(*refspec, "refs/tags/*"))
- return error("--mirror and --tags are incompatible");
- return error("--mirror can't be combined with refspecs");
- }
+ if (HAS_MULTI_BITS(flags & TRANSPORT_PUSH_MODE_MASK))
+ return error("Multiple push modes specified");
- if ((flags & (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) ==
- (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) {
- return error("--all and --mirror are incompatible");
- }
+ if (flags & TRANSPORT_PUSH_CURRENT)
+ setup_push_current(remote);
+ else if (flags & TRANSPORT_PUSH_MATCHING)
+ add_refspec(":");
- if (!refspec
- && !(flags & TRANSPORT_PUSH_ALL)
- && remote->push_refspec_nr) {
- refspec = remote->push_refspec;
- refspec_nr = remote->push_refspec_nr;
+ if (!refspec && !(flags & TRANSPORT_PUSH_MODE_MASK)) {
+ if (remote->push_refspec_nr) {
+ refspec = remote->push_refspec;
+ refspec_nr = remote->push_refspec_nr;
+ } else {
+ handle_default_push(remote, &flags);
+ }
}
+
errs = 0;
for (i = 0; i < remote->url_nr; i++) {
struct transport *transport =
@@ -120,6 +167,10 @@ int cmd_push(int argc, const char **argv, const char *prefix)
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)),
+ OPT_BIT( 0 , "matching", &flags, "push all matching refs",
+ TRANSPORT_PUSH_MATCHING),
+ OPT_BIT( 0 , "current", &flags, "push current branch",
+ TRANSPORT_PUSH_CURRENT),
OPT_BOOLEAN( 0 , "tags", &tags, "push tags"),
OPT_BIT( 0 , "dry-run", &flags, "dry run", TRANSPORT_PUSH_DRY_RUN),
OPT_BIT('f', "force", &flags, "force updates", TRANSPORT_PUSH_FORCE),
diff --git a/transport.h b/transport.h
index 6bbc1a8..b897d0c 100644
--- a/transport.h
+++ b/transport.h
@@ -34,6 +34,15 @@ struct transport {
#define TRANSPORT_PUSH_DRY_RUN 4
#define TRANSPORT_PUSH_MIRROR 8
#define TRANSPORT_PUSH_VERBOSE 16
+#define TRANSPORT_PUSH_MATCHING 32
+#define TRANSPORT_PUSH_CURRENT 64
+/**
+ * All push flags that imply a certain set of refspecs to be pushed must
+ * be combined into TRANSPORT_PUSH_MODE_MASK
+ **/
+#define TRANSPORT_PUSH_MODE_MASK \
+ (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR | TRANSPORT_PUSH_MATCHING | \
+ TRANSPORT_PUSH_CURRENT)
/* Returns a transport suitable for the url */
struct transport *transport_get(struct remote *, const char *);
--
1.6.2.105.g6ff1f.dirty
next prev parent reply other threads:[~2009-03-09 23:18 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-09 22:35 [RFC/PATCH] git push usability improvements and default change Finn Arne Gangstad
2009-03-09 22:35 ` [PATCH 1/7] remote: Make "-" an alias for the current remote Finn Arne Gangstad
2009-03-09 22:35 ` [PATCH 2/7] New config option push.default Finn Arne Gangstad
2009-03-09 22:35 ` Finn Arne Gangstad [this message]
2009-03-09 23:49 ` [PATCH 3/7] git push: New options --matching and --current Daniel Barkalow
2009-03-10 8:54 ` Finn Arne Gangstad
2009-03-09 22:35 ` [PATCH 4/7] git push: Display warning on unconfigured default push Finn Arne Gangstad
2009-03-10 0:25 ` Jay Soffian
2009-03-09 22:35 ` [PATCH 5/7] git push: Document that "nothing" is the future push default Finn Arne Gangstad
2009-03-09 22:35 ` [PATCH 6/7] git push: Change default for "git push" to nothing Finn Arne Gangstad
2009-03-09 22:35 ` [PATCH 7/7] git push: Remove warning for "git push" default change Finn Arne Gangstad
2009-03-09 23:35 ` [RFC/PATCH] git push usability improvements and " Johannes Schindelin
2009-03-10 0:12 ` Junio C Hamano
2009-03-10 8:46 ` Finn Arne Gangstad
2009-03-10 11:01 ` Johannes Schindelin
2009-03-10 11:12 ` Finn Arne Gangstad
2009-03-10 0:07 ` Junio C Hamano
2009-03-10 0:19 ` Junio C Hamano
2009-03-10 10:04 ` Finn Arne Gangstad
2009-03-10 16:20 ` Jay Soffian
2009-03-11 20:35 ` Junio C Hamano
2009-03-12 3:01 ` Nanako Shiraishi
2009-03-12 10:22 ` Finn Arne Gangstad
2009-03-12 10:52 ` Miles Bader
2009-03-12 12:20 ` Finn Arne Gangstad
2009-03-13 8:28 ` Miles Bader
2009-03-13 10:07 ` John Tapsell
2009-03-10 17:52 ` Jeff King
2009-03-10 22:04 ` Finn Arne Gangstad
2009-03-10 22:10 ` Jeff King
2009-03-11 1:57 ` Jay Soffian
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=1236638151-6465-4-git-send-email-finnag@pvv.org \
--to=finnag@pvv.org \
--cc=git@vger.kernel.org \
/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).