git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] clone: local URLs are not for ssh

From
Torsten Bögershausen <tboegi@web.de>
Date
Oct 13, 2013, 20:00 UTC
Message-ID
<525AFBCC.4080303@web.de>
In-Reply-To
<52506D15.9040206@web.de>
On 05.10.13 21:48, Torsten Bögershausen wrote:
> On 2013-10-03 03.31, Jeff King wrote:
>>
>>   http://article.gmane.org/gmane.comp.version-control.git/235473
What do we think about extending the test a little bit:
git diff 771cf1dab9303bab3c8198b8b6 -- t5602-clone-remote-exec.sh 
diff --git a/t/t5602-clone-remote-exec.sh b/t/t5602-clone-remote-exec.sh
index 3f353d9..790896f 100755
--- a/t/t5602-clone-remote-exec.sh
+++ b/t/t5602-clone-remote-exec.sh
@@ -30,5 +30,124 @@ test_expect_success 'clone calls specified git upload-pack with -u option' '
 	echo "localhost ./something/bin/git-upload-pack '\''/path/to/repo'\''" >expected &&
 	test_cmp expected not_ssh_output
 '
+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
+	while test $# -gt 1; do shift; done
+	eval "$1"
+	EOF
+
+	GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
+	export GIT_SSH &&
+	export TRASH_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_cmp ssh-expect ssh-output)
+}
+
+test_expect_success 'create src.git' '
+	mkdir src.git &&
+	( 
+		cd src.git &&
+		git init &&
+		>file &&
+		git add file &&
+		git commit -m "add file"
+	)
+'
+
+# git clone could fail, so break the && chain and ignore the exit code
+# clone local
+test_expect_success './foo:bar is not ssh' '
+	clear_ssh &&
+	git clone "./foo:bar" foobar
+	expect_ssh none
+'
+
+test_expect_success './[nohost:123]:src is not ssh' '
+	clear_ssh &&
+	git clone "./[nohost:123]:src" 1_2_3
+	expect_ssh none
+'
+
+test_expect_success '[nohost:234] is not ssh' '
+	clear_ssh &&
+	git clone "[nohost:234]" 2_3_4
+	expect_ssh none
+'
+
+test_expect_success ':345 is not ssh' '
+	clear_ssh &&
+	git clone ":345" 3_4_5 
+	expect_ssh none
+'
+
+test_expect_success '456: is not ssh' '
+	clear_ssh &&
+	git clone "456:" 4_5_6 
+	expect_ssh none
+'
+
+# clone via ssh
+# the expect_ssh checks that git clone tried to use ssh
+test_expect_success 'myhost:567 is ssh' '
+	clear_ssh &&
+	git clone myhost:567 myhost_567
+	expect_ssh myhost 567
+'
+
+test_expect_success '[myhost:678]:src is ssh' '
+	clear_ssh &&
+	git clone "[myhost:678]:src" myhost_678
+	expect_ssh myhost:678 src
+'
+
+#clone url looks like ssh, but is on disk
+test_expect_success SYMLINKS 'dir:123 on disk' '
+	clear_ssh &&
+	ln -s src.git dir:123 &&
+	git clone dir:123 dir_123 &&
+	expect_ssh none
+'
+
+test_expect_success SYMLINKS '[dir:234]:src on disk' '
+	clear_ssh &&
+	ln -s src.git [dir:234]:src &&
+	git clone [dir:234]:src dir_234_src &&
+	expect_ssh none
+'
+
+test_expect_success 'ssh://host.xz/~user/repo' '
+	clear_ssh &&
+	git clone "ssh://host.xz/~user/repo" user-repo
+	expect_ssh host.xz "~user/repo"
+'
+
+test_expect_success 'ssh://host.xz:22/~user/repo' '
+	clear_ssh &&
+	git clone "ssh://host.xz:22/~user/repo" user-repo
+	expect_ssh "-p 22 host.xz" "~user/repo"
+'
+
+test_expect_success 'ssh://[::1]:22/~user/repo' '
+	clear_ssh &&
+	git clone "ssh://[::1]:22/~user/repo" user-repo6
+	expect_ssh "-p 22 ::1" "~user/repo"
+'
 
 test_done

==============
And we need this on top of Duys patch:

diff --git a/connect.c b/connect.c
index e8473f3..09be2b3 100644
--- a/connect.c
+++ b/connect.c
@@ -611,7 +611,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
                end = host;
 
        path = strchr(end, c);
-       if (path && !has_dos_drive_prefix(end)) {
+       if (path && host != path && !has_dos_drive_prefix(end)) {
                if (c == ':') {
       if (host != url || path < strchrnul(host, '/')) {
                                protocol = PROTO_SSH;
Previous: Matthieu MoyNext: Jeff King
Message 8 of 10 in “clone: local URLs are not for ssh”
  1. clone: local URLs are not for sshTorsten Bögershausen, Sep 28, 2013
  2. Duy NguyenSep 29, 2013
  3. Torsten BögershausenOct 2, 2013
  4. Duy NguyenOct 3, 2013
  5. Jeff KingOct 3, 2013
  6. Torsten BögershausenOct 5, 2013
  7. Matthieu MoyOct 5, 2013
  8. Torsten BögershausenOct 13, 2013
  9. Jeff KingOct 15, 2013
  10. Torsten BögershausenOct 15, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.