From 710eb3e22cfe5fb84f41a3ef1d3a91b5cf5d3463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Thu, 28 Nov 2013 20:53:47 +0100 Subject: t5601: remove clear_ssh, refactor setup_ssh_wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 8d3d28f5 added test cases for URLs which should be ssh. Remove the function clear_ssh, use test_when_finished to clean up. Introduce the function setup_ssh_wrapper, which could be factored out together with expect_ssh. Tighten one test and use "foo:bar" instead of "./foo:bar", Helped-by: Jeff King Signed-off-by: Torsten Bögershausen Signed-off-by: Junio C Hamano --- t/t5601-clone.sh | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 't') diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 1d1c8755ea..c634f776d7 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -280,25 +280,26 @@ test_expect_success 'clone checking out a tag' ' test_cmp fetch.expected fetch.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 - 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" +setup_ssh_wrapper () { + 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 && + >"$TRASH_DIRECTORY"/ssh-output + ' } expect_ssh () { + test_when_finished ' + (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output) + ' && { case "$1" in none) @@ -310,21 +311,20 @@ expect_ssh () { (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output) } +setup_ssh_wrapper + test_expect_success 'cloning myhost:src uses ssh' ' - clear_ssh && git clone myhost:src ssh-clone && expect_ssh myhost src ' test_expect_success NOT_MINGW,NOT_CYGWIN 'clone local path foo:bar' ' - clear_ssh && cp -R src "foo:bar" && - git clone "./foo:bar" foobar && + git clone "foo:bar" foobar && expect_ssh none ' test_expect_success 'bracketed hostnames are still ssh' ' - clear_ssh && git clone "[myhost:123]:src" ssh-bracket-clone && expect_ssh myhost:123 src ' -- cgit v1.2.3 From 2171f3d2aa1412a744545c07b28003a7ff4af5df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Thu, 28 Nov 2013 20:48:22 +0100 Subject: t5601: add tests for ssh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add more tests testing all the combinations: -IPv4 or IPv6 -path starting with "/" or with "/~" -with and without the ssh:// scheme Some tests fail; they need updates in connect.c Signed-off-by: Torsten Bögershausen Signed-off-by: Junio C Hamano --- t/t5601-clone.sh | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index c634f776d7..ba99972d88 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -313,7 +313,7 @@ expect_ssh () { setup_ssh_wrapper -test_expect_success 'cloning myhost:src uses ssh' ' +test_expect_success 'clone myhost:src uses ssh' ' git clone myhost:src ssh-clone && expect_ssh myhost src ' @@ -329,6 +329,104 @@ test_expect_success 'bracketed hostnames are still ssh' ' expect_ssh myhost:123 src ' +counter=0 +# $1 url +# $2 none|host +# $3 path +test_clone_url () { + counter=$(($counter + 1)) + test_might_fail git clone "$1" tmp$counter && + expect_ssh "$2" "$3" +} + +test_expect_success NOT_MINGW 'clone c:temp is ssl' ' + test_clone_url c:temp c temp +' + +test_expect_success MINGW 'clone c:temp is dos drive' ' + test_clone_url c:temp none +' + +#ip v4 +for repo in rep rep/home/project /~proj 123 +do + test_expect_success "clone host:$repo" ' + test_clone_url host:$repo host $repo + ' +done + +#ipv6 +# failing +for repo in /~proj +do + test_expect_failure "clone [::1]:$repo" ' + test_clone_url [::1]:$repo ::1 $repo + ' +done + +for repo in rep rep/home/project 123 +do + test_expect_success "clone [::1]:$repo" ' + test_clone_url [::1]:$repo ::1 $repo + ' +done + +# Corner cases +# failing +for repo in [foo]bar/baz:qux [foo/bar]:baz +do + test_expect_failure "clone $url is not ssh" ' + test_clone_url $url none + ' +done + +for url in foo/bar:baz +do + test_expect_success "clone $url is not ssh" ' + test_clone_url $url none + ' +done + +#with ssh:// scheme +test_expect_success 'clone ssh://host.xz/home/user/repo' ' + test_clone_url "ssh://host.xz/home/user/repo" host.xz "/home/user/repo" +' + +# from home directory +test_expect_success 'clone ssh://host.xz/~repo' ' + test_clone_url "ssh://host.xz/~repo" host.xz "~repo" +' + +# with port number +test_expect_success 'clone ssh://host.xz:22/home/user/repo' ' + test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo" +' + +# from home directory with port number +test_expect_success 'clone ssh://host.xz:22/~repo' ' + test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo" +' + +#IPv6 +test_expect_success 'clone ssh://[::1]/home/user/repo' ' + test_clone_url "ssh://[::1]/home/user/repo" "::1" "/home/user/repo" +' + +#IPv6 from home directory +test_expect_success 'clone ssh://[::1]/~repo' ' + test_clone_url "ssh://[::1]/~repo" "::1" "~repo" +' + +#IPv6 with port number +test_expect_success 'clone ssh://[::1]:22/home/user/repo' ' + test_clone_url "ssh://[::1]:22/home/user/repo" "-p 22 ::1" "/home/user/repo" +' + +#IPv6 from home directory with port number +test_expect_success 'clone ssh://[::1]:22/~repo' ' + test_clone_url "ssh://[::1]:22/~repo" "-p 22 ::1" "~repo" +' + test_expect_success 'clone from a repository with two identical branches' ' ( -- cgit v1.2.3 From 854aeb7beb85a7a3f05fc11daea7c8d2fed3a22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Thu, 28 Nov 2013 20:49:29 +0100 Subject: t5500: add test cases for diag-url MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add test cases using git fetch-pack --diag-url: - parse out host and path for URLs with a scheme (git:// file:// ssh://) - parse host names embedded by [] correctly - extract the port number, if present - separate URLs like "file" (which are local) from URLs like "host:repo" which should use ssh Signed-off-by: Torsten Bögershausen Signed-off-by: Junio C Hamano --- t/t5500-fetch-pack.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 't') diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index d87ddf73b7..545dd7b8e1 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -531,5 +531,64 @@ test_expect_success 'shallow fetch with tags does not break the repository' ' git fsck ) ' +check_prot_path () { + cat >expected <<-EOF && + Diag: url=$1 + Diag: protocol=$2 + Diag: path=$3 + EOF + git fetch-pack --diag-url "$1" | grep -v hostandport= >actual && + test_cmp expected actual +} + +check_prot_host_path () { + cat >expected <<-EOF && + Diag: url=$1 + Diag: protocol=$2 + Diag: hostandport=$3 + Diag: path=$4 + EOF + git fetch-pack --diag-url "$1" >actual && + test_cmp expected actual +} + +for r in repo re:po re/po +do + # git or ssh with scheme + for p in "ssh+git" "git+ssh" git ssh + do + for h in host host:12 [::1] [::1]:23 + do + case "$p" in + *ssh*) + hh=$(echo $h | tr -d "[]") + pp=ssh + ;; + *) + hh=$h + pp=$p + ;; + esac + test_expect_success "fetch-pack --diag-url $p://$h/$r" ' + check_prot_host_path $p://$h/$r $pp "$hh" "/$r" + ' + # "/~" -> "~" conversion + test_expect_success "fetch-pack --diag-url $p://$h/~$r" ' + check_prot_host_path $p://$h/~$r $pp "$hh" "~$r" + ' + done + done + # file with scheme + for p in file + do + test_expect_success "fetch-pack --diag-url $p://$h/$r" ' + check_prot_path $p://$h/$r $p "/$r" + ' + # No "/~" -> "~" conversion for file + test_expect_success "fetch-pack --diag-url $p://$h/~$r" ' + check_prot_path $p://$h/~$r $p "/~$r" + ' + done +done test_done -- cgit v1.2.3 From 6a59974869c0a6e9399101bc02223b4c00a8aff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Thu, 28 Nov 2013 20:49:38 +0100 Subject: git fetch: support host:/~repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The documentation (in urls.txt) says that "ssh://host:/~repo", "host:/~repo" or "host:~repo" specify the repository "repo" in the home directory at "host". This has not been working for "host:/~repo". Before commit 356bec "Support [address] in URLs", the comparison "url != hostname" could be used to determine if the URL had a scheme or not: "ssh://host/host" != "host". However, after 356bec "[::1]" was converted into "::1", yielding url != hostname as well. To fix this regression, don't use "if (url != hostname)", but look at the separator instead. Rename the variable "c" into "separator" to make it easier to read. Signed-off-by: Torsten Bögershausen Signed-off-by: Junio C Hamano --- t/t5500-fetch-pack.sh | 24 ++++++++++++++++++++++++ t/t5601-clone.sh | 12 ++---------- 2 files changed, 26 insertions(+), 10 deletions(-) (limited to 't') diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index 545dd7b8e1..df5baf8d6f 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -589,6 +589,30 @@ do check_prot_path $p://$h/~$r $p "/~$r" ' done + # file without scheme + for h in nohost nohost:12 [::1] [::1]:23 [ [:aa + do + test_expect_success "fetch-pack --diag-url ./$h:$r" ' + check_prot_path ./$h:$r $p "./$h:$r" + ' + # No "/~" -> "~" conversion for file + test_expect_success "fetch-pack --diag-url ./$p:$h/~$r" ' + check_prot_path ./$p:$h/~$r $p "./$p:$h/~$r" + ' + done + #ssh without scheme + p=ssh + for h in host [::1] + do + hh=$(echo $h | tr -d "[]") + test_expect_success "fetch-pack --diag-url $h:$r" ' + check_prot_path $h:$r $p "$r" + ' + # Do "/~" -> "~" conversion + test_expect_success "fetch-pack --diag-url $h:/~$r" ' + check_prot_host_path $h:/~$r $p "$hh" "~$r" + ' + done done test_done diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index ba99972d88..4db0c0b01e 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -348,7 +348,7 @@ test_expect_success MINGW 'clone c:temp is dos drive' ' ' #ip v4 -for repo in rep rep/home/project /~proj 123 +for repo in rep rep/home/project 123 do test_expect_success "clone host:$repo" ' test_clone_url host:$repo host $repo @@ -356,14 +356,6 @@ do done #ipv6 -# failing -for repo in /~proj -do - test_expect_failure "clone [::1]:$repo" ' - test_clone_url [::1]:$repo ::1 $repo - ' -done - for repo in rep rep/home/project 123 do test_expect_success "clone [::1]:$repo" ' @@ -373,7 +365,7 @@ done # Corner cases # failing -for repo in [foo]bar/baz:qux [foo/bar]:baz +for url in [foo]bar/baz:qux [foo/bar]:baz do test_expect_failure "clone $url is not ssh" ' test_clone_url $url none -- cgit v1.2.3 From 83b058752707a6ba4af51ebc98c47913bc7d2d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Thu, 28 Nov 2013 20:49:54 +0100 Subject: git_connect(): refactor the port handling for ssh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use get_host_and_port() even for ssh. Remove the variable port git_connect(), and simplify parse_connect_url() Use only one return point in git_connect(), doing the free() and return conn. t5601 had 2 corner test cases which now pass. Signed-off-by: Torsten Bögershausen Signed-off-by: Junio C Hamano --- t/t5500-fetch-pack.sh | 9 +++------ t/t5601-clone.sh | 10 +--------- 2 files changed, 4 insertions(+), 15 deletions(-) (limited to 't') diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index df5baf8d6f..b4866ea3a3 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -561,20 +561,18 @@ do do case "$p" in *ssh*) - hh=$(echo $h | tr -d "[]") pp=ssh ;; *) - hh=$h pp=$p ;; esac test_expect_success "fetch-pack --diag-url $p://$h/$r" ' - check_prot_host_path $p://$h/$r $pp "$hh" "/$r" + check_prot_host_path $p://$h/$r $pp "$h" "/$r" ' # "/~" -> "~" conversion test_expect_success "fetch-pack --diag-url $p://$h/~$r" ' - check_prot_host_path $p://$h/~$r $pp "$hh" "~$r" + check_prot_host_path $p://$h/~$r $pp "$h" "~$r" ' done done @@ -604,13 +602,12 @@ do p=ssh for h in host [::1] do - hh=$(echo $h | tr -d "[]") test_expect_success "fetch-pack --diag-url $h:$r" ' check_prot_path $h:$r $p "$r" ' # Do "/~" -> "~" conversion test_expect_success "fetch-pack --diag-url $h:/~$r" ' - check_prot_host_path $h:/~$r $p "$hh" "~$r" + check_prot_host_path $h:/~$r $p "$h" "~$r" ' done done diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 4db0c0b01e..53a1de9efd 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -364,15 +364,7 @@ do done # Corner cases -# failing -for url in [foo]bar/baz:qux [foo/bar]:baz -do - test_expect_failure "clone $url is not ssh" ' - test_clone_url $url none - ' -done - -for url in foo/bar:baz +for url in foo/bar:baz [foo]bar/baz:qux [foo/bar]:baz do test_expect_success "clone $url is not ssh" ' test_clone_url $url none -- cgit v1.2.3 From c59ab2e52a64abd7fded97e0983a9b7f3d0508a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Thu, 28 Nov 2013 20:50:03 +0100 Subject: connect.c: refactor url parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the function is_local() in transport.c public, rename it into url_is_local_not_ssh() and use it in both transport.c and connect.c Use a protocol "local" for URLs for the local file system. One note about using file:// under Windows: The (absolute) path on Unix like system typically starts with "/". When the host is empty, it can be omitted, so that a shell scriptlet url=file://$pwd will give a URL like "file:///home/user/repo". Windows does not have the same concept of a root directory located in "/". When parsing the URL allow "file://C:/user/repo" (even if RFC1738 indicates that "file:///C:/user/repo" should be used). Signed-off-by: Torsten Bögershausen Signed-off-by: Junio C Hamano --- t/t5500-fetch-pack.sh | 7 +++++++ t/t5601-clone.sh | 8 ++++++++ 2 files changed, 15 insertions(+) (limited to 't') diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index b4866ea3a3..5b2b1c2c13 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -612,4 +612,11 @@ do done done +test_expect_success MINGW 'fetch-pack --diag-url file://c:/repo' ' + check_prot_path file://c:/repo file c:/repo +' +test_expect_success MINGW 'fetch-pack --diag-url c:repo' ' + check_prot_path c:repo file c:repo +' + test_done diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 53a1de9efd..62fbd7e664 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -362,6 +362,14 @@ do test_clone_url [::1]:$repo ::1 $repo ' done +#home directory +test_expect_success "clone host:/~repo" ' + test_clone_url host:/~repo host "~repo" +' + +test_expect_success "clone [::1]:/~repo" ' + test_clone_url [::1]:/~repo ::1 "~repo" +' # Corner cases for url in foo/bar:baz [foo]bar/baz:qux [foo/bar]:baz -- cgit v1.2.3