clone: allow cloning local paths with colons in them

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>

Nguyễn Thái Ngọc Duy committed May 4, 2013 at 09:19 UTC 60003340cda05f5ecd79ee8522b21eda038b994b
4 files changed +18 -2
Documentation/urls.txt
+6
@@ -23,6 +23,12 @@ An alternative scp-like syntax may also be used with the ssh protocol:
23
24 - {startsb}user@{endsb}host.xz:path/to/repo.git/
25
26 +This syntax is only recognized if there are no slashes before the
27 +first colon. This helps differentiate a local path that contains a
28 +colon. For example the local path `foo:bar` could be specified as an
29 +absolute path or `./foo:bar` to avoid being misinterpreted as an ssh
30 +url.
31 +
32 The ssh and git protocols additionally support ~username expansion:
33
34 - ssh://{startsb}user@{endsb}host.xz{startsb}:port{endsb}/~{startsb}user{endsb}/path/to/repo.git/
builtin/clone.c
+2
@@ -724,6 +724,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
724 is_local = option_local != 0 && path && !is_bundle;
725 if (is_local && option_depth)
726 warning(_("--depth is ignored in local clones; use file:// instead."));
727 + if (option_local > 0 && !is_local)
728 + warning(_("--local is ignored"));
729
730 if (argc == 2)
731 dir = xstrdup(argv[1]);
connect.c
+5 -2
@@ -550,8 +550,11 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
550 path = strchr(end, c);
551 if (path && !has_dos_drive_prefix(end)) {
552 if (c == ':') {
553 - protocol = PROTO_SSH;
554 - *path++ = '\0';
553 + if (path < strchrnul(host, '/')) {
554 + protocol = PROTO_SSH;
555 + *path++ = '\0';
556 + } else /* '/' in the host part, assume local path */
557 + path = end;
558 }
559 } else
560 path = end;
t/t5601-clone.sh
+5
@@ -280,4 +280,9 @@ test_expect_success 'clone checking out a tag' '
280 test_cmp fetch.expected fetch.actual
281 '
282
283 +test_expect_success NOT_MINGW,NOT_CYGWIN 'clone local path foo:bar' '
284 + cp -R src "foo:bar" &&
285 + git clone "./foo:bar" foobar
286 +'
287 +
288 test_done