git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
/*
|
|
|
|
* "git push"
|
|
|
|
*/
|
|
|
|
#include "cache.h"
|
|
|
|
#include "refs.h"
|
|
|
|
#include "run-command.h"
|
|
|
|
#include "builtin.h"
|
2007-05-12 19:45:53 +04:00
|
|
|
#include "remote.h"
|
2007-09-11 07:03:04 +04:00
|
|
|
#include "transport.h"
|
2007-11-05 06:35:37 +03:00
|
|
|
#include "parse-options.h"
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
|
2007-11-05 06:35:37 +03:00
|
|
|
static const char * const push_usage[] = {
|
2010-04-10 06:50:19 +04:00
|
|
|
"git push [<options>] [<repository> [<refspec>...]]",
|
2007-11-05 06:35:37 +03:00
|
|
|
NULL,
|
|
|
|
};
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
|
2008-07-20 16:02:20 +04:00
|
|
|
static int thin;
|
2009-12-30 22:57:42 +03:00
|
|
|
static int deleterefs;
|
2007-01-19 15:49:27 +03:00
|
|
|
static const char *receivepack;
|
2010-02-24 15:50:24 +03:00
|
|
|
static int verbosity;
|
2010-02-24 15:50:27 +03:00
|
|
|
static int progress;
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
|
2006-08-15 21:23:48 +04:00
|
|
|
static const char **refspec;
|
|
|
|
static int refspec_nr;
|
2010-07-31 16:54:55 +04:00
|
|
|
static int refspec_alloc;
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
|
|
|
|
static void add_refspec(const char *ref)
|
|
|
|
{
|
2010-07-31 16:54:55 +04:00
|
|
|
refspec_nr++;
|
|
|
|
ALLOC_GROW(refspec, refspec_nr, refspec_alloc);
|
|
|
|
refspec[refspec_nr-1] = ref;
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_refspecs(const char **refs, int nr)
|
|
|
|
{
|
2007-05-25 09:20:56 +04:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < nr; i++) {
|
|
|
|
const char *ref = refs[i];
|
|
|
|
if (!strcmp("tag", ref)) {
|
|
|
|
char *tag;
|
|
|
|
int len;
|
|
|
|
if (nr <= ++i)
|
|
|
|
die("tag shorthand without <tag>");
|
|
|
|
len = strlen(refs[i]) + 11;
|
2009-12-30 22:57:42 +03:00
|
|
|
if (deleterefs) {
|
|
|
|
tag = xmalloc(len+1);
|
|
|
|
strcpy(tag, ":refs/tags/");
|
|
|
|
} else {
|
|
|
|
tag = xmalloc(len);
|
|
|
|
strcpy(tag, "refs/tags/");
|
|
|
|
}
|
2007-05-25 09:20:56 +04:00
|
|
|
strcat(tag, refs[i]);
|
|
|
|
ref = tag;
|
2009-12-30 22:57:42 +03:00
|
|
|
} else if (deleterefs && !strchr(ref, ':')) {
|
|
|
|
char *delref;
|
|
|
|
int len = strlen(ref)+1;
|
2010-01-29 13:31:30 +03:00
|
|
|
delref = xmalloc(len+1);
|
2009-12-30 22:57:42 +03:00
|
|
|
strcpy(delref, ":");
|
|
|
|
strcat(delref, ref);
|
|
|
|
ref = delref;
|
|
|
|
} else if (deleterefs)
|
|
|
|
die("--delete only accepts plain target ref names");
|
2007-05-25 09:20:56 +04:00
|
|
|
add_refspec(ref);
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 18:42:51 +03:00
|
|
|
static void setup_push_tracking(void)
|
|
|
|
{
|
|
|
|
struct strbuf refspec = STRBUF_INIT;
|
|
|
|
struct branch *branch = branch_get(NULL);
|
|
|
|
if (!branch)
|
|
|
|
die("You are not currently on a branch.");
|
2010-02-24 20:08:53 +03:00
|
|
|
if (!branch->merge_nr || !branch->merge)
|
2009-03-16 18:42:51 +03:00
|
|
|
die("The current branch %s is not tracking anything.",
|
|
|
|
branch->name);
|
|
|
|
if (branch->merge_nr != 1)
|
|
|
|
die("The current branch %s is tracking multiple branches, "
|
|
|
|
"refusing to push.", branch->name);
|
|
|
|
strbuf_addf(&refspec, "%s:%s", branch->name, branch->merge[0]->src);
|
|
|
|
add_refspec(refspec.buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setup_default_push_refspecs(void)
|
|
|
|
{
|
|
|
|
switch (push_default) {
|
2009-07-19 04:19:47 +04:00
|
|
|
default:
|
2009-03-16 18:42:51 +03:00
|
|
|
case PUSH_DEFAULT_MATCHING:
|
|
|
|
add_refspec(":");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PUSH_DEFAULT_TRACKING:
|
|
|
|
setup_push_tracking();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PUSH_DEFAULT_CURRENT:
|
|
|
|
add_refspec("HEAD");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PUSH_DEFAULT_NOTHING:
|
|
|
|
die("You didn't specify any refspecs to push, and "
|
|
|
|
"push.default is \"nothing\".");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-18 04:42:22 +03:00
|
|
|
static int push_with_options(struct transport *transport, int flags)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int nonfastforward;
|
2010-02-24 15:50:24 +03:00
|
|
|
|
2010-02-24 15:50:27 +03:00
|
|
|
transport_set_verbosity(transport, verbosity, progress);
|
2010-02-24 15:50:24 +03:00
|
|
|
|
2009-11-18 04:42:22 +03:00
|
|
|
if (receivepack)
|
|
|
|
transport_set_option(transport,
|
|
|
|
TRANS_OPT_RECEIVEPACK, receivepack);
|
|
|
|
if (thin)
|
|
|
|
transport_set_option(transport, TRANS_OPT_THIN, "yes");
|
|
|
|
|
2010-02-24 15:50:24 +03:00
|
|
|
if (verbosity > 0)
|
2009-11-18 04:42:22 +03:00
|
|
|
fprintf(stderr, "Pushing to %s\n", transport->url);
|
|
|
|
err = transport_push(transport, refspec_nr, refspec, flags,
|
|
|
|
&nonfastforward);
|
2009-12-04 02:31:44 +03:00
|
|
|
if (err != 0)
|
|
|
|
error("failed to push some refs to '%s'", transport->url);
|
|
|
|
|
2009-11-18 04:42:22 +03:00
|
|
|
err |= transport_disconnect(transport);
|
|
|
|
|
|
|
|
if (!err)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (nonfastforward && advice_push_nonfastforward) {
|
2010-02-27 07:52:13 +03:00
|
|
|
fprintf(stderr, "To prevent you from losing history, non-fast-forward updates were rejected\n"
|
2010-08-02 17:42:44 +04:00
|
|
|
"Merge the remote changes (e.g. 'git pull') before pushing again. See the\n"
|
|
|
|
"'Note about fast-forwards' section of 'git push --help' for details.\n");
|
2009-11-18 04:42:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-09-11 07:03:04 +04:00
|
|
|
static int do_push(const char *repo, int flags)
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
{
|
2007-05-12 19:45:53 +04:00
|
|
|
int i, errs;
|
|
|
|
struct remote *remote = remote_get(repo);
|
2009-06-09 20:01:34 +04:00
|
|
|
const char **url;
|
|
|
|
int url_nr;
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
|
Give error when no remote is configured
When there's no explicitly-named remote, we use the remote specified
for the current branch, which in turn defaults to "origin". But it
this case should require the remote to actually be configured, and not
fall back to the path "origin".
Possibly, the config file's "remote = something" should require the
something to be a configured remote instead of a bare repository URL,
but we actually test with a bare repository URL.
In fetch, we were giving the sensible error message when coming up
with a URL failed, but this wasn't actually reachable, so move that
error up and use it when appropriate.
In push, we need a new error message, because the old one (formerly
unreachable without a lot of help) used the repo name, which was NULL.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-03-11 08:47:20 +03:00
|
|
|
if (!remote) {
|
|
|
|
if (repo)
|
|
|
|
die("bad repository '%s'", repo);
|
|
|
|
die("No destination configured to push to.");
|
|
|
|
}
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
|
2008-04-17 15:17:20 +04:00
|
|
|
if (remote->mirror)
|
|
|
|
flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
|
|
|
|
|
2008-08-16 21:58:32 +04:00
|
|
|
if ((flags & TRANSPORT_PUSH_ALL) && refspec) {
|
|
|
|
if (!strcmp(*refspec, "refs/tags/*"))
|
|
|
|
return error("--all and --tags are incompatible");
|
|
|
|
return error("--all can't be combined with 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");
|
|
|
|
}
|
2008-04-17 15:17:20 +04:00
|
|
|
|
|
|
|
if ((flags & (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) ==
|
|
|
|
(TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) {
|
|
|
|
return error("--all and --mirror are incompatible");
|
|
|
|
}
|
|
|
|
|
2009-03-16 18:42:51 +03:00
|
|
|
if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) {
|
|
|
|
if (remote->push_refspec_nr) {
|
|
|
|
refspec = remote->push_refspec;
|
|
|
|
refspec_nr = remote->push_refspec_nr;
|
|
|
|
} else if (!(flags & TRANSPORT_PUSH_MIRROR))
|
|
|
|
setup_default_push_refspecs();
|
2007-05-12 19:45:53 +04:00
|
|
|
}
|
2007-04-07 10:04:53 +04:00
|
|
|
errs = 0;
|
2009-06-09 20:01:34 +04:00
|
|
|
if (remote->pushurl_nr) {
|
|
|
|
url = remote->pushurl;
|
|
|
|
url_nr = remote->pushurl_nr;
|
|
|
|
} else {
|
|
|
|
url = remote->url;
|
|
|
|
url_nr = remote->url_nr;
|
|
|
|
}
|
2009-11-18 04:42:22 +03:00
|
|
|
if (url_nr) {
|
|
|
|
for (i = 0; i < url_nr; i++) {
|
|
|
|
struct transport *transport =
|
|
|
|
transport_get(remote, url[i]);
|
|
|
|
if (push_with_options(transport, flags))
|
|
|
|
errs++;
|
2009-08-08 11:51:08 +04:00
|
|
|
}
|
2009-11-18 04:42:22 +03:00
|
|
|
} else {
|
|
|
|
struct transport *transport =
|
|
|
|
transport_get(remote, NULL);
|
|
|
|
|
|
|
|
if (push_with_options(transport, flags))
|
|
|
|
errs++;
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
}
|
2007-04-07 10:04:53 +04:00
|
|
|
return !!errs;
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
}
|
|
|
|
|
2006-07-29 09:44:25 +04:00
|
|
|
int cmd_push(int argc, const char **argv, const char *prefix)
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
{
|
2007-09-11 07:03:04 +04:00
|
|
|
int flags = 0;
|
2007-11-05 06:35:37 +03:00
|
|
|
int tags = 0;
|
2008-04-17 15:17:20 +04:00
|
|
|
int rc;
|
2007-05-12 19:45:53 +04:00
|
|
|
const char *repo = NULL; /* default repository */
|
2007-11-05 06:35:37 +03:00
|
|
|
struct option options[] = {
|
2010-02-24 15:50:24 +03:00
|
|
|
OPT__VERBOSITY(&verbosity),
|
2007-11-05 06:35:37 +03:00
|
|
|
OPT_STRING( 0 , "repo", &repo, "repository", "repository"),
|
2008-07-20 16:02:20 +04:00
|
|
|
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)),
|
2009-12-30 22:57:42 +03:00
|
|
|
OPT_BOOLEAN( 0, "delete", &deleterefs, "delete refs"),
|
2009-10-30 18:04:53 +03:00
|
|
|
OPT_BOOLEAN( 0 , "tags", &tags, "push tags (can't be used with --all or --mirror)"),
|
2009-09-13 20:56:45 +04:00
|
|
|
OPT_BIT('n' , "dry-run", &flags, "dry run", TRANSPORT_PUSH_DRY_RUN),
|
2009-06-23 05:10:01 +04:00
|
|
|
OPT_BIT( 0, "porcelain", &flags, "machine-readable output", TRANSPORT_PUSH_PORCELAIN),
|
2008-07-20 16:02:20 +04:00
|
|
|
OPT_BIT('f', "force", &flags, "force updates", TRANSPORT_PUSH_FORCE),
|
2007-11-05 06:35:37 +03:00
|
|
|
OPT_BOOLEAN( 0 , "thin", &thin, "use thin pack"),
|
|
|
|
OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", "receive pack program"),
|
|
|
|
OPT_STRING( 0 , "exec", &receivepack, "receive-pack", "receive pack program"),
|
2010-01-17 00:45:31 +03:00
|
|
|
OPT_BIT('u', "set-upstream", &flags, "set upstream for git pull/status",
|
|
|
|
TRANSPORT_PUSH_SET_UPSTREAM),
|
2010-02-24 15:50:27 +03:00
|
|
|
OPT_BOOLEAN(0, "progress", &progress, "force progress reporting"),
|
2007-11-05 06:35:37 +03:00
|
|
|
OPT_END()
|
|
|
|
};
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
|
2009-10-25 22:15:22 +03:00
|
|
|
git_config(git_default_config, NULL);
|
2009-05-23 22:53:12 +04:00
|
|
|
argc = parse_options(argc, argv, prefix, options, push_usage, 0);
|
2007-11-05 06:35:37 +03:00
|
|
|
|
2009-12-30 22:57:42 +03:00
|
|
|
if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
|
|
|
|
die("--delete is incompatible with --all, --mirror and --tags");
|
|
|
|
if (deleterefs && argc < 2)
|
|
|
|
die("--delete doesn't make sense without any refs");
|
|
|
|
|
2007-11-05 06:35:37 +03:00
|
|
|
if (tags)
|
|
|
|
add_refspec("refs/tags/*");
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
repo = argv[0];
|
|
|
|
set_refspecs(argv + 1, argc - 1);
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
}
|
2007-05-25 09:20:56 +04:00
|
|
|
|
2008-04-17 15:17:20 +04:00
|
|
|
rc = do_push(repo, flags);
|
|
|
|
if (rc == -1)
|
2007-11-10 02:32:25 +03:00
|
|
|
usage_with_options(push_usage, options);
|
2008-04-17 15:17:20 +04:00
|
|
|
else
|
|
|
|
return rc;
|
git builtin "push"
This adds a builtin "push" command, which is largely just a C'ification of
the "git-push.sh" script.
Now, the reason I did it as a built-in is partly because it's yet another
step on relying less on shell, but it's actually mostly because I've
wanted to be able to push to _multiple_ repositories, and the most obvious
and simplest interface for that would seem be to just have a "remotes"
file that has multiple URL entries.
(For "pull", having multiple entries should either just select the first
one, or you could fall back on the others on failure - your choice).
And quite frankly, it just became too damn messy to do that in shell.
Besides, we actually have a fair amount of infrastructure in C, so it just
wasn't that hard to do.
Of course, this is almost totally untested. It probably doesn't work for
anything but the one trial I threw at it. "Simple" doesn't necessarily
mean "obviously correct".
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 08:22:49 +04:00
|
|
|
}
|