From: Patrick Steinhardt Date: Mon, 27 Jul 2015 11:48:28 GMT Subject: [PATCH] clone: fix repo name when cloning a server's root Message-ID: <1437997708-10732-1-git-send-email-ps@pks.im> When cloning a repository from a server's root, that is the URL's path component is a '/' only, we fail to generate a sensible repository name when the URL contains authentication data. This is especially bad when cloning URLs like 'ssh://user:passwd@example.com/', which results in a repository 'passwd@example.com' being created. Improve the behavior by also regarding '@'-signs as a separator when scanning the URL. In the mentioned case this would instead result in a directory 'example.com' being created. Signed-off-by: Patrick Steinhardt --- I was not able to come by with a useful test as that would require being able to clone a root directory. I couldn't find anything in the current tests that looks like what I want to do. Does anybody have an idea on how to achieve this? builtin/clone.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index a72ff7e..aaf38b2 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -164,11 +164,13 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare) /* * Find last component, but be prepared that repo could have - * the form "remote.example.com:foo.git", i.e. no slash - * in the directory part. + * the form "remote.example.com:foo.git", i.e. no slash in + * the directory part, or "user:password@remote.example.com/", + * that is the path component may be empty. */ start = end; - while (repo < start && !is_dir_sep(start[-1]) && start[-1] != ':') + while (repo < start && !is_dir_sep(start[-1]) && start[-1] != ':' + && start[-1] != '@') start--; /* -- 2.4.6