diff options
author | Patrick Steinhardt <ps@pks.im> | 2015-08-10 17:48:24 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-08-10 11:02:07 -0700 |
commit | 92722efec01f67a54b68c83fcbc3cd65f9fbb7b8 (patch) | |
tree | eefdfc349caa9a30a962a1ef67f9586abc3fc688 /builtin | |
parent | clone: do not include authentication data in guessed dir (diff) | |
download | tgif-92722efec01f67a54b68c83fcbc3cd65f9fbb7b8.tar.xz |
clone: do not use port number as dir name
If the URI contains a port number and the URI's path component is
empty we fail to guess a sensible directory name. E.g. cloning a
repository 'ssh://example.com:2222/' we guess a directory name
'2222' where we would want the hostname only, e.g. 'example.com'.
We need to take care to not drop trailing port-like numbers in
certain cases. E.g. when cloning a repository 'foo/bar:2222.git'
we want to guess the directory name '2222' instead of 'bar'.
Thus, we have to first check the stripped URI for path separators
and only strip port numbers if there are path separators present.
This heuristic breaks when cloning a repository 'bar:2222.git',
though.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/clone.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/builtin/clone.c b/builtin/clone.c index 6aa286fd7b..c68eae13bf 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -182,6 +182,23 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare) } /* + * Strip trailing port number if we've got only a + * hostname (that is, there is no dir separator but a + * colon). This check is required such that we do not + * strip URI's like '/foo/bar:2222.git', which should + * result in a dir '2222' being guessed due to backwards + * compatibility. + */ + if (memchr(start, '/', end - start) == NULL + && memchr(start, ':', end - start) != NULL) { + ptr = end; + while (start < ptr && isdigit(ptr[-1]) && ptr[-1] != ':') + ptr--; + if (start < ptr && ptr[-1] == ':') + end = ptr - 1; + } + + /* * Find last component. To remain backwards compatible we * also regard colons as path separators, such that * cloning a repository 'foo:bar.git' would result in a |