commit 6000334 (clone: allow cloning local paths with colons in them -
2013-05-04) is added to make it possible to specify a path that has
colons in it without file://, e.g. ../foo:bar/somewhere. But the check
is a bit loose.
Consider the url '[foo]:bar', the '[]' unwrapping code will turn the
string to 'foo\0:bar'. The effect of this new string is the same as
'foo/:bar' to the expression "path < strchrnul(host, '/')", which
mistakes it as a sign of local paths while it's actually not.
Make sure we only check so when no protocol is specified and the url
is not started with '['.
Noticed-by: Morten Stenshorne [off-list ref]
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
I wanted to add a test then realized there were no ssh tests in the
test suite. So laziness won :p
connect.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Jeff King <hidden> Date: 2016-06-15 22:58:55
On Fri, Sep 27, 2013 at 08:48:13PM +0700, Nguyen Thai Ngoc Duy wrote:
---
I wanted to add a test then realized there were no ssh tests in the
test suite. So laziness won :p
There is one in t5602, but it's not very reusable. How about squashing
in the patch below, which does a basic ssh-works test, and confirms your
fix?
---
@@ -280,9 +280,53 @@ test_expect_success NOT_MINGW,NOT_CYGWIN 'clone local path foo:bar' 'test_cmpfetch.expectedfetch.actual'+test_expect_success'setup ssh wrapper''+write_script"$TRASH_DIRECTORY/ssh-wrapper"<<-\EOF&&+echo>>"$TRASH_DIRECTORY/ssh-output""ssh: $*"&&+# throw away all but the last argument, which should be the+# command+whiletest$#-gt1;doshift;done+eval"$1"+EOF++GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper"&&+exportGIT_SSH&&+exportTRASH_DIRECTORY+'++clear_ssh(){+>"$TRASH_DIRECTORY/ssh-output"+}++expect_ssh(){+{+case"$1"in+none)+;;+*)+echo"ssh: $1 git-upload-pack '$2'"+esac+}>"$TRASH_DIRECTORY/ssh-expect"&&+(cd"$TRASH_DIRECTORY"&&test_cmpssh-expectssh-output)+}++test_expect_success'cloning myhost:src uses ssh''+clear_ssh&&+gitclonemyhost:srcssh-clone&&+expect_sshmyhostsrc+'+ test_expect_successNOT_MINGW,NOT_CYGWIN'clone local path foo:bar''+clear_ssh&&cp-Rsrc"foo:bar"&&-gitclone"./foo:bar"foobar+gitclone"./foo:bar"foobar&&+expect_sshnone+'++test_expect_success'bracketed hostnames are still ssh''+clear_ssh&&+gitclone"[myhost:123]:src"ssh-bracket-clone&&+expect_sshmyhost:123src' test_done
From: Jonathan Nieder <hidden> Date: 2016-06-15 22:58:55
Nguyễn Thái Ngọc Duy wrote:
commit 6000334 (clone: allow cloning local paths with colons in them -
2013-05-04) is added to make it possible to specify a path that has
colons in it without file://, e.g. ../foo:bar/somewhere. But the check
is a bit loose.
[...]
Make sure we only check so when no protocol is specified and the url
is not started with '['.
More precisely, this disables the "'/' before ':'" check when the
url has been mangled by '[]' unwrapping (which only happens if the
URL starts with '[' and contains an ']' at some point later).
If I try to clone "[foo]bar/baz:qux", after this change it will act as
though I specified the remote repository "foo:qux" instead of the local
repository "./foo:qux" as before this change. Both are wrong ---
that's a bug for another day.
Thanks, both.
commit 6000334 (clone: allow cloning local paths with colons in them -
2013-05-04) is added to make it possible to specify a path that has
colons in it without file://, e.g. ../foo:bar/somewhere. But the check
is a bit loose.
[...]
quoted
Make sure we only check so when no protocol is specified and the url
is not started with '['.
More precisely, this disables the "'/' before ':'" check when the
url has been mangled by '[]' unwrapping (which only happens if the
URL starts with '[' and contains an ']' at some point later).
If I try to clone "[foo]bar/baz:qux", after this change it will act as
though I specified the remote repository "foo:qux" instead of the local
repository "./foo:qux" as before this change. Both are wrong ---
that's a bug for another day.
(Loud thinking)
Could it make sense to disable the SSH autodection logic
whenever the url starts with '.' (like in "../XX.git")
or with "/" like in /home/USER/projects/XX.git ?