Require a struct remote in transport_get()
cmd_ls_remote() was calling transport_get() with a NULL remote and a non-NULL url in the case where it was run outside a git repository. This involved a bunch of ill-tested special cases. Instead, simply get the struct remote for the URL with remote_get(), which works fine outside a git repository, and can also take global options into account. This fixes a tiny and obscure bug where "git ls-remote" without a repo didn't support global url.*.insteadOf, even though "git clone" and "git ls-remote" in any repo did. Also, enforce that all callers provide a struct remote to transport_get(). Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Daniel Barkalow committed
Nov 3, 2009 at 21:38 UTC
c1d45cf7b0c1953eed72a3018b5e557dbcd538e0
2 files changed
+8
-5
builtin-ls-remote.c
+3
-3
@@ -86,10 +86,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
86
pattern[j - i] = p;
87
}
88
}
89
- remote = nongit ? NULL : remote_get(dest);
90
- if (remote && !remote->url_nr)
89
+ remote = remote_get(dest);
90
+ if (!remote->url_nr)
91
die("remote %s has no configured URL", dest);
92
- transport = transport_get(remote, remote ? remote->url[0] : dest);
92
+ transport = transport_get(remote, remote->url[0]);
93
if (uploadpack != NULL)
94
transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
95
transport.c
+5
-2
@@ -812,6 +812,9 @@ struct transport *transport_get(struct remote *remote, const char *url)
812
{
813
struct transport *ret = xcalloc(1, sizeof(*ret));
814
815
+ if (!remote)
816
+ die("No remote provided to transport_get()");
817
+
818
ret->remote = remote;
819
ret->url = url;
820
@@ -849,10 +852,10 @@ struct transport *transport_get(struct remote *remote, const char *url)
852
data->thin = 1;
853
data->conn = NULL;
854
data->uploadpack = "git-upload-pack";
852
- if (remote && remote->uploadpack)
855
+ if (remote->uploadpack)
856
data->uploadpack = remote->uploadpack;
857
data->receivepack = "git-receive-pack";
855
- if (remote && remote->receivepack)
858
+ if (remote->receivepack)
859
data->receivepack = remote->receivepack;
860
}
861