clone: do not use port number as dir name
[gitweb.git] / builtin / clone.c
index 6aa286fd7be6cc7e6de8194c4c37c84a474be6a2..c68eae13bfab940213e41064523baf24eb9fe642 100644 (file)
@@ -181,6 +181,23 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
                        end--;
        }
 
+       /*
+        * 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