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>
Michael J Gruber committed
Jun 9, 2009 at 18:01 UTC
203462347fce0eab563fe77640648a7e8ae64d3b
5 files changed
+37
-4
Documentation/config.txt
+3
@@ -1319,6 +1319,9 @@ remote.<name>.url::
1319
The URL of a remote repository. See linkgit:git-fetch[1] or
1320
linkgit:git-push[1].
1321
1322
+remote.<name>.pushurl::
1323
+ The push URL of a remote repository. See linkgit:git-push[1].
1324
+
1325
remote.<name>.proxy::
1326
For remotes that require curl (http, https and ftp), the URL to
1327
the proxy to use for that remote. Set to the empty string to
Documentation/urls-remotes.txt
+3
@@ -27,10 +27,13 @@ config file would appear like this:
27
------------
28
[remote "<name>"]
29
url = <url>
30
+ pushurl = <pushurl>
31
push = <refspec>
32
fetch = <refspec>
33
------------
34
35
+The `<pushurl>` is used for pushes only. It is optional and defaults
36
+to `<url>`.
37
38
Named file in `$GIT_DIR/remotes`
39
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
builtin-push.c
+13
-4
@@ -117,6 +117,8 @@ static int do_push(const char *repo, int flags)
117
{
118
int i, errs;
119
struct remote *remote = remote_get(repo);
120
+ const char **url;
121
+ int url_nr;
122
123
if (!remote) {
124
if (repo)
@@ -152,9 +154,16 @@ static int do_push(const char *repo, int flags)
154
setup_default_push_refspecs();
155
}
156
errs = 0;
155
- for (i = 0; i < remote->url_nr; i++) {
157
+ if (remote->pushurl_nr) {
158
+ url = remote->pushurl;
159
+ url_nr = remote->pushurl_nr;
160
+ } else {
161
+ url = remote->url;
162
+ url_nr = remote->url_nr;
163
+ }
164
+ for (i = 0; i < url_nr; i++) {
165
struct transport *transport =
157
- transport_get(remote, remote->url[i]);
166
+ transport_get(remote, url[i]);
167
int err;
168
if (receivepack)
169
transport_set_option(transport,
@@ -163,14 +172,14 @@ static int do_push(const char *repo, int flags)
172
transport_set_option(transport, TRANS_OPT_THIN, "yes");
173
174
if (flags & TRANSPORT_PUSH_VERBOSE)
166
- fprintf(stderr, "Pushing to %s\n", remote->url[i]);
175
+ fprintf(stderr, "Pushing to %s\n", url[i]);
176
err = transport_push(transport, refspec_nr, refspec, flags);
177
err |= transport_disconnect(transport);
178
179
if (!err)
180
continue;
181
173
- error("failed to push some refs to '%s'", remote->url[i]);
182
+ error("failed to push some refs to '%s'", url[i]);
183
errs++;
184
}
185
return !!errs;
remote.c
+14
@@ -106,6 +106,12 @@ static void add_url_alias(struct remote *remote, const char *url)
106
add_url(remote, alias_url(url));
107
}
108
109
+static void add_pushurl(struct remote *remote, const char *pushurl)
110
+{
111
+ ALLOC_GROW(remote->pushurl, remote->pushurl_nr + 1, remote->pushurl_alloc);
112
+ remote->pushurl[remote->pushurl_nr++] = pushurl;
113
+}
114
+
115
static struct remote *make_remote(const char *name, int len)
116
{
117
struct remote *ret;
@@ -379,6 +385,11 @@ static int handle_config(const char *key, const char *value, void *cb)
385
if (git_config_string(&v, key, value))
386
return -1;
387
add_url(remote, v);
388
+ } else if (!strcmp(subkey, ".pushurl")) {
389
+ const char *v;
390
+ if (git_config_string(&v, key, value))
391
+ return -1;
392
+ add_pushurl(remote, v);
393
} else if (!strcmp(subkey, ".push")) {
394
const char *v;
395
if (git_config_string(&v, key, value))
@@ -424,6 +435,9 @@ static void alias_all_urls(void)
435
for (j = 0; j < remotes[i]->url_nr; j++) {
436
remotes[i]->url[j] = alias_url(remotes[i]->url[j]);
437
}
438
+ for (j = 0; j < remotes[i]->pushurl_nr; j++) {
439
+ remotes[i]->pushurl[j] = alias_url(remotes[i]->pushurl[j]);
440
+ }
441
}
442
}
443
remote.h
+4
@@ -15,6 +15,10 @@ struct remote {
15
int url_nr;
16
int url_alloc;
17
18
+ const char **pushurl;
19
+ int pushurl_nr;
20
+ int pushurl_alloc;
21
+
22
const char **push_refspec;
23
struct refspec *push;
24
int push_refspec_nr;