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 12:22:49 +08:00
|
|
|
/*
|
|
|
|
* "git push"
|
|
|
|
*/
|
|
|
|
#include "cache.h"
|
2017-06-15 02:07:36 +08:00
|
|
|
#include "config.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 12:22:49 +08:00
|
|
|
#include "refs.h"
|
2018-05-17 06:57:48 +08:00
|
|
|
#include "refspec.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 12:22:49 +08:00
|
|
|
#include "run-command.h"
|
|
|
|
#include "builtin.h"
|
2007-05-12 23:45:53 +08:00
|
|
|
#include "remote.h"
|
2007-09-11 11:03:04 +08:00
|
|
|
#include "transport.h"
|
2007-11-05 11:35:37 +08:00
|
|
|
#include "parse-options.h"
|
2011-08-20 06:08:47 +08:00
|
|
|
#include "submodule.h"
|
2015-11-17 19:05:56 +08:00
|
|
|
#include "submodule-config.h"
|
2015-08-19 23:26:46 +08:00
|
|
|
#include "send-pack.h"
|
2018-04-21 18:10:00 +08:00
|
|
|
#include "color.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 12:22:49 +08:00
|
|
|
|
2007-11-05 11:35:37 +08:00
|
|
|
static const char * const push_usage[] = {
|
2012-08-20 20:32:33 +08:00
|
|
|
N_("git push [<options>] [<repository> [<refspec>...]]"),
|
2007-11-05 11:35:37 +08: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 12:22:49 +08:00
|
|
|
|
2018-04-21 18:10:00 +08:00
|
|
|
static int push_use_color = -1;
|
|
|
|
static char push_colors[][COLOR_MAXLEN] = {
|
|
|
|
GIT_COLOR_RESET,
|
|
|
|
GIT_COLOR_RED, /* ERROR */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum color_push {
|
|
|
|
PUSH_COLOR_RESET = 0,
|
|
|
|
PUSH_COLOR_ERROR = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
static int parse_push_color_slot(const char *slot)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(slot, "reset"))
|
|
|
|
return PUSH_COLOR_RESET;
|
|
|
|
if (!strcasecmp(slot, "error"))
|
|
|
|
return PUSH_COLOR_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *push_get_color(enum color_push ix)
|
|
|
|
{
|
|
|
|
if (want_color_stderr(push_use_color))
|
|
|
|
return push_colors[ix];
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-08-12 21:55:55 +08:00
|
|
|
static int thin = 1;
|
2009-12-31 03:57:42 +08:00
|
|
|
static int deleterefs;
|
2007-01-19 20:49:27 +08:00
|
|
|
static const char *receivepack;
|
2010-02-24 20:50:24 +08:00
|
|
|
static int verbosity;
|
2015-12-03 21:10:35 +08:00
|
|
|
static int progress = -1;
|
|
|
|
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
|
2016-02-03 12:09:14 +08:00
|
|
|
static enum transport_family family;
|
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 12:22:49 +08:00
|
|
|
|
remote.c: add command line option parser for "--force-with-lease"
Update "git push" and "git send-pack" to parse this commnd line
option.
The intended sematics is:
* "--force-with-lease" alone, without specifying the details, will
protect _all_ remote refs that are going to be updated by
requiring their current value to be the same as some reasonable
default, unless otherwise specified;
* "--force-with-lease=refname", without specifying the expected
value, will protect that refname, if it is going to be updated,
by requiring its current value to be the same as some reasonable
default.
* "--force-with-lease=refname:value" will protect that refname, if
it is going to be updated, by requiring its current value to be
the same as the specified value; and
* "--no-force-with-lease" will cancel all the previous --force-with-lease on the
command line.
For now, "some reasonable default" is tentatively defined as "the
value of the remote-tracking branch we have for the ref of the
remote being updated", and it is an error if we do not have such a
remote-tracking branch. But this is known to be fragile, its use is
not yet recommended, and hopefully we will find more reasonable
default as we gain experience with this feature. The manual marks
the feature as experimental unless the expected value is specified
explicitly for this reason.
Because the command line options are parsed _before_ we know which
remote we are pushing to, there needs further processing to the
parsed data after we instantiate the transport object to:
* expand "refname" given by the user to a full refname to be
matched with the list of "struct ref" used in match_push_refs()
and set_ref_status_for_push(); and
* learning the actual local ref that is the remote-tracking branch
for the specified remote ref.
Further, some processing need to be deferred until we find the set
of remote refs and match_push_refs() returns in order to find the
ones that need to be checked after explicit ones have been processed
for "--force-with-lease" (no specific details).
These post-processing will be the topic of the next patch.
This option was originally called "cas" (for "compare and swap"),
the name which nobody liked because it was too technical. The
second attempt called it "lockref" (because it is conceptually like
pushing after taking a lock) but the word "lock" was hated because
it implied that it may reject push by others, which is not the way
this option works. This round calls it "force-with-lease". You
assume you took the lease on the ref when you fetched to decide what
the rebased history should be, and you can push back only if the
lease has not been broken.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-09 06:34:36 +08:00
|
|
|
static struct push_cas_option cas;
|
|
|
|
|
2018-05-17 06:58:16 +08:00
|
|
|
static struct refspec rs = REFSPEC_INIT_PUSH;
|
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 12:22:49 +08:00
|
|
|
|
2017-10-23 19:44:49 +08:00
|
|
|
static struct string_list push_options_config = STRING_LIST_INIT_DUP;
|
|
|
|
|
push: use remote.$name.push as a refmap
Since f2690487 (fetch: opportunistically update tracking refs,
2013-05-11), we stopped taking a non-storing refspec given on the
command line of "git fetch" literally, and instead started mapping
it via remote.$name.fetch refspecs. This allows
$ git fetch origin master
from the 'origin' repository, which is configured with
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
to update refs/remotes/origin/master with the result, as if the
command line were
$ git fetch origin +master:refs/remotes/origin/master
to reduce surprises and improve usability. Before that change, a
refspec on the command line without a colon was only to fetch the
history and leave the result in FETCH_HEAD, without updating the
remote-tracking branches.
When you are simulating a fetch from you by your mothership with a
push by you into your mothership, instead of having:
[remote "satellite"]
fetch = +refs/heads/*:refs/remotes/satellite/*
on the mothership repository and running:
mothership$ git fetch satellite
you would have:
[remote "mothership"]
push = +refs/heads/*:refs/remotes/satellite/*
on your satellite machine, and run:
satellite$ git push mothership
Because we so far did not make the corresponding change to the push
side, this command:
satellite$ git push mothership master
does _not_ allow you on the satellite to only push 'master' out but
still to the usual destination (i.e. refs/remotes/satellite/master).
Implement the logic to map an unqualified refspec given on the
command line via the remote.$name.push refspec. This will bring a
bit more symmetry between "fetch" and "push".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-12-04 07:41:15 +08:00
|
|
|
static const char *map_refspec(const char *ref,
|
|
|
|
struct remote *remote, struct ref *local_refs)
|
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 12:22:49 +08:00
|
|
|
{
|
push: use remote.$name.push as a refmap
Since f2690487 (fetch: opportunistically update tracking refs,
2013-05-11), we stopped taking a non-storing refspec given on the
command line of "git fetch" literally, and instead started mapping
it via remote.$name.fetch refspecs. This allows
$ git fetch origin master
from the 'origin' repository, which is configured with
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
to update refs/remotes/origin/master with the result, as if the
command line were
$ git fetch origin +master:refs/remotes/origin/master
to reduce surprises and improve usability. Before that change, a
refspec on the command line without a colon was only to fetch the
history and leave the result in FETCH_HEAD, without updating the
remote-tracking branches.
When you are simulating a fetch from you by your mothership with a
push by you into your mothership, instead of having:
[remote "satellite"]
fetch = +refs/heads/*:refs/remotes/satellite/*
on the mothership repository and running:
mothership$ git fetch satellite
you would have:
[remote "mothership"]
push = +refs/heads/*:refs/remotes/satellite/*
on your satellite machine, and run:
satellite$ git push mothership
Because we so far did not make the corresponding change to the push
side, this command:
satellite$ git push mothership master
does _not_ allow you on the satellite to only push 'master' out but
still to the usual destination (i.e. refs/remotes/satellite/master).
Implement the logic to map an unqualified refspec given on the
command line via the remote.$name.push refspec. This will bring a
bit more symmetry between "fetch" and "push".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-12-04 07:41:15 +08:00
|
|
|
struct ref *matched = NULL;
|
|
|
|
|
|
|
|
/* Does "ref" uniquely name our ref? */
|
|
|
|
if (count_refspec_match(ref, local_refs, &matched) != 1)
|
|
|
|
return ref;
|
|
|
|
|
2018-05-17 06:58:00 +08:00
|
|
|
if (remote->push.nr) {
|
2018-05-17 06:57:49 +08:00
|
|
|
struct refspec_item query;
|
|
|
|
memset(&query, 0, sizeof(struct refspec_item));
|
push: use remote.$name.push as a refmap
Since f2690487 (fetch: opportunistically update tracking refs,
2013-05-11), we stopped taking a non-storing refspec given on the
command line of "git fetch" literally, and instead started mapping
it via remote.$name.fetch refspecs. This allows
$ git fetch origin master
from the 'origin' repository, which is configured with
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
to update refs/remotes/origin/master with the result, as if the
command line were
$ git fetch origin +master:refs/remotes/origin/master
to reduce surprises and improve usability. Before that change, a
refspec on the command line without a colon was only to fetch the
history and leave the result in FETCH_HEAD, without updating the
remote-tracking branches.
When you are simulating a fetch from you by your mothership with a
push by you into your mothership, instead of having:
[remote "satellite"]
fetch = +refs/heads/*:refs/remotes/satellite/*
on the mothership repository and running:
mothership$ git fetch satellite
you would have:
[remote "mothership"]
push = +refs/heads/*:refs/remotes/satellite/*
on your satellite machine, and run:
satellite$ git push mothership
Because we so far did not make the corresponding change to the push
side, this command:
satellite$ git push mothership master
does _not_ allow you on the satellite to only push 'master' out but
still to the usual destination (i.e. refs/remotes/satellite/master).
Implement the logic to map an unqualified refspec given on the
command line via the remote.$name.push refspec. This will bring a
bit more symmetry between "fetch" and "push".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-12-04 07:41:15 +08:00
|
|
|
query.src = matched->name;
|
2018-05-17 06:58:12 +08:00
|
|
|
if (!query_refspecs(&remote->push, &query) && query.dst) {
|
push: use remote.$name.push as a refmap
Since f2690487 (fetch: opportunistically update tracking refs,
2013-05-11), we stopped taking a non-storing refspec given on the
command line of "git fetch" literally, and instead started mapping
it via remote.$name.fetch refspecs. This allows
$ git fetch origin master
from the 'origin' repository, which is configured with
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
to update refs/remotes/origin/master with the result, as if the
command line were
$ git fetch origin +master:refs/remotes/origin/master
to reduce surprises and improve usability. Before that change, a
refspec on the command line without a colon was only to fetch the
history and leave the result in FETCH_HEAD, without updating the
remote-tracking branches.
When you are simulating a fetch from you by your mothership with a
push by you into your mothership, instead of having:
[remote "satellite"]
fetch = +refs/heads/*:refs/remotes/satellite/*
on the mothership repository and running:
mothership$ git fetch satellite
you would have:
[remote "mothership"]
push = +refs/heads/*:refs/remotes/satellite/*
on your satellite machine, and run:
satellite$ git push mothership
Because we so far did not make the corresponding change to the push
side, this command:
satellite$ git push mothership master
does _not_ allow you on the satellite to only push 'master' out but
still to the usual destination (i.e. refs/remotes/satellite/master).
Implement the logic to map an unqualified refspec given on the
command line via the remote.$name.push refspec. This will bring a
bit more symmetry between "fetch" and "push".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-12-04 07:41:15 +08:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
|
|
|
strbuf_addf(&buf, "%s%s:%s",
|
|
|
|
query.force ? "+" : "",
|
|
|
|
query.src, query.dst);
|
|
|
|
return strbuf_detach(&buf, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-04 08:23:35 +08:00
|
|
|
if (push_default == PUSH_DEFAULT_UPSTREAM &&
|
2014-03-08 07:18:17 +08:00
|
|
|
starts_with(matched->name, "refs/heads/")) {
|
2013-12-04 08:23:35 +08:00
|
|
|
struct branch *branch = branch_get(matched->name + 11);
|
|
|
|
if (branch->merge_nr == 1 && branch->merge[0]->src) {
|
|
|
|
struct strbuf buf = STRBUF_INIT;
|
|
|
|
strbuf_addf(&buf, "%s:%s",
|
|
|
|
ref, branch->merge[0]->src);
|
|
|
|
return strbuf_detach(&buf, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
push: use remote.$name.push as a refmap
Since f2690487 (fetch: opportunistically update tracking refs,
2013-05-11), we stopped taking a non-storing refspec given on the
command line of "git fetch" literally, and instead started mapping
it via remote.$name.fetch refspecs. This allows
$ git fetch origin master
from the 'origin' repository, which is configured with
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
to update refs/remotes/origin/master with the result, as if the
command line were
$ git fetch origin +master:refs/remotes/origin/master
to reduce surprises and improve usability. Before that change, a
refspec on the command line without a colon was only to fetch the
history and leave the result in FETCH_HEAD, without updating the
remote-tracking branches.
When you are simulating a fetch from you by your mothership with a
push by you into your mothership, instead of having:
[remote "satellite"]
fetch = +refs/heads/*:refs/remotes/satellite/*
on the mothership repository and running:
mothership$ git fetch satellite
you would have:
[remote "mothership"]
push = +refs/heads/*:refs/remotes/satellite/*
on your satellite machine, and run:
satellite$ git push mothership
Because we so far did not make the corresponding change to the push
side, this command:
satellite$ git push mothership master
does _not_ allow you on the satellite to only push 'master' out but
still to the usual destination (i.e. refs/remotes/satellite/master).
Implement the logic to map an unqualified refspec given on the
command line via the remote.$name.push refspec. This will bring a
bit more symmetry between "fetch" and "push".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-12-04 07:41:15 +08:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_refspecs(const char **refs, int nr, const char *repo)
|
|
|
|
{
|
|
|
|
struct remote *remote = NULL;
|
|
|
|
struct ref *local_refs = NULL;
|
2007-05-25 13:20:56 +08:00
|
|
|
int i;
|
push: use remote.$name.push as a refmap
Since f2690487 (fetch: opportunistically update tracking refs,
2013-05-11), we stopped taking a non-storing refspec given on the
command line of "git fetch" literally, and instead started mapping
it via remote.$name.fetch refspecs. This allows
$ git fetch origin master
from the 'origin' repository, which is configured with
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
to update refs/remotes/origin/master with the result, as if the
command line were
$ git fetch origin +master:refs/remotes/origin/master
to reduce surprises and improve usability. Before that change, a
refspec on the command line without a colon was only to fetch the
history and leave the result in FETCH_HEAD, without updating the
remote-tracking branches.
When you are simulating a fetch from you by your mothership with a
push by you into your mothership, instead of having:
[remote "satellite"]
fetch = +refs/heads/*:refs/remotes/satellite/*
on the mothership repository and running:
mothership$ git fetch satellite
you would have:
[remote "mothership"]
push = +refs/heads/*:refs/remotes/satellite/*
on your satellite machine, and run:
satellite$ git push mothership
Because we so far did not make the corresponding change to the push
side, this command:
satellite$ git push mothership master
does _not_ allow you on the satellite to only push 'master' out but
still to the usual destination (i.e. refs/remotes/satellite/master).
Implement the logic to map an unqualified refspec given on the
command line via the remote.$name.push refspec. This will bring a
bit more symmetry between "fetch" and "push".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-12-04 07:41:15 +08:00
|
|
|
|
2007-05-25 13:20:56 +08:00
|
|
|
for (i = 0; i < nr; i++) {
|
|
|
|
const char *ref = refs[i];
|
|
|
|
if (!strcmp("tag", ref)) {
|
2013-12-04 06:33:10 +08:00
|
|
|
struct strbuf tagref = STRBUF_INIT;
|
2007-05-25 13:20:56 +08:00
|
|
|
if (nr <= ++i)
|
2011-02-23 07:42:11 +08:00
|
|
|
die(_("tag shorthand without <tag>"));
|
2013-12-04 06:33:10 +08:00
|
|
|
ref = refs[i];
|
|
|
|
if (deleterefs)
|
|
|
|
strbuf_addf(&tagref, ":refs/tags/%s", ref);
|
|
|
|
else
|
|
|
|
strbuf_addf(&tagref, "refs/tags/%s", ref);
|
|
|
|
ref = strbuf_detach(&tagref, NULL);
|
|
|
|
} else if (deleterefs) {
|
|
|
|
struct strbuf delref = STRBUF_INIT;
|
|
|
|
if (strchr(ref, ':'))
|
|
|
|
die(_("--delete only accepts plain target ref names"));
|
|
|
|
strbuf_addf(&delref, ":%s", ref);
|
|
|
|
ref = strbuf_detach(&delref, NULL);
|
push: use remote.$name.push as a refmap
Since f2690487 (fetch: opportunistically update tracking refs,
2013-05-11), we stopped taking a non-storing refspec given on the
command line of "git fetch" literally, and instead started mapping
it via remote.$name.fetch refspecs. This allows
$ git fetch origin master
from the 'origin' repository, which is configured with
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
to update refs/remotes/origin/master with the result, as if the
command line were
$ git fetch origin +master:refs/remotes/origin/master
to reduce surprises and improve usability. Before that change, a
refspec on the command line without a colon was only to fetch the
history and leave the result in FETCH_HEAD, without updating the
remote-tracking branches.
When you are simulating a fetch from you by your mothership with a
push by you into your mothership, instead of having:
[remote "satellite"]
fetch = +refs/heads/*:refs/remotes/satellite/*
on the mothership repository and running:
mothership$ git fetch satellite
you would have:
[remote "mothership"]
push = +refs/heads/*:refs/remotes/satellite/*
on your satellite machine, and run:
satellite$ git push mothership
Because we so far did not make the corresponding change to the push
side, this command:
satellite$ git push mothership master
does _not_ allow you on the satellite to only push 'master' out but
still to the usual destination (i.e. refs/remotes/satellite/master).
Implement the logic to map an unqualified refspec given on the
command line via the remote.$name.push refspec. This will bring a
bit more symmetry between "fetch" and "push".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-12-04 07:41:15 +08:00
|
|
|
} else if (!strchr(ref, ':')) {
|
|
|
|
if (!remote) {
|
|
|
|
/* lazily grab remote and local_refs */
|
|
|
|
remote = remote_get(repo);
|
|
|
|
local_refs = get_local_heads();
|
2009-12-31 03:57:42 +08:00
|
|
|
}
|
push: use remote.$name.push as a refmap
Since f2690487 (fetch: opportunistically update tracking refs,
2013-05-11), we stopped taking a non-storing refspec given on the
command line of "git fetch" literally, and instead started mapping
it via remote.$name.fetch refspecs. This allows
$ git fetch origin master
from the 'origin' repository, which is configured with
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
to update refs/remotes/origin/master with the result, as if the
command line were
$ git fetch origin +master:refs/remotes/origin/master
to reduce surprises and improve usability. Before that change, a
refspec on the command line without a colon was only to fetch the
history and leave the result in FETCH_HEAD, without updating the
remote-tracking branches.
When you are simulating a fetch from you by your mothership with a
push by you into your mothership, instead of having:
[remote "satellite"]
fetch = +refs/heads/*:refs/remotes/satellite/*
on the mothership repository and running:
mothership$ git fetch satellite
you would have:
[remote "mothership"]
push = +refs/heads/*:refs/remotes/satellite/*
on your satellite machine, and run:
satellite$ git push mothership
Because we so far did not make the corresponding change to the push
side, this command:
satellite$ git push mothership master
does _not_ allow you on the satellite to only push 'master' out but
still to the usual destination (i.e. refs/remotes/satellite/master).
Implement the logic to map an unqualified refspec given on the
command line via the remote.$name.push refspec. This will bring a
bit more symmetry between "fetch" and "push".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-12-04 07:41:15 +08:00
|
|
|
ref = map_refspec(ref, remote, local_refs);
|
2013-12-04 06:33:10 +08:00
|
|
|
}
|
2018-05-17 06:58:16 +08:00
|
|
|
refspec_append(&rs, 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 12:22:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
push: error out when the "upstream" semantics does not make sense
The user can say "git push" without specifying any refspec. When using
the "upstream" semantics via the push.default configuration, the user
wants to update the "upstream" branch of the current branch, which is the
branch at a remote repository the current branch is set to integrate with,
with this command.
However, there are cases that such a "git push" that uses the "upstream"
semantics does not make sense:
- The current branch does not have branch.$name.remote configured. By
definition, "git push" that does not name where to push to will not
know where to push to. The user may explicitly say "git push $there",
but again, by definition, no branch at repository $there is set to
integrate with the current branch in this case and we wouldn't know
which remote branch to update.
- The current branch does have branch.$name.remote configured, but it
does not specify branch.$name.merge that names what branch at the
remote this branch integrates with. "git push" knows where to push in
this case (or the user may explicitly say "git push $remote" to tell us
where to push), but we do not know which remote branch to update.
- The current branch does have its remote and upstream branch configured,
but the user said "git push $there", where $there is not the remote
named by "branch.$name.remote". By definition, no branch at repository
$there is set to integrate with the current branch in this case, and
this push is not meant to update any branch at the remote repository
$there.
The first two cases were already checked correctly, but the third case was
not checked and we ended up updating the branch named branch.$name.merge
at repository $there, which was totally bogus.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-31 07:07:12 +08:00
|
|
|
static int push_url_of_remote(struct remote *remote, const char ***url_p)
|
|
|
|
{
|
|
|
|
if (remote->pushurl_nr) {
|
|
|
|
*url_p = remote->pushurl;
|
|
|
|
return remote->pushurl_nr;
|
|
|
|
}
|
|
|
|
*url_p = remote->url;
|
|
|
|
return remote->url_nr;
|
|
|
|
}
|
|
|
|
|
2018-12-09 18:25:21 +08:00
|
|
|
static NORETURN int die_push_simple(struct branch *branch,
|
|
|
|
struct remote *remote)
|
|
|
|
{
|
2012-04-24 15:50:03 +08:00
|
|
|
/*
|
|
|
|
* There's no point in using shorten_unambiguous_ref here,
|
|
|
|
* as the ambiguity would be on the remote side, not what
|
|
|
|
* we have locally. Plus, this is supposed to be the simple
|
|
|
|
* mode. If the user is doing something crazy like setting
|
|
|
|
* upstream to a non-branch, we should probably be showing
|
|
|
|
* them the big ugly fully qualified ref.
|
|
|
|
*/
|
|
|
|
const char *advice_maybe = "";
|
refactor skip_prefix to return a boolean
The skip_prefix() function returns a pointer to the content
past the prefix, or NULL if the prefix was not found. While
this is nice and simple, in practice it makes it hard to use
for two reasons:
1. When you want to conditionally skip or keep the string
as-is, you have to introduce a temporary variable.
For example:
tmp = skip_prefix(buf, "foo");
if (tmp)
buf = tmp;
2. It is verbose to check the outcome in a conditional, as
you need extra parentheses to silence compiler
warnings. For example:
if ((cp = skip_prefix(buf, "foo"))
/* do something with cp */
Both of these make it harder to use for long if-chains, and
we tend to use starts_with() instead. However, the first line
of "do something" is often to then skip forward in buf past
the prefix, either using a magic constant or with an extra
strlen(3) (which is generally computed at compile time, but
means we are repeating ourselves).
This patch refactors skip_prefix() to return a simple boolean,
and to provide the pointer value as an out-parameter. If the
prefix is not found, the out-parameter is untouched. This
lets you write:
if (skip_prefix(arg, "foo ", &arg))
do_foo(arg);
else if (skip_prefix(arg, "bar ", &arg))
do_bar(arg);
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-06-19 03:44:19 +08:00
|
|
|
const char *short_upstream = branch->merge[0]->src;
|
|
|
|
|
|
|
|
skip_prefix(short_upstream, "refs/heads/", &short_upstream);
|
2012-04-24 15:50:03 +08:00
|
|
|
|
|
|
|
/*
|
2013-07-29 16:18:21 +08:00
|
|
|
* Don't show advice for people who explicitly set
|
2012-04-24 15:50:03 +08:00
|
|
|
* push.default.
|
|
|
|
*/
|
|
|
|
if (push_default == PUSH_DEFAULT_UNSPECIFIED)
|
|
|
|
advice_maybe = _("\n"
|
|
|
|
"To choose either option permanently, "
|
|
|
|
"see push.default in 'git help config'.");
|
|
|
|
die(_("The upstream branch of your current branch does not match\n"
|
|
|
|
"the name of your current branch. To push to the upstream branch\n"
|
|
|
|
"on the remote, use\n"
|
|
|
|
"\n"
|
|
|
|
" git push %s HEAD:%s\n"
|
|
|
|
"\n"
|
|
|
|
"To push to the branch of the same name on the remote, use\n"
|
|
|
|
"\n"
|
2018-11-14 04:39:09 +08:00
|
|
|
" git push %s HEAD\n"
|
2012-04-24 15:50:03 +08:00
|
|
|
"%s"),
|
|
|
|
remote->name, short_upstream,
|
2018-11-14 04:39:09 +08:00
|
|
|
remote->name, advice_maybe);
|
2012-04-24 15:50:03 +08:00
|
|
|
}
|
|
|
|
|
2013-05-30 03:21:49 +08:00
|
|
|
static const char message_detached_head_die[] =
|
|
|
|
N_("You are not currently on a branch.\n"
|
|
|
|
"To push the history leading to the current (detached HEAD)\n"
|
|
|
|
"state now, use\n"
|
|
|
|
"\n"
|
|
|
|
" git push %s HEAD:<name-of-remote-branch>\n");
|
|
|
|
|
2013-06-19 19:11:41 +08:00
|
|
|
static void setup_push_upstream(struct remote *remote, struct branch *branch,
|
2014-11-27 11:43:06 +08:00
|
|
|
int triangular, int simple)
|
2009-03-16 23:42:51 +08:00
|
|
|
{
|
|
|
|
struct strbuf refspec = STRBUF_INIT;
|
2013-06-19 19:11:41 +08:00
|
|
|
|
2009-03-16 23:42:51 +08:00
|
|
|
if (!branch)
|
2013-05-30 03:21:49 +08:00
|
|
|
die(_(message_detached_head_die), remote->name);
|
push: error out when the "upstream" semantics does not make sense
The user can say "git push" without specifying any refspec. When using
the "upstream" semantics via the push.default configuration, the user
wants to update the "upstream" branch of the current branch, which is the
branch at a remote repository the current branch is set to integrate with,
with this command.
However, there are cases that such a "git push" that uses the "upstream"
semantics does not make sense:
- The current branch does not have branch.$name.remote configured. By
definition, "git push" that does not name where to push to will not
know where to push to. The user may explicitly say "git push $there",
but again, by definition, no branch at repository $there is set to
integrate with the current branch in this case and we wouldn't know
which remote branch to update.
- The current branch does have branch.$name.remote configured, but it
does not specify branch.$name.merge that names what branch at the
remote this branch integrates with. "git push" knows where to push in
this case (or the user may explicitly say "git push $remote" to tell us
where to push), but we do not know which remote branch to update.
- The current branch does have its remote and upstream branch configured,
but the user said "git push $there", where $there is not the remote
named by "branch.$name.remote". By definition, no branch at repository
$there is set to integrate with the current branch in this case, and
this push is not meant to update any branch at the remote repository
$there.
The first two cases were already checked correctly, but the third case was
not checked and we ended up updating the branch named branch.$name.merge
at repository $there, which was totally bogus.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-31 07:07:12 +08:00
|
|
|
if (!branch->merge_nr || !branch->merge || !branch->remote_name)
|
2011-04-02 08:55:55 +08:00
|
|
|
die(_("The current branch %s has no upstream branch.\n"
|
2011-03-03 04:12:10 +08:00
|
|
|
"To push the current branch and set the remote as upstream, use\n"
|
|
|
|
"\n"
|
2011-04-02 08:55:55 +08:00
|
|
|
" git push --set-upstream %s %s\n"),
|
2011-03-03 04:12:10 +08:00
|
|
|
branch->name,
|
|
|
|
remote->name,
|
2009-03-16 23:42:51 +08:00
|
|
|
branch->name);
|
|
|
|
if (branch->merge_nr != 1)
|
2011-04-02 08:55:55 +08:00
|
|
|
die(_("The current branch %s has multiple upstream branches, "
|
2011-02-23 07:42:11 +08:00
|
|
|
"refusing to push."), branch->name);
|
2013-06-19 19:11:41 +08:00
|
|
|
if (triangular)
|
push: error out when the "upstream" semantics does not make sense
The user can say "git push" without specifying any refspec. When using
the "upstream" semantics via the push.default configuration, the user
wants to update the "upstream" branch of the current branch, which is the
branch at a remote repository the current branch is set to integrate with,
with this command.
However, there are cases that such a "git push" that uses the "upstream"
semantics does not make sense:
- The current branch does not have branch.$name.remote configured. By
definition, "git push" that does not name where to push to will not
know where to push to. The user may explicitly say "git push $there",
but again, by definition, no branch at repository $there is set to
integrate with the current branch in this case and we wouldn't know
which remote branch to update.
- The current branch does have branch.$name.remote configured, but it
does not specify branch.$name.merge that names what branch at the
remote this branch integrates with. "git push" knows where to push in
this case (or the user may explicitly say "git push $remote" to tell us
where to push), but we do not know which remote branch to update.
- The current branch does have its remote and upstream branch configured,
but the user said "git push $there", where $there is not the remote
named by "branch.$name.remote". By definition, no branch at repository
$there is set to integrate with the current branch in this case, and
this push is not meant to update any branch at the remote repository
$there.
The first two cases were already checked correctly, but the third case was
not checked and we ended up updating the branch named branch.$name.merge
at repository $there, which was totally bogus.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-31 07:07:12 +08:00
|
|
|
die(_("You are pushing to remote '%s', which is not the upstream of\n"
|
|
|
|
"your current branch '%s', without telling me what to push\n"
|
|
|
|
"to update which remote branch."),
|
|
|
|
remote->name, branch->name);
|
2013-06-19 19:11:41 +08:00
|
|
|
|
2014-11-27 11:43:06 +08:00
|
|
|
if (simple) {
|
2013-06-19 19:11:41 +08:00
|
|
|
/* Additional safety */
|
|
|
|
if (strcmp(branch->refname, branch->merge[0]->src))
|
|
|
|
die_push_simple(branch, remote);
|
|
|
|
}
|
push: error out when the "upstream" semantics does not make sense
The user can say "git push" without specifying any refspec. When using
the "upstream" semantics via the push.default configuration, the user
wants to update the "upstream" branch of the current branch, which is the
branch at a remote repository the current branch is set to integrate with,
with this command.
However, there are cases that such a "git push" that uses the "upstream"
semantics does not make sense:
- The current branch does not have branch.$name.remote configured. By
definition, "git push" that does not name where to push to will not
know where to push to. The user may explicitly say "git push $there",
but again, by definition, no branch at repository $there is set to
integrate with the current branch in this case and we wouldn't know
which remote branch to update.
- The current branch does have branch.$name.remote configured, but it
does not specify branch.$name.merge that names what branch at the
remote this branch integrates with. "git push" knows where to push in
this case (or the user may explicitly say "git push $remote" to tell us
where to push), but we do not know which remote branch to update.
- The current branch does have its remote and upstream branch configured,
but the user said "git push $there", where $there is not the remote
named by "branch.$name.remote". By definition, no branch at repository
$there is set to integrate with the current branch in this case, and
this push is not meant to update any branch at the remote repository
$there.
The first two cases were already checked correctly, but the third case was
not checked and we ended up updating the branch named branch.$name.merge
at repository $there, which was totally bogus.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-31 07:07:12 +08:00
|
|
|
|
2016-10-29 03:25:30 +08:00
|
|
|
strbuf_addf(&refspec, "%s:%s", branch->refname, branch->merge[0]->src);
|
2018-05-17 06:58:16 +08:00
|
|
|
refspec_append(&rs, refspec.buf);
|
2009-03-16 23:42:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-19 19:11:41 +08:00
|
|
|
static void setup_push_current(struct remote *remote, struct branch *branch)
|
|
|
|
{
|
2016-10-29 03:25:30 +08:00
|
|
|
struct strbuf refspec = STRBUF_INIT;
|
|
|
|
|
2013-06-19 19:11:41 +08:00
|
|
|
if (!branch)
|
|
|
|
die(_(message_detached_head_die), remote->name);
|
2016-10-29 03:25:30 +08:00
|
|
|
strbuf_addf(&refspec, "%s:%s", branch->refname, branch->refname);
|
2018-05-17 06:58:16 +08:00
|
|
|
refspec_append(&rs, refspec.buf);
|
2013-06-19 19:11:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int is_workflow_triangular(struct remote *remote)
|
|
|
|
{
|
|
|
|
struct remote *fetch_remote = remote_get(NULL);
|
|
|
|
return (fetch_remote && fetch_remote != remote);
|
|
|
|
}
|
|
|
|
|
2011-03-03 04:12:10 +08:00
|
|
|
static void setup_default_push_refspecs(struct remote *remote)
|
2009-03-16 23:42:51 +08:00
|
|
|
{
|
2013-06-19 19:11:41 +08:00
|
|
|
struct branch *branch = branch_get(NULL);
|
|
|
|
int triangular = is_workflow_triangular(remote);
|
2013-05-30 03:21:50 +08:00
|
|
|
|
2009-03-16 23:42:51 +08:00
|
|
|
switch (push_default) {
|
2009-07-19 08:19:47 +08:00
|
|
|
default:
|
2009-03-16 23:42:51 +08:00
|
|
|
case PUSH_DEFAULT_MATCHING:
|
2018-05-17 06:58:16 +08:00
|
|
|
refspec_append(&rs, ":");
|
2009-03-16 23:42:51 +08:00
|
|
|
break;
|
|
|
|
|
2013-01-05 08:02:29 +08:00
|
|
|
case PUSH_DEFAULT_UNSPECIFIED:
|
2012-04-24 15:50:03 +08:00
|
|
|
case PUSH_DEFAULT_SIMPLE:
|
2013-06-19 19:11:41 +08:00
|
|
|
if (triangular)
|
|
|
|
setup_push_current(remote, branch);
|
|
|
|
else
|
2014-11-27 11:43:06 +08:00
|
|
|
setup_push_upstream(remote, branch, triangular, 1);
|
2012-04-24 15:50:03 +08:00
|
|
|
break;
|
|
|
|
|
2011-02-16 08:54:24 +08:00
|
|
|
case PUSH_DEFAULT_UPSTREAM:
|
2014-11-27 11:43:06 +08:00
|
|
|
setup_push_upstream(remote, branch, triangular, 0);
|
2009-03-16 23:42:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PUSH_DEFAULT_CURRENT:
|
2013-06-19 19:11:41 +08:00
|
|
|
setup_push_current(remote, branch);
|
2009-03-16 23:42:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PUSH_DEFAULT_NOTHING:
|
2011-02-23 07:42:11 +08:00
|
|
|
die(_("You didn't specify any refspecs to push, and "
|
|
|
|
"push.default is \"nothing\"."));
|
2009-03-16 23:42:51 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
push: Provide situational hints for non-fast-forward errors
Pushing a non-fast-forward update to a remote repository will result in
an error, but the hint text doesn't provide the correct resolution in
every case. Give better resolution advice in three push scenarios:
1) If you push your current branch and it triggers a non-fast-forward
error, you should merge remote changes with 'git pull' before pushing
again.
2) If you push to a shared repository others push to, and your local
tracking branches are not kept up to date, the 'matching refs' default
will generate non-fast-forward errors on outdated branches. If this is
your workflow, the 'matching refs' default is not for you. Consider
setting the 'push.default' configuration variable to 'current' or
'upstream' to ensure only your current branch is pushed.
3) If you explicitly specify a ref that is not your current branch or
push matching branches with ':', you will generate a non-fast-forward
error if any pushed branch tip is out of date. You should checkout the
offending branch and merge remote changes before pushing again.
Teach transport.c to recognize these scenarios and configure push.c
to hint for them. If 'git push's default behavior changes or we
discover more scenarios, extension is easy. Standardize on the
advice API and add three new advice variables, 'pushNonFFCurrent',
'pushNonFFDefault', and 'pushNonFFMatching'. Setting any of these
to 'false' will disable their affiliated advice. Setting
'pushNonFastForward' to false will disable all three, thus preserving the
config option for users who already set it, but guaranteeing new
users won't disable push advice accidentally.
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Christopher Tiwald <christiwald@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-20 12:31:33 +08:00
|
|
|
static const char message_advice_pull_before_push[] =
|
|
|
|
N_("Updates were rejected because the tip of your current branch is behind\n"
|
2013-07-08 03:02:14 +08:00
|
|
|
"its remote counterpart. Integrate the remote changes (e.g.\n"
|
|
|
|
"'git pull ...') before pushing again.\n"
|
push: Provide situational hints for non-fast-forward errors
Pushing a non-fast-forward update to a remote repository will result in
an error, but the hint text doesn't provide the correct resolution in
every case. Give better resolution advice in three push scenarios:
1) If you push your current branch and it triggers a non-fast-forward
error, you should merge remote changes with 'git pull' before pushing
again.
2) If you push to a shared repository others push to, and your local
tracking branches are not kept up to date, the 'matching refs' default
will generate non-fast-forward errors on outdated branches. If this is
your workflow, the 'matching refs' default is not for you. Consider
setting the 'push.default' configuration variable to 'current' or
'upstream' to ensure only your current branch is pushed.
3) If you explicitly specify a ref that is not your current branch or
push matching branches with ':', you will generate a non-fast-forward
error if any pushed branch tip is out of date. You should checkout the
offending branch and merge remote changes before pushing again.
Teach transport.c to recognize these scenarios and configure push.c
to hint for them. If 'git push's default behavior changes or we
discover more scenarios, extension is easy. Standardize on the
advice API and add three new advice variables, 'pushNonFFCurrent',
'pushNonFFDefault', and 'pushNonFFMatching'. Setting any of these
to 'false' will disable their affiliated advice. Setting
'pushNonFastForward' to false will disable all three, thus preserving the
config option for users who already set it, but guaranteeing new
users won't disable push advice accidentally.
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Christopher Tiwald <christiwald@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-20 12:31:33 +08:00
|
|
|
"See the 'Note about fast-forwards' in 'git push --help' for details.");
|
|
|
|
|
|
|
|
static const char message_advice_checkout_pull_push[] =
|
|
|
|
N_("Updates were rejected because a pushed branch tip is behind its remote\n"
|
2013-07-08 03:02:14 +08:00
|
|
|
"counterpart. Check out this branch and integrate the remote changes\n"
|
|
|
|
"(e.g. 'git pull ...') before pushing again.\n"
|
push: Provide situational hints for non-fast-forward errors
Pushing a non-fast-forward update to a remote repository will result in
an error, but the hint text doesn't provide the correct resolution in
every case. Give better resolution advice in three push scenarios:
1) If you push your current branch and it triggers a non-fast-forward
error, you should merge remote changes with 'git pull' before pushing
again.
2) If you push to a shared repository others push to, and your local
tracking branches are not kept up to date, the 'matching refs' default
will generate non-fast-forward errors on outdated branches. If this is
your workflow, the 'matching refs' default is not for you. Consider
setting the 'push.default' configuration variable to 'current' or
'upstream' to ensure only your current branch is pushed.
3) If you explicitly specify a ref that is not your current branch or
push matching branches with ':', you will generate a non-fast-forward
error if any pushed branch tip is out of date. You should checkout the
offending branch and merge remote changes before pushing again.
Teach transport.c to recognize these scenarios and configure push.c
to hint for them. If 'git push's default behavior changes or we
discover more scenarios, extension is easy. Standardize on the
advice API and add three new advice variables, 'pushNonFFCurrent',
'pushNonFFDefault', and 'pushNonFFMatching'. Setting any of these
to 'false' will disable their affiliated advice. Setting
'pushNonFastForward' to false will disable all three, thus preserving the
config option for users who already set it, but guaranteeing new
users won't disable push advice accidentally.
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Christopher Tiwald <christiwald@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-20 12:31:33 +08:00
|
|
|
"See the 'Note about fast-forwards' in 'git push --help' for details.");
|
|
|
|
|
push: introduce REJECT_FETCH_FIRST and REJECT_NEEDS_FORCE
When we push to update an existing ref, if:
* the object at the tip of the remote is not a commit; or
* the object we are pushing is not a commit,
it won't be correct to suggest to fetch, integrate and push again,
as the old and new objects will not "merge". We should explain that
the push must be forced when there is a non-committish object is
involved in such a case.
If we do not have the current object at the tip of the remote, we do
not even know that object, when fetched, is something that can be
merged. In such a case, suggesting to pull first just like
non-fast-forward case may not be technically correct, but in
practice, most such failures are seen when you try to push your work
to a branch without knowing that somebody else already pushed to
update the same branch since you forked, so "pull first" would work
as a suggestion most of the time. And if the object at the tip is
not a commit, "pull first" will fail, without making any permanent
damage. As a side effect, it also makes the error message the user
will get during the next "push" attempt easier to understand, now
the user is aware that a non-commit object is involved.
In these cases, the current code already rejects such a push on the
client end, but we used the same error and advice messages as the
ones used when rejecting a non-fast-forward push, i.e. pull from
there and integrate before pushing again.
Introduce new rejection reasons and reword the messages
appropriately.
[jc: with help by Peff on message details]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-24 05:55:30 +08:00
|
|
|
static const char message_advice_ref_fetch_first[] =
|
|
|
|
N_("Updates were rejected because the remote contains work that you do\n"
|
|
|
|
"not have locally. This is usually caused by another repository pushing\n"
|
2013-07-08 03:02:14 +08:00
|
|
|
"to the same ref. You may want to first integrate the remote changes\n"
|
|
|
|
"(e.g., 'git pull ...') before pushing again.\n"
|
push: introduce REJECT_FETCH_FIRST and REJECT_NEEDS_FORCE
When we push to update an existing ref, if:
* the object at the tip of the remote is not a commit; or
* the object we are pushing is not a commit,
it won't be correct to suggest to fetch, integrate and push again,
as the old and new objects will not "merge". We should explain that
the push must be forced when there is a non-committish object is
involved in such a case.
If we do not have the current object at the tip of the remote, we do
not even know that object, when fetched, is something that can be
merged. In such a case, suggesting to pull first just like
non-fast-forward case may not be technically correct, but in
practice, most such failures are seen when you try to push your work
to a branch without knowing that somebody else already pushed to
update the same branch since you forked, so "pull first" would work
as a suggestion most of the time. And if the object at the tip is
not a commit, "pull first" will fail, without making any permanent
damage. As a side effect, it also makes the error message the user
will get during the next "push" attempt easier to understand, now
the user is aware that a non-commit object is involved.
In these cases, the current code already rejects such a push on the
client end, but we used the same error and advice messages as the
ones used when rejecting a non-fast-forward push, i.e. pull from
there and integrate before pushing again.
Introduce new rejection reasons and reword the messages
appropriately.
[jc: with help by Peff on message details]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-24 05:55:30 +08:00
|
|
|
"See the 'Note about fast-forwards' in 'git push --help' for details.");
|
|
|
|
|
2012-11-30 09:41:34 +08:00
|
|
|
static const char message_advice_ref_already_exists[] =
|
2013-01-25 13:09:00 +08:00
|
|
|
N_("Updates were rejected because the tag already exists in the remote.");
|
2012-11-30 09:41:34 +08:00
|
|
|
|
push: introduce REJECT_FETCH_FIRST and REJECT_NEEDS_FORCE
When we push to update an existing ref, if:
* the object at the tip of the remote is not a commit; or
* the object we are pushing is not a commit,
it won't be correct to suggest to fetch, integrate and push again,
as the old and new objects will not "merge". We should explain that
the push must be forced when there is a non-committish object is
involved in such a case.
If we do not have the current object at the tip of the remote, we do
not even know that object, when fetched, is something that can be
merged. In such a case, suggesting to pull first just like
non-fast-forward case may not be technically correct, but in
practice, most such failures are seen when you try to push your work
to a branch without knowing that somebody else already pushed to
update the same branch since you forked, so "pull first" would work
as a suggestion most of the time. And if the object at the tip is
not a commit, "pull first" will fail, without making any permanent
damage. As a side effect, it also makes the error message the user
will get during the next "push" attempt easier to understand, now
the user is aware that a non-commit object is involved.
In these cases, the current code already rejects such a push on the
client end, but we used the same error and advice messages as the
ones used when rejecting a non-fast-forward push, i.e. pull from
there and integrate before pushing again.
Introduce new rejection reasons and reword the messages
appropriately.
[jc: with help by Peff on message details]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-24 05:55:30 +08:00
|
|
|
static const char message_advice_ref_needs_force[] =
|
|
|
|
N_("You cannot update a remote ref that points at a non-commit object,\n"
|
|
|
|
"or update a remote ref to make it point at a non-commit object,\n"
|
|
|
|
"without using the '--force' option.\n");
|
2012-11-30 09:41:34 +08:00
|
|
|
|
push: Provide situational hints for non-fast-forward errors
Pushing a non-fast-forward update to a remote repository will result in
an error, but the hint text doesn't provide the correct resolution in
every case. Give better resolution advice in three push scenarios:
1) If you push your current branch and it triggers a non-fast-forward
error, you should merge remote changes with 'git pull' before pushing
again.
2) If you push to a shared repository others push to, and your local
tracking branches are not kept up to date, the 'matching refs' default
will generate non-fast-forward errors on outdated branches. If this is
your workflow, the 'matching refs' default is not for you. Consider
setting the 'push.default' configuration variable to 'current' or
'upstream' to ensure only your current branch is pushed.
3) If you explicitly specify a ref that is not your current branch or
push matching branches with ':', you will generate a non-fast-forward
error if any pushed branch tip is out of date. You should checkout the
offending branch and merge remote changes before pushing again.
Teach transport.c to recognize these scenarios and configure push.c
to hint for them. If 'git push's default behavior changes or we
discover more scenarios, extension is easy. Standardize on the
advice API and add three new advice variables, 'pushNonFFCurrent',
'pushNonFFDefault', and 'pushNonFFMatching'. Setting any of these
to 'false' will disable their affiliated advice. Setting
'pushNonFastForward' to false will disable all three, thus preserving the
config option for users who already set it, but guaranteeing new
users won't disable push advice accidentally.
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Christopher Tiwald <christiwald@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-20 12:31:33 +08:00
|
|
|
static void advise_pull_before_push(void)
|
|
|
|
{
|
2012-12-03 11:27:50 +08:00
|
|
|
if (!advice_push_non_ff_current || !advice_push_update_rejected)
|
push: Provide situational hints for non-fast-forward errors
Pushing a non-fast-forward update to a remote repository will result in
an error, but the hint text doesn't provide the correct resolution in
every case. Give better resolution advice in three push scenarios:
1) If you push your current branch and it triggers a non-fast-forward
error, you should merge remote changes with 'git pull' before pushing
again.
2) If you push to a shared repository others push to, and your local
tracking branches are not kept up to date, the 'matching refs' default
will generate non-fast-forward errors on outdated branches. If this is
your workflow, the 'matching refs' default is not for you. Consider
setting the 'push.default' configuration variable to 'current' or
'upstream' to ensure only your current branch is pushed.
3) If you explicitly specify a ref that is not your current branch or
push matching branches with ':', you will generate a non-fast-forward
error if any pushed branch tip is out of date. You should checkout the
offending branch and merge remote changes before pushing again.
Teach transport.c to recognize these scenarios and configure push.c
to hint for them. If 'git push's default behavior changes or we
discover more scenarios, extension is easy. Standardize on the
advice API and add three new advice variables, 'pushNonFFCurrent',
'pushNonFFDefault', and 'pushNonFFMatching'. Setting any of these
to 'false' will disable their affiliated advice. Setting
'pushNonFastForward' to false will disable all three, thus preserving the
config option for users who already set it, but guaranteeing new
users won't disable push advice accidentally.
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Christopher Tiwald <christiwald@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-20 12:31:33 +08:00
|
|
|
return;
|
|
|
|
advise(_(message_advice_pull_before_push));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void advise_checkout_pull_push(void)
|
|
|
|
{
|
2012-12-03 11:27:50 +08:00
|
|
|
if (!advice_push_non_ff_matching || !advice_push_update_rejected)
|
push: Provide situational hints for non-fast-forward errors
Pushing a non-fast-forward update to a remote repository will result in
an error, but the hint text doesn't provide the correct resolution in
every case. Give better resolution advice in three push scenarios:
1) If you push your current branch and it triggers a non-fast-forward
error, you should merge remote changes with 'git pull' before pushing
again.
2) If you push to a shared repository others push to, and your local
tracking branches are not kept up to date, the 'matching refs' default
will generate non-fast-forward errors on outdated branches. If this is
your workflow, the 'matching refs' default is not for you. Consider
setting the 'push.default' configuration variable to 'current' or
'upstream' to ensure only your current branch is pushed.
3) If you explicitly specify a ref that is not your current branch or
push matching branches with ':', you will generate a non-fast-forward
error if any pushed branch tip is out of date. You should checkout the
offending branch and merge remote changes before pushing again.
Teach transport.c to recognize these scenarios and configure push.c
to hint for them. If 'git push's default behavior changes or we
discover more scenarios, extension is easy. Standardize on the
advice API and add three new advice variables, 'pushNonFFCurrent',
'pushNonFFDefault', and 'pushNonFFMatching'. Setting any of these
to 'false' will disable their affiliated advice. Setting
'pushNonFastForward' to false will disable all three, thus preserving the
config option for users who already set it, but guaranteeing new
users won't disable push advice accidentally.
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Christopher Tiwald <christiwald@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-20 12:31:33 +08:00
|
|
|
return;
|
|
|
|
advise(_(message_advice_checkout_pull_push));
|
|
|
|
}
|
|
|
|
|
2012-11-30 09:41:34 +08:00
|
|
|
static void advise_ref_already_exists(void)
|
|
|
|
{
|
2012-12-03 11:27:51 +08:00
|
|
|
if (!advice_push_already_exists || !advice_push_update_rejected)
|
|
|
|
return;
|
2012-11-30 09:41:34 +08:00
|
|
|
advise(_(message_advice_ref_already_exists));
|
|
|
|
}
|
|
|
|
|
push: introduce REJECT_FETCH_FIRST and REJECT_NEEDS_FORCE
When we push to update an existing ref, if:
* the object at the tip of the remote is not a commit; or
* the object we are pushing is not a commit,
it won't be correct to suggest to fetch, integrate and push again,
as the old and new objects will not "merge". We should explain that
the push must be forced when there is a non-committish object is
involved in such a case.
If we do not have the current object at the tip of the remote, we do
not even know that object, when fetched, is something that can be
merged. In such a case, suggesting to pull first just like
non-fast-forward case may not be technically correct, but in
practice, most such failures are seen when you try to push your work
to a branch without knowing that somebody else already pushed to
update the same branch since you forked, so "pull first" would work
as a suggestion most of the time. And if the object at the tip is
not a commit, "pull first" will fail, without making any permanent
damage. As a side effect, it also makes the error message the user
will get during the next "push" attempt easier to understand, now
the user is aware that a non-commit object is involved.
In these cases, the current code already rejects such a push on the
client end, but we used the same error and advice messages as the
ones used when rejecting a non-fast-forward push, i.e. pull from
there and integrate before pushing again.
Introduce new rejection reasons and reword the messages
appropriately.
[jc: with help by Peff on message details]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-24 05:55:30 +08:00
|
|
|
static void advise_ref_fetch_first(void)
|
|
|
|
{
|
|
|
|
if (!advice_push_fetch_first || !advice_push_update_rejected)
|
|
|
|
return;
|
|
|
|
advise(_(message_advice_ref_fetch_first));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void advise_ref_needs_force(void)
|
|
|
|
{
|
|
|
|
if (!advice_push_needs_force || !advice_push_update_rejected)
|
|
|
|
return;
|
|
|
|
advise(_(message_advice_ref_needs_force));
|
|
|
|
}
|
|
|
|
|
2018-05-17 06:58:16 +08:00
|
|
|
static int push_with_options(struct transport *transport, struct refspec *rs,
|
|
|
|
int flags)
|
2009-11-18 09:42:22 +08:00
|
|
|
{
|
|
|
|
int err;
|
2012-11-30 09:41:33 +08:00
|
|
|
unsigned int reject_reasons;
|
2010-02-24 20:50:24 +08:00
|
|
|
|
2010-02-24 20:50:27 +08:00
|
|
|
transport_set_verbosity(transport, verbosity, progress);
|
2016-02-03 12:09:14 +08:00
|
|
|
transport->family = family;
|
2010-02-24 20:50:24 +08:00
|
|
|
|
2009-11-18 09:42:22 +08:00
|
|
|
if (receivepack)
|
|
|
|
transport_set_option(transport,
|
|
|
|
TRANS_OPT_RECEIVEPACK, receivepack);
|
2013-08-12 21:55:55 +08:00
|
|
|
transport_set_option(transport, TRANS_OPT_THIN, thin ? "yes" : NULL);
|
2009-11-18 09:42:22 +08:00
|
|
|
|
2013-07-10 02:01:06 +08:00
|
|
|
if (!is_empty_cas(&cas)) {
|
|
|
|
if (!transport->smart_options)
|
|
|
|
die("underlying transport does not support --%s option",
|
|
|
|
CAS_OPT_NAME);
|
|
|
|
transport->smart_options->cas = &cas;
|
|
|
|
}
|
|
|
|
|
2010-02-24 20:50:24 +08:00
|
|
|
if (verbosity > 0)
|
2011-02-23 07:42:11 +08:00
|
|
|
fprintf(stderr, _("Pushing to %s\n"), transport->url);
|
2018-11-10 13:48:55 +08:00
|
|
|
err = transport_push(the_repository, transport,
|
|
|
|
rs, flags, &reject_reasons);
|
2018-04-21 18:10:00 +08:00
|
|
|
if (err != 0) {
|
|
|
|
fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
|
2011-02-23 07:42:11 +08:00
|
|
|
error(_("failed to push some refs to '%s'"), transport->url);
|
2018-04-21 18:10:00 +08:00
|
|
|
fprintf(stderr, "%s", push_get_color(PUSH_COLOR_RESET));
|
|
|
|
}
|
2009-12-04 07:31:44 +08:00
|
|
|
|
2009-11-18 09:42:22 +08:00
|
|
|
err |= transport_disconnect(transport);
|
|
|
|
if (!err)
|
|
|
|
return 0;
|
|
|
|
|
2012-11-30 09:41:33 +08:00
|
|
|
if (reject_reasons & REJECT_NON_FF_HEAD) {
|
push: Provide situational hints for non-fast-forward errors
Pushing a non-fast-forward update to a remote repository will result in
an error, but the hint text doesn't provide the correct resolution in
every case. Give better resolution advice in three push scenarios:
1) If you push your current branch and it triggers a non-fast-forward
error, you should merge remote changes with 'git pull' before pushing
again.
2) If you push to a shared repository others push to, and your local
tracking branches are not kept up to date, the 'matching refs' default
will generate non-fast-forward errors on outdated branches. If this is
your workflow, the 'matching refs' default is not for you. Consider
setting the 'push.default' configuration variable to 'current' or
'upstream' to ensure only your current branch is pushed.
3) If you explicitly specify a ref that is not your current branch or
push matching branches with ':', you will generate a non-fast-forward
error if any pushed branch tip is out of date. You should checkout the
offending branch and merge remote changes before pushing again.
Teach transport.c to recognize these scenarios and configure push.c
to hint for them. If 'git push's default behavior changes or we
discover more scenarios, extension is easy. Standardize on the
advice API and add three new advice variables, 'pushNonFFCurrent',
'pushNonFFDefault', and 'pushNonFFMatching'. Setting any of these
to 'false' will disable their affiliated advice. Setting
'pushNonFastForward' to false will disable all three, thus preserving the
config option for users who already set it, but guaranteeing new
users won't disable push advice accidentally.
Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Christopher Tiwald <christiwald@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-20 12:31:33 +08:00
|
|
|
advise_pull_before_push();
|
2012-11-30 09:41:33 +08:00
|
|
|
} else if (reject_reasons & REJECT_NON_FF_OTHER) {
|
2013-01-05 08:02:29 +08:00
|
|
|
advise_checkout_pull_push();
|
2012-11-30 09:41:34 +08:00
|
|
|
} else if (reject_reasons & REJECT_ALREADY_EXISTS) {
|
|
|
|
advise_ref_already_exists();
|
push: introduce REJECT_FETCH_FIRST and REJECT_NEEDS_FORCE
When we push to update an existing ref, if:
* the object at the tip of the remote is not a commit; or
* the object we are pushing is not a commit,
it won't be correct to suggest to fetch, integrate and push again,
as the old and new objects will not "merge". We should explain that
the push must be forced when there is a non-committish object is
involved in such a case.
If we do not have the current object at the tip of the remote, we do
not even know that object, when fetched, is something that can be
merged. In such a case, suggesting to pull first just like
non-fast-forward case may not be technically correct, but in
practice, most such failures are seen when you try to push your work
to a branch without knowing that somebody else already pushed to
update the same branch since you forked, so "pull first" would work
as a suggestion most of the time. And if the object at the tip is
not a commit, "pull first" will fail, without making any permanent
damage. As a side effect, it also makes the error message the user
will get during the next "push" attempt easier to understand, now
the user is aware that a non-commit object is involved.
In these cases, the current code already rejects such a push on the
client end, but we used the same error and advice messages as the
ones used when rejecting a non-fast-forward push, i.e. pull from
there and integrate before pushing again.
Introduce new rejection reasons and reword the messages
appropriately.
[jc: with help by Peff on message details]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-24 05:55:30 +08:00
|
|
|
} else if (reject_reasons & REJECT_FETCH_FIRST) {
|
|
|
|
advise_ref_fetch_first();
|
|
|
|
} else if (reject_reasons & REJECT_NEEDS_FORCE) {
|
|
|
|
advise_ref_needs_force();
|
2009-11-18 09:42:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-07-15 05:49:47 +08:00
|
|
|
static int do_push(const char *repo, int flags,
|
|
|
|
const struct string_list *push_options)
|
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 12:22:49 +08:00
|
|
|
{
|
2007-05-12 23:45:53 +08:00
|
|
|
int i, errs;
|
remote.c: introduce a way to have different remotes for fetch/push
Currently, do_push() in push.c calls remote_get(), which gets the
configured remote for fetching and pushing. Replace this call with a
call to pushremote_get() instead, a new function that will return the
remote configured specifically for pushing. This function tries to
work with the string pushremote_name, before falling back to the
codepath of remote_get(). This patch has no visible impact, but
serves to enable future patches to introduce configuration variables
to set pushremote_name. For example, you can now do the following in
handle_config():
if (!strcmp(key, "remote.pushdefault"))
git_config_string(&pushremote_name, key, value);
Then, pushes will automatically go to the remote specified by
remote.pushdefault.
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-02 15:40:32 +08:00
|
|
|
struct remote *remote = pushremote_get(repo);
|
2009-06-10 00:01:34 +08:00
|
|
|
const char **url;
|
|
|
|
int url_nr;
|
2018-05-17 06:58:16 +08:00
|
|
|
struct refspec *push_refspec = &rs;
|
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 12:22:49 +08: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 13:47:20 +08:00
|
|
|
if (!remote) {
|
|
|
|
if (repo)
|
2011-02-23 07:42:11 +08:00
|
|
|
die(_("bad repository '%s'"), repo);
|
2011-04-02 08:55:55 +08:00
|
|
|
die(_("No configured push destination.\n"
|
2011-03-03 04:12:11 +08:00
|
|
|
"Either specify the URL from the command-line or configure a remote repository using\n"
|
|
|
|
"\n"
|
|
|
|
" git remote add <name> <url>\n"
|
|
|
|
"\n"
|
|
|
|
"and then push using the remote name\n"
|
|
|
|
"\n"
|
2011-04-02 08:55:55 +08:00
|
|
|
" git push <name>\n"));
|
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 13:47:20 +08:00
|
|
|
}
|
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 12:22:49 +08:00
|
|
|
|
2008-04-17 19:17:20 +08:00
|
|
|
if (remote->mirror)
|
|
|
|
flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
|
|
|
|
|
2016-07-15 05:49:47 +08:00
|
|
|
if (push_options->nr)
|
|
|
|
flags |= TRANSPORT_PUSH_OPTIONS;
|
|
|
|
|
2018-05-17 06:58:16 +08:00
|
|
|
if (!push_refspec->nr && !(flags & TRANSPORT_PUSH_ALL)) {
|
|
|
|
if (remote->push.nr) {
|
|
|
|
push_refspec = &remote->push;
|
2009-03-16 23:42:51 +08:00
|
|
|
} else if (!(flags & TRANSPORT_PUSH_MIRROR))
|
2011-03-03 04:12:10 +08:00
|
|
|
setup_default_push_refspecs(remote);
|
2007-05-12 23:45:53 +08:00
|
|
|
}
|
2007-04-07 14:04:53 +08:00
|
|
|
errs = 0;
|
push: error out when the "upstream" semantics does not make sense
The user can say "git push" without specifying any refspec. When using
the "upstream" semantics via the push.default configuration, the user
wants to update the "upstream" branch of the current branch, which is the
branch at a remote repository the current branch is set to integrate with,
with this command.
However, there are cases that such a "git push" that uses the "upstream"
semantics does not make sense:
- The current branch does not have branch.$name.remote configured. By
definition, "git push" that does not name where to push to will not
know where to push to. The user may explicitly say "git push $there",
but again, by definition, no branch at repository $there is set to
integrate with the current branch in this case and we wouldn't know
which remote branch to update.
- The current branch does have branch.$name.remote configured, but it
does not specify branch.$name.merge that names what branch at the
remote this branch integrates with. "git push" knows where to push in
this case (or the user may explicitly say "git push $remote" to tell us
where to push), but we do not know which remote branch to update.
- The current branch does have its remote and upstream branch configured,
but the user said "git push $there", where $there is not the remote
named by "branch.$name.remote". By definition, no branch at repository
$there is set to integrate with the current branch in this case, and
this push is not meant to update any branch at the remote repository
$there.
The first two cases were already checked correctly, but the third case was
not checked and we ended up updating the branch named branch.$name.merge
at repository $there, which was totally bogus.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-31 07:07:12 +08:00
|
|
|
url_nr = push_url_of_remote(remote, &url);
|
2009-11-18 09:42:22 +08:00
|
|
|
if (url_nr) {
|
|
|
|
for (i = 0; i < url_nr; i++) {
|
|
|
|
struct transport *transport =
|
|
|
|
transport_get(remote, url[i]);
|
2016-07-15 05:49:47 +08:00
|
|
|
if (flags & TRANSPORT_PUSH_OPTIONS)
|
|
|
|
transport->push_options = push_options;
|
2018-05-17 06:58:16 +08:00
|
|
|
if (push_with_options(transport, push_refspec, flags))
|
2009-11-18 09:42:22 +08:00
|
|
|
errs++;
|
2009-08-08 15:51:08 +08:00
|
|
|
}
|
2009-11-18 09:42:22 +08:00
|
|
|
} else {
|
|
|
|
struct transport *transport =
|
|
|
|
transport_get(remote, NULL);
|
2016-07-15 05:49:47 +08:00
|
|
|
if (flags & TRANSPORT_PUSH_OPTIONS)
|
|
|
|
transport->push_options = push_options;
|
2018-05-17 06:58:16 +08:00
|
|
|
if (push_with_options(transport, push_refspec, flags))
|
2009-11-18 09:42:22 +08:00
|
|
|
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 12:22:49 +08:00
|
|
|
}
|
2007-04-07 14:04:53 +08: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 12:22:49 +08:00
|
|
|
}
|
|
|
|
|
2011-08-20 06:08:47 +08:00
|
|
|
static int option_parse_recurse_submodules(const struct option *opt,
|
|
|
|
const char *arg, int unset)
|
|
|
|
{
|
2015-11-17 19:05:56 +08:00
|
|
|
int *recurse_submodules = opt->value;
|
2012-03-29 15:21:24 +08:00
|
|
|
|
2015-11-17 19:05:56 +08:00
|
|
|
if (unset)
|
|
|
|
*recurse_submodules = RECURSE_SUBMODULES_OFF;
|
|
|
|
else if (arg)
|
|
|
|
*recurse_submodules = parse_push_recurse_submodules_arg(opt->long_name, arg);
|
|
|
|
else
|
|
|
|
die("%s missing parameter", opt->long_name);
|
2011-08-20 06:08:47 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-19 23:26:47 +08:00
|
|
|
static void set_push_cert_flags(int *flags, int v)
|
|
|
|
{
|
|
|
|
switch (v) {
|
|
|
|
case SEND_PACK_PUSH_CERT_NEVER:
|
|
|
|
*flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED);
|
|
|
|
break;
|
|
|
|
case SEND_PACK_PUSH_CERT_ALWAYS:
|
|
|
|
*flags |= TRANSPORT_PUSH_CERT_ALWAYS;
|
|
|
|
*flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED;
|
|
|
|
break;
|
|
|
|
case SEND_PACK_PUSH_CERT_IF_ASKED:
|
|
|
|
*flags |= TRANSPORT_PUSH_CERT_IF_ASKED;
|
|
|
|
*flags &= ~TRANSPORT_PUSH_CERT_ALWAYS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-22 22:57:49 +08:00
|
|
|
static int git_push_config(const char *k, const char *v, void *cb)
|
|
|
|
{
|
2018-04-21 18:10:00 +08:00
|
|
|
const char *slot_name;
|
2015-02-16 14:16:19 +08:00
|
|
|
int *flags = cb;
|
2014-10-22 22:57:49 +08:00
|
|
|
int status;
|
|
|
|
|
|
|
|
status = git_gpg_config(k, v, NULL);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2015-02-16 14:16:19 +08:00
|
|
|
|
|
|
|
if (!strcmp(k, "push.followtags")) {
|
|
|
|
if (git_config_bool(k, v))
|
|
|
|
*flags |= TRANSPORT_PUSH_FOLLOW_TAGS;
|
|
|
|
else
|
|
|
|
*flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS;
|
|
|
|
return 0;
|
2015-08-19 23:26:47 +08:00
|
|
|
} else if (!strcmp(k, "push.gpgsign")) {
|
|
|
|
const char *value;
|
|
|
|
if (!git_config_get_value("push.gpgsign", &value)) {
|
2017-08-08 02:20:49 +08:00
|
|
|
switch (git_parse_maybe_bool(value)) {
|
2015-08-19 23:26:47 +08:00
|
|
|
case 0:
|
|
|
|
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (value && !strcasecmp(value, "if-asked"))
|
|
|
|
set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
|
|
|
|
else
|
|
|
|
return error("Invalid value for '%s'", k);
|
|
|
|
}
|
|
|
|
}
|
2015-11-17 19:05:56 +08:00
|
|
|
} else if (!strcmp(k, "push.recursesubmodules")) {
|
|
|
|
const char *value;
|
|
|
|
if (!git_config_get_value("push.recursesubmodules", &value))
|
|
|
|
recurse_submodules = parse_push_recurse_submodules_arg(k, value);
|
2017-06-01 08:30:49 +08:00
|
|
|
} else if (!strcmp(k, "submodule.recurse")) {
|
|
|
|
int val = git_config_bool(k, v) ?
|
|
|
|
RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
|
|
|
|
recurse_submodules = val;
|
2017-10-23 19:44:49 +08:00
|
|
|
} else if (!strcmp(k, "push.pushoption")) {
|
|
|
|
if (!v)
|
|
|
|
return config_error_nonbool(k);
|
|
|
|
else
|
|
|
|
if (!*v)
|
|
|
|
string_list_clear(&push_options_config, 0);
|
|
|
|
else
|
|
|
|
string_list_append(&push_options_config, v);
|
|
|
|
return 0;
|
2018-04-21 18:10:00 +08:00
|
|
|
} else if (!strcmp(k, "color.push")) {
|
|
|
|
push_use_color = git_config_colorbool(k, v);
|
|
|
|
return 0;
|
|
|
|
} else if (skip_prefix(k, "color.push.", &slot_name)) {
|
|
|
|
int slot = parse_push_color_slot(slot_name);
|
|
|
|
if (slot < 0)
|
|
|
|
return 0;
|
|
|
|
if (!v)
|
|
|
|
return config_error_nonbool(k);
|
|
|
|
return color_parse(v, push_colors[slot]);
|
2015-02-16 14:16:19 +08:00
|
|
|
}
|
|
|
|
|
2015-02-16 13:46:30 +08:00
|
|
|
return git_default_config(k, v, NULL);
|
2014-10-22 22:57:49 +08:00
|
|
|
}
|
|
|
|
|
2006-07-29 13:44:25 +08: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 12:22:49 +08:00
|
|
|
{
|
2007-09-11 11:03:04 +08:00
|
|
|
int flags = 0;
|
2007-11-05 11:35:37 +08:00
|
|
|
int tags = 0;
|
2015-08-19 23:26:46 +08:00
|
|
|
int push_cert = -1;
|
2008-04-17 19:17:20 +08:00
|
|
|
int rc;
|
2007-05-12 23:45:53 +08:00
|
|
|
const char *repo = NULL; /* default repository */
|
2017-10-23 19:44:49 +08:00
|
|
|
struct string_list push_options_cmdline = STRING_LIST_INIT_DUP;
|
|
|
|
struct string_list *push_options;
|
2017-04-01 07:56:22 +08:00
|
|
|
const struct string_list_item *item;
|
2016-07-15 05:49:47 +08:00
|
|
|
|
2007-11-05 11:35:37 +08:00
|
|
|
struct option options[] = {
|
2010-02-24 20:50:24 +08:00
|
|
|
OPT__VERBOSITY(&verbosity),
|
2012-08-20 20:32:33 +08:00
|
|
|
OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
|
|
|
|
OPT_BIT( 0 , "all", &flags, N_("push all refs"), TRANSPORT_PUSH_ALL),
|
|
|
|
OPT_BIT( 0 , "mirror", &flags, N_("mirror all refs"),
|
2008-07-20 20:02:20 +08:00
|
|
|
(TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
|
2015-12-14 23:23:04 +08:00
|
|
|
OPT_BOOL('d', "delete", &deleterefs, N_("delete refs")),
|
2013-08-03 19:51:19 +08:00
|
|
|
OPT_BOOL( 0 , "tags", &tags, N_("push tags (can't be used with --all or --mirror)")),
|
2012-08-20 20:32:33 +08:00
|
|
|
OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
|
|
|
|
OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
|
|
|
|
OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
|
remote.c: add command line option parser for "--force-with-lease"
Update "git push" and "git send-pack" to parse this commnd line
option.
The intended sematics is:
* "--force-with-lease" alone, without specifying the details, will
protect _all_ remote refs that are going to be updated by
requiring their current value to be the same as some reasonable
default, unless otherwise specified;
* "--force-with-lease=refname", without specifying the expected
value, will protect that refname, if it is going to be updated,
by requiring its current value to be the same as some reasonable
default.
* "--force-with-lease=refname:value" will protect that refname, if
it is going to be updated, by requiring its current value to be
the same as the specified value; and
* "--no-force-with-lease" will cancel all the previous --force-with-lease on the
command line.
For now, "some reasonable default" is tentatively defined as "the
value of the remote-tracking branch we have for the ref of the
remote being updated", and it is an error if we do not have such a
remote-tracking branch. But this is known to be fragile, its use is
not yet recommended, and hopefully we will find more reasonable
default as we gain experience with this feature. The manual marks
the feature as experimental unless the expected value is specified
explicitly for this reason.
Because the command line options are parsed _before_ we know which
remote we are pushing to, there needs further processing to the
parsed data after we instantiate the transport object to:
* expand "refname" given by the user to a full refname to be
matched with the list of "struct ref" used in match_push_refs()
and set_ref_status_for_push(); and
* learning the actual local ref that is the remote-tracking branch
for the specified remote ref.
Further, some processing need to be deferred until we find the set
of remote refs and match_push_refs() returns in order to find the
ones that need to be checked after explicit ones have been processed
for "--force-with-lease" (no specific details).
These post-processing will be the topic of the next patch.
This option was originally called "cas" (for "compare and swap"),
the name which nobody liked because it was too technical. The
second attempt called it "lockref" (because it is conceptually like
pushing after taking a lock) but the word "lock" was hated because
it implied that it may reject push by others, which is not the way
this option works. This round calls it "force-with-lease". You
assume you took the lease on the ref when you fetched to decide what
the rebased history should be, and you can push back only if the
lease has not been broken.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-09 06:34:36 +08:00
|
|
|
{ OPTION_CALLBACK,
|
2018-08-02 06:31:33 +08:00
|
|
|
0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"),
|
remote.c: add command line option parser for "--force-with-lease"
Update "git push" and "git send-pack" to parse this commnd line
option.
The intended sematics is:
* "--force-with-lease" alone, without specifying the details, will
protect _all_ remote refs that are going to be updated by
requiring their current value to be the same as some reasonable
default, unless otherwise specified;
* "--force-with-lease=refname", without specifying the expected
value, will protect that refname, if it is going to be updated,
by requiring its current value to be the same as some reasonable
default.
* "--force-with-lease=refname:value" will protect that refname, if
it is going to be updated, by requiring its current value to be
the same as the specified value; and
* "--no-force-with-lease" will cancel all the previous --force-with-lease on the
command line.
For now, "some reasonable default" is tentatively defined as "the
value of the remote-tracking branch we have for the ref of the
remote being updated", and it is an error if we do not have such a
remote-tracking branch. But this is known to be fragile, its use is
not yet recommended, and hopefully we will find more reasonable
default as we gain experience with this feature. The manual marks
the feature as experimental unless the expected value is specified
explicitly for this reason.
Because the command line options are parsed _before_ we know which
remote we are pushing to, there needs further processing to the
parsed data after we instantiate the transport object to:
* expand "refname" given by the user to a full refname to be
matched with the list of "struct ref" used in match_push_refs()
and set_ref_status_for_push(); and
* learning the actual local ref that is the remote-tracking branch
for the specified remote ref.
Further, some processing need to be deferred until we find the set
of remote refs and match_push_refs() returns in order to find the
ones that need to be checked after explicit ones have been processed
for "--force-with-lease" (no specific details).
These post-processing will be the topic of the next patch.
This option was originally called "cas" (for "compare and swap"),
the name which nobody liked because it was too technical. The
second attempt called it "lockref" (because it is conceptually like
pushing after taking a lock) but the word "lock" was hated because
it implied that it may reject push by others, which is not the way
this option works. This round calls it "force-with-lease". You
assume you took the lease on the ref when you fetched to decide what
the rebased history should be, and you can push back only if the
lease has not been broken.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-09 06:34:36 +08:00
|
|
|
N_("require old value of ref to be at this value"),
|
2018-08-02 06:31:33 +08:00
|
|
|
PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option },
|
2018-08-20 01:34:48 +08:00
|
|
|
{ OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules, "(check|on-demand|no)",
|
2012-08-20 20:32:55 +08:00
|
|
|
N_("control recursive pushing of submodules"),
|
2011-08-20 06:08:47 +08:00
|
|
|
PARSE_OPT_OPTARG, option_parse_recurse_submodules },
|
2018-02-09 19:02:10 +08:00
|
|
|
OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE),
|
2012-08-20 20:32:33 +08:00
|
|
|
OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")),
|
|
|
|
OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")),
|
|
|
|
OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"),
|
2010-01-17 05:45:31 +08:00
|
|
|
TRANSPORT_PUSH_SET_UPSTREAM),
|
2012-08-20 20:32:33 +08:00
|
|
|
OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
|
|
|
|
OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
|
2012-02-23 06:43:41 +08:00
|
|
|
TRANSPORT_PUSH_PRUNE),
|
2013-01-13 13:17:03 +08:00
|
|
|
OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
|
2013-03-05 04:09:50 +08:00
|
|
|
OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
|
|
|
|
TRANSPORT_PUSH_FOLLOW_TAGS),
|
2015-08-19 23:26:46 +08:00
|
|
|
{ OPTION_CALLBACK,
|
2018-08-20 01:34:48 +08:00
|
|
|
0, "signed", &push_cert, "(yes|no|if-asked)", N_("GPG sign the push"),
|
2015-08-19 23:26:46 +08:00
|
|
|
PARSE_OPT_OPTARG, option_parse_push_signed },
|
2015-02-16 14:12:04 +08:00
|
|
|
OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
|
2017-10-23 19:44:49 +08:00
|
|
|
OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
|
2016-02-03 12:09:14 +08:00
|
|
|
OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
|
|
|
|
TRANSPORT_FAMILY_IPV4),
|
|
|
|
OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
|
|
|
|
TRANSPORT_FAMILY_IPV6),
|
2007-11-05 11:35:37 +08: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 12:22:49 +08:00
|
|
|
|
2011-02-24 22:30:19 +08:00
|
|
|
packet_trace_identity("push");
|
2015-02-16 14:13:25 +08:00
|
|
|
git_config(git_push_config, &flags);
|
2009-05-24 02:53:12 +08:00
|
|
|
argc = parse_options(argc, argv, prefix, options, push_usage, 0);
|
2017-10-23 19:44:49 +08:00
|
|
|
push_options = (push_options_cmdline.nr
|
|
|
|
? &push_options_cmdline
|
|
|
|
: &push_options_config);
|
2015-08-19 23:26:47 +08:00
|
|
|
set_push_cert_flags(&flags, push_cert);
|
2007-11-05 11:35:37 +08:00
|
|
|
|
2009-12-31 03:57:42 +08:00
|
|
|
if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
|
2011-02-23 07:42:11 +08:00
|
|
|
die(_("--delete is incompatible with --all, --mirror and --tags"));
|
2009-12-31 03:57:42 +08:00
|
|
|
if (deleterefs && argc < 2)
|
2011-02-23 07:42:11 +08:00
|
|
|
die(_("--delete doesn't make sense without any refs"));
|
2018-05-17 06:58:15 +08:00
|
|
|
if (flags & TRANSPORT_PUSH_ALL) {
|
|
|
|
if (tags)
|
|
|
|
die(_("--all and --tags are incompatible"));
|
|
|
|
if (argc >= 2)
|
|
|
|
die(_("--all can't be combined with refspecs"));
|
|
|
|
}
|
|
|
|
if (flags & TRANSPORT_PUSH_MIRROR) {
|
|
|
|
if (tags)
|
|
|
|
die(_("--mirror and --tags are incompatible"));
|
|
|
|
if (argc >= 2)
|
|
|
|
die(_("--mirror can't be combined with refspecs"));
|
|
|
|
}
|
|
|
|
if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR))
|
|
|
|
die(_("--all and --mirror are incompatible"));
|
2009-12-31 03:57:42 +08:00
|
|
|
|
2015-11-17 19:05:56 +08:00
|
|
|
if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
|
|
|
|
flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
|
|
|
|
else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
|
|
|
|
flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
|
2016-12-20 02:25:33 +08:00
|
|
|
else if (recurse_submodules == RECURSE_SUBMODULES_ONLY)
|
|
|
|
flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY;
|
2015-11-17 19:05:56 +08:00
|
|
|
|
2007-11-05 11:35:37 +08:00
|
|
|
if (tags)
|
2018-05-17 06:58:16 +08:00
|
|
|
refspec_append(&rs, "refs/tags/*");
|
2007-11-05 11:35:37 +08:00
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
repo = argv[0];
|
push: use remote.$name.push as a refmap
Since f2690487 (fetch: opportunistically update tracking refs,
2013-05-11), we stopped taking a non-storing refspec given on the
command line of "git fetch" literally, and instead started mapping
it via remote.$name.fetch refspecs. This allows
$ git fetch origin master
from the 'origin' repository, which is configured with
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
to update refs/remotes/origin/master with the result, as if the
command line were
$ git fetch origin +master:refs/remotes/origin/master
to reduce surprises and improve usability. Before that change, a
refspec on the command line without a colon was only to fetch the
history and leave the result in FETCH_HEAD, without updating the
remote-tracking branches.
When you are simulating a fetch from you by your mothership with a
push by you into your mothership, instead of having:
[remote "satellite"]
fetch = +refs/heads/*:refs/remotes/satellite/*
on the mothership repository and running:
mothership$ git fetch satellite
you would have:
[remote "mothership"]
push = +refs/heads/*:refs/remotes/satellite/*
on your satellite machine, and run:
satellite$ git push mothership
Because we so far did not make the corresponding change to the push
side, this command:
satellite$ git push mothership master
does _not_ allow you on the satellite to only push 'master' out but
still to the usual destination (i.e. refs/remotes/satellite/master).
Implement the logic to map an unqualified refspec given on the
command line via the remote.$name.push refspec. This will bring a
bit more symmetry between "fetch" and "push".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-12-04 07:41:15 +08:00
|
|
|
set_refspecs(argv + 1, argc - 1, repo);
|
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 12:22:49 +08:00
|
|
|
}
|
2007-05-25 13:20:56 +08:00
|
|
|
|
2017-10-23 19:44:49 +08:00
|
|
|
for_each_string_list_item(item, push_options)
|
2016-07-15 05:49:47 +08:00
|
|
|
if (strchr(item->string, '\n'))
|
|
|
|
die(_("push options must not have new line characters"));
|
|
|
|
|
2017-10-23 19:44:49 +08:00
|
|
|
rc = do_push(repo, flags, push_options);
|
|
|
|
string_list_clear(&push_options_cmdline, 0);
|
|
|
|
string_list_clear(&push_options_config, 0);
|
2008-04-17 19:17:20 +08:00
|
|
|
if (rc == -1)
|
2007-11-10 07:32:25 +08:00
|
|
|
usage_with_options(push_usage, options);
|
2008-04-17 19:17:20 +08: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 12:22:49 +08:00
|
|
|
}
|