[PATCH] clone: fix repo name when cloning a server's root

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx/', which results in a repository
'passwd@xxxxxxxxxxx' 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 <ps@xxxxxx>
---
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@xxxxxxxxxxxxxxxxxx/",
+	 * 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]