Skip to content

Commit cabb411

Browse files
committed
Merge branch 'nd/clone-local-with-colon'
* nd/clone-local-with-colon: clone: tighten "local paths with colons" check a bit
2 parents 13f17f3 + 8d3d28f commit cabb411

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

connect.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
552552
path = strchr(end, c);
553553
if (path && !has_dos_drive_prefix(end)) {
554554
if (c == ':') {
555-
if (path < strchrnul(host, '/')) {
555+
if (host != url || path < strchrnul(host, '/')) {
556556
protocol = PROTO_SSH;
557557
*path++ = '\0';
558558
} else /* '/' in the host part, assume local path */

t/t5601-clone.sh

+45-1
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,53 @@ test_expect_success 'clone checking out a tag' '
280280
test_cmp fetch.expected fetch.actual
281281
'
282282

283+
test_expect_success 'setup ssh wrapper' '
284+
write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF &&
285+
echo >>"$TRASH_DIRECTORY/ssh-output" "ssh: $*" &&
286+
# throw away all but the last argument, which should be the
287+
# command
288+
while test $# -gt 1; do shift; done
289+
eval "$1"
290+
EOF
291+
292+
GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
293+
export GIT_SSH &&
294+
export TRASH_DIRECTORY
295+
'
296+
297+
clear_ssh () {
298+
>"$TRASH_DIRECTORY/ssh-output"
299+
}
300+
301+
expect_ssh () {
302+
{
303+
case "$1" in
304+
none)
305+
;;
306+
*)
307+
echo "ssh: $1 git-upload-pack '$2'"
308+
esac
309+
} >"$TRASH_DIRECTORY/ssh-expect" &&
310+
(cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
311+
}
312+
313+
test_expect_success 'cloning myhost:src uses ssh' '
314+
clear_ssh &&
315+
git clone myhost:src ssh-clone &&
316+
expect_ssh myhost src
317+
'
318+
283319
test_expect_success NOT_MINGW,NOT_CYGWIN 'clone local path foo:bar' '
320+
clear_ssh &&
284321
cp -R src "foo:bar" &&
285-
git clone "./foo:bar" foobar
322+
git clone "./foo:bar" foobar &&
323+
expect_ssh none
324+
'
325+
326+
test_expect_success 'bracketed hostnames are still ssh' '
327+
clear_ssh &&
328+
git clone "[myhost:123]:src" ssh-bracket-clone &&
329+
expect_ssh myhost:123 src
286330
'
287331

288332
test_done

0 commit comments

Comments
 (0)