t5601: remove clear_ssh, refactor setup_ssh_wrapper
[gitweb.git] / t / t5601-clone.sh
index f8e5a9a4ae1051216e4ef55c8a46c99686e45b5c..c634f776d727f00b73f8f772847ab3a257352c03 100755 (executable)
@@ -280,9 +280,53 @@ test_expect_success 'clone checking out a tag' '
        test_cmp fetch.expected fetch.actual
 '
 
+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)
+                       ;;
+               *)
+                       echo "ssh: $1 git-upload-pack '$2'"
+               esac
+       } >"$TRASH_DIRECTORY/ssh-expect" &&
+       (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
+}
+
+setup_ssh_wrapper
+
+test_expect_success 'cloning myhost:src uses ssh' '
+       git clone myhost:src ssh-clone &&
+       expect_ssh myhost src
+'
+
 test_expect_success NOT_MINGW,NOT_CYGWIN 'clone local path foo:bar' '
        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' '
+       git clone "[myhost:123]:src" ssh-bracket-clone &&
+       expect_ssh myhost:123 src
 '
 
 test_expect_success 'clone from a repository with two identical branches' '