Allow push and fetch urls to be different
This introduces a config setting remote.$remotename.pushurl which is used for pushes only. If absent remote.$remotename.url is used for pushes and fetches as before. This is useful, for example, in order to do passwordless fetches (remote update) over the git transport but pushes over ssh. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
f4f78e668d
commit
203462347f
@ -1319,6 +1319,9 @@ remote.<name>.url::
|
|||||||
The URL of a remote repository. See linkgit:git-fetch[1] or
|
The URL of a remote repository. See linkgit:git-fetch[1] or
|
||||||
linkgit:git-push[1].
|
linkgit:git-push[1].
|
||||||
|
|
||||||
|
remote.<name>.pushurl::
|
||||||
|
The push URL of a remote repository. See linkgit:git-push[1].
|
||||||
|
|
||||||
remote.<name>.proxy::
|
remote.<name>.proxy::
|
||||||
For remotes that require curl (http, https and ftp), the URL to
|
For remotes that require curl (http, https and ftp), the URL to
|
||||||
the proxy to use for that remote. Set to the empty string to
|
the proxy to use for that remote. Set to the empty string to
|
||||||
|
@ -27,10 +27,13 @@ config file would appear like this:
|
|||||||
------------
|
------------
|
||||||
[remote "<name>"]
|
[remote "<name>"]
|
||||||
url = <url>
|
url = <url>
|
||||||
|
pushurl = <pushurl>
|
||||||
push = <refspec>
|
push = <refspec>
|
||||||
fetch = <refspec>
|
fetch = <refspec>
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
The `<pushurl>` is used for pushes only. It is optional and defaults
|
||||||
|
to `<url>`.
|
||||||
|
|
||||||
Named file in `$GIT_DIR/remotes`
|
Named file in `$GIT_DIR/remotes`
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -117,6 +117,8 @@ static int do_push(const char *repo, int flags)
|
|||||||
{
|
{
|
||||||
int i, errs;
|
int i, errs;
|
||||||
struct remote *remote = remote_get(repo);
|
struct remote *remote = remote_get(repo);
|
||||||
|
const char **url;
|
||||||
|
int url_nr;
|
||||||
|
|
||||||
if (!remote) {
|
if (!remote) {
|
||||||
if (repo)
|
if (repo)
|
||||||
@ -152,9 +154,16 @@ static int do_push(const char *repo, int flags)
|
|||||||
setup_default_push_refspecs();
|
setup_default_push_refspecs();
|
||||||
}
|
}
|
||||||
errs = 0;
|
errs = 0;
|
||||||
for (i = 0; i < remote->url_nr; i++) {
|
if (remote->pushurl_nr) {
|
||||||
|
url = remote->pushurl;
|
||||||
|
url_nr = remote->pushurl_nr;
|
||||||
|
} else {
|
||||||
|
url = remote->url;
|
||||||
|
url_nr = remote->url_nr;
|
||||||
|
}
|
||||||
|
for (i = 0; i < url_nr; i++) {
|
||||||
struct transport *transport =
|
struct transport *transport =
|
||||||
transport_get(remote, remote->url[i]);
|
transport_get(remote, url[i]);
|
||||||
int err;
|
int err;
|
||||||
if (receivepack)
|
if (receivepack)
|
||||||
transport_set_option(transport,
|
transport_set_option(transport,
|
||||||
@ -163,14 +172,14 @@ static int do_push(const char *repo, int flags)
|
|||||||
transport_set_option(transport, TRANS_OPT_THIN, "yes");
|
transport_set_option(transport, TRANS_OPT_THIN, "yes");
|
||||||
|
|
||||||
if (flags & TRANSPORT_PUSH_VERBOSE)
|
if (flags & TRANSPORT_PUSH_VERBOSE)
|
||||||
fprintf(stderr, "Pushing to %s\n", remote->url[i]);
|
fprintf(stderr, "Pushing to %s\n", url[i]);
|
||||||
err = transport_push(transport, refspec_nr, refspec, flags);
|
err = transport_push(transport, refspec_nr, refspec, flags);
|
||||||
err |= transport_disconnect(transport);
|
err |= transport_disconnect(transport);
|
||||||
|
|
||||||
if (!err)
|
if (!err)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
error("failed to push some refs to '%s'", remote->url[i]);
|
error("failed to push some refs to '%s'", url[i]);
|
||||||
errs++;
|
errs++;
|
||||||
}
|
}
|
||||||
return !!errs;
|
return !!errs;
|
||||||
|
14
remote.c
14
remote.c
@ -106,6 +106,12 @@ static void add_url_alias(struct remote *remote, const char *url)
|
|||||||
add_url(remote, alias_url(url));
|
add_url(remote, alias_url(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void add_pushurl(struct remote *remote, const char *pushurl)
|
||||||
|
{
|
||||||
|
ALLOC_GROW(remote->pushurl, remote->pushurl_nr + 1, remote->pushurl_alloc);
|
||||||
|
remote->pushurl[remote->pushurl_nr++] = pushurl;
|
||||||
|
}
|
||||||
|
|
||||||
static struct remote *make_remote(const char *name, int len)
|
static struct remote *make_remote(const char *name, int len)
|
||||||
{
|
{
|
||||||
struct remote *ret;
|
struct remote *ret;
|
||||||
@ -379,6 +385,11 @@ static int handle_config(const char *key, const char *value, void *cb)
|
|||||||
if (git_config_string(&v, key, value))
|
if (git_config_string(&v, key, value))
|
||||||
return -1;
|
return -1;
|
||||||
add_url(remote, v);
|
add_url(remote, v);
|
||||||
|
} else if (!strcmp(subkey, ".pushurl")) {
|
||||||
|
const char *v;
|
||||||
|
if (git_config_string(&v, key, value))
|
||||||
|
return -1;
|
||||||
|
add_pushurl(remote, v);
|
||||||
} else if (!strcmp(subkey, ".push")) {
|
} else if (!strcmp(subkey, ".push")) {
|
||||||
const char *v;
|
const char *v;
|
||||||
if (git_config_string(&v, key, value))
|
if (git_config_string(&v, key, value))
|
||||||
@ -424,6 +435,9 @@ static void alias_all_urls(void)
|
|||||||
for (j = 0; j < remotes[i]->url_nr; j++) {
|
for (j = 0; j < remotes[i]->url_nr; j++) {
|
||||||
remotes[i]->url[j] = alias_url(remotes[i]->url[j]);
|
remotes[i]->url[j] = alias_url(remotes[i]->url[j]);
|
||||||
}
|
}
|
||||||
|
for (j = 0; j < remotes[i]->pushurl_nr; j++) {
|
||||||
|
remotes[i]->pushurl[j] = alias_url(remotes[i]->pushurl[j]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
remote.h
4
remote.h
@ -15,6 +15,10 @@ struct remote {
|
|||||||
int url_nr;
|
int url_nr;
|
||||||
int url_alloc;
|
int url_alloc;
|
||||||
|
|
||||||
|
const char **pushurl;
|
||||||
|
int pushurl_nr;
|
||||||
|
int pushurl_alloc;
|
||||||
|
|
||||||
const char **push_refspec;
|
const char **push_refspec;
|
||||||
struct refspec *push;
|
struct refspec *push;
|
||||||
int push_refspec_nr;
|
int push_refspec_nr;
|
||||||
|
Reference in New Issue
Block a user