clone: allow cloning local paths with colons in them
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 4 May 2013 02:19:33 +0000 (09:19 +0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 May 2013 15:32:14 +0000 (08:32 -0700)
Usually "foo:bar" is interpreted as an ssh url. This patch allows to
clone from such paths by putting at least one slash before the colon
(i.e. /path/to/foo:bar or just ./foo:bar).

file://foo:bar should also work, but local optimizations are off in
that case, which may be unwanted. While at there, warn the users about
--local being ignored in this case.

Reported-by: William Giokas <1007380@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/urls.txt
builtin/clone.c
connect.c
t/t5601-clone.sh
index 3ca122faedd01cfbd61bf07dbc245b04f40f2b23..476e3381c5d40725910bee7fd9d35e7b007ac253 100644 (file)
@@ -23,6 +23,12 @@ An alternative scp-like syntax may also be used with the ssh protocol:
 
 - {startsb}user@{endsb}host.xz:path/to/repo.git/
 
+This syntax is only recognized if there are no slashes before the
+first colon. This helps differentiate a local path that contains a
+colon. For example the local path `foo:bar` could be specified as an
+absolute path or `./foo:bar` to avoid being misinterpreted as an ssh
+url.
+
 The ssh and git protocols additionally support ~username expansion:
 
 - ssh://{startsb}user@{endsb}host.xz{startsb}:port{endsb}/~{startsb}user{endsb}/path/to/repo.git/
index e0aaf13583376c7adf49f504cc9e7e1303fb4a4d..a4d444a94b0166a0cd672b51ba4f2374b5d0038f 100644 (file)
@@ -724,6 +724,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        is_local = option_local != 0 && path && !is_bundle;
        if (is_local && option_depth)
                warning(_("--depth is ignored in local clones; use file:// instead."));
+       if (option_local > 0 && !is_local)
+               warning(_("--local is ignored"));
 
        if (argc == 2)
                dir = xstrdup(argv[1]);
index 49e56ba35a645359b0d7c1f7bbc9e2108b3424d9..715a309d2152b5d8ba5624b38657a714adaf67b5 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -550,8 +550,11 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
        path = strchr(end, c);
        if (path && !has_dos_drive_prefix(end)) {
                if (c == ':') {
-                       protocol = PROTO_SSH;
-                       *path++ = '\0';
+                       if (path < strchrnul(host, '/')) {
+                               protocol = PROTO_SSH;
+                               *path++ = '\0';
+                       } else /* '/' in the host part, assume local path */
+                               path = end;
                }
        } else
                path = end;
index 67869b4813dd354f4376ead1470ecb0e58929302..0629149eddcff4e6e724ab82479504deda141141 100755 (executable)
@@ -280,4 +280,9 @@ test_expect_success 'clone checking out a tag' '
        test_cmp fetch.expected fetch.actual
 '
 
+test_expect_success NOT_MINGW,NOT_CYGWIN 'clone local path foo:bar' '
+       cp -R src "foo:bar" &&
+       git clone "./foo:bar" foobar
+'
+
 test_done