Skip to content

Commit ffce821

Browse files
peffgitster
authored andcommitted
remote: always require at least one url in a remote
When we return a struct from remote_get(), the result _almost_ always has at least one url. In remotes_remote_get_1(), we do this: if (name_given && !valid_remote(ret)) add_url_alias(remote_state, ret, name); if (!valid_remote(ret)) return NULL; So if the remote doesn't have a url, we give it one based on the name (this is how unconfigured urls are used as remotes). And if that doesn't work, we return NULL. But there's a catch: valid_remote() checks that we have at least one url _unless_ the remote.*.vcs field is set. This comes from c578f51 (Add a config option for remotes to specify a foreign vcs, 2009-11-18), and the whole idea was to support remote helpers that don't have their own url. However, that mode has been broken since 25d5cc4 (Pass unknown protocols to external protocol handlers, 2009-12-09)! That commit unconditionally looks at the url in get_helper(), causing a segfault with something like: git -c remote.foo.vcs=bar fetch foo We could fix that now, of course. But given that it has been broken for almost 15 years and nobody noticed, there's a better option. This weird "there might not be a url" special case requires checks all over the code base, and it's not clear if there are other similar segfaults lurking. It would be nice if we could drop that special case. So instead, let's let the "the remote name is the url" code kick in. If you have "remote.foo.vcs", then your url (unless otherwise configured) is "foo". This does have a visible effect compared to what 25d5cc4 was trying to do. The idea back then is that for a remote without a url, we'd run: # only one command-line option! git-remote-bar foo whereas with our default url, now we'll run: git-remote-bar foo foo Again, in practice nobody can be relying on this because it has been segfaulting for 15 years. We should consider just removing this "vcs" config option entirely, but that would be a user-visible breakage. So by fixing it this way, we can keep things working that have been working, and simplify away one special case inside our code. This fixes the segfault from 25d5cc4 (demonstrated by the test), and we can build further cleanups on top. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7384e75 commit ffce821

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct counted_string {
3232

3333
static int valid_remote(const struct remote *remote)
3434
{
35-
return (!!remote->url.nr) || (!!remote->foreign_vcs);
35+
return !!remote->url.nr;
3636
}
3737

3838
static char *alias_url(const char *url, struct rewrites *r)

t/t5801-remote-helpers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test_expect_success 'fetch with configured remote.*.vcs' '
5353
test_grep remote-testgit vcs-fetch.trace
5454
'
5555

56-
test_expect_failure 'vcs remote with no url' '
56+
test_expect_success 'vcs remote with no url' '
5757
NOURL_UPSTREAM=$PWD/server &&
5858
export NOURL_UPSTREAM &&
5959
git init vcs-nourl &&

0 commit comments

Comments
 (0)