Skip to content

Commit 41aaccd

Browse files
committed
Merge branch 'nd/clone-local-with-colon'
"git clone foo/bar:baz" cannot be a request to clone from a remote over git-over-ssh specified in the scp style. Detect this case and clone from a local repository at "foo/bar:baz". * nd/clone-local-with-colon: clone: allow cloning local paths with colons in them
2 parents dbbc93b + 6000334 commit 41aaccd

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

Documentation/urls.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ An alternative scp-like syntax may also be used with the ssh protocol:
2323

2424
- {startsb}user@{endsb}host.xz:path/to/repo.git/
2525

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+
2632
The ssh and git protocols additionally support ~username expansion:
2733

2834
- ssh://{startsb}user@{endsb}host.xz{startsb}:port{endsb}/~{startsb}user{endsb}/path/to/repo.git/

builtin/clone.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
782782
is_local = option_local != 0 && path && !is_bundle;
783783
if (is_local && option_depth)
784784
warning(_("--depth is ignored in local clones; use file:// instead."));
785+
if (option_local > 0 && !is_local)
786+
warning(_("--local is ignored"));
785787

786788
if (argc == 2)
787789
dir = xstrdup(argv[1]);

connect.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,11 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
551551
path = strchr(end, c);
552552
if (path && !has_dos_drive_prefix(end)) {
553553
if (c == ':') {
554-
protocol = PROTO_SSH;
555-
*path++ = '\0';
554+
if (path < strchrnul(host, '/')) {
555+
protocol = PROTO_SSH;
556+
*path++ = '\0';
557+
} else /* '/' in the host part, assume local path */
558+
path = end;
556559
}
557560
} else
558561
path = end;

t/t5601-clone.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,9 @@ test_expect_success 'clone checking out a tag' '
280280
test_cmp fetch.expected fetch.actual
281281
'
282282

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+
283288
test_done

0 commit comments

Comments
 (0)