Merge branch 'sb/ref-lock-lose-lock-fd'
[gitweb.git] / t / t5601-clone.sh
index e4f10c0f68b94bfa719c3d208f622541506c86b3..bfdaf75966f7b8bb057e4db0b8791306f6e6a44f 100755 (executable)
@@ -296,16 +296,28 @@ setup_ssh_wrapper () {
        '
 }
 
+copy_ssh_wrapper_as () {
+       cp "$TRASH_DIRECTORY/ssh-wrapper" "$1" &&
+       GIT_SSH="$1" &&
+       export GIT_SSH
+}
+
 expect_ssh () {
        test_when_finished '
                (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
        ' &&
        {
-               case "$1" in
-               none)
+               case "$#" in
+               1)
                        ;;
-               *)
+               2)
                        echo "ssh: $1 git-upload-pack '$2'"
+                       ;;
+               3)
+                       echo "ssh: $1 $2 git-upload-pack '$3'"
+                       ;;
+               *)
+                       echo "ssh: $1 $2 git-upload-pack '$3' $4"
                esac
        } >"$TRASH_DIRECTORY/ssh-expect" &&
        (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
@@ -326,9 +338,36 @@ test_expect_success !MINGW,!CYGWIN 'clone local path foo:bar' '
 
 test_expect_success 'bracketed hostnames are still ssh' '
        git clone "[myhost:123]:src" ssh-bracket-clone &&
-       expect_ssh myhost:123 src
+       expect_ssh "-p 123" myhost src
+'
+
+test_expect_success 'uplink is not treated as putty' '
+       copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
+       git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
+       expect_ssh "-p 123" myhost src
 '
 
+test_expect_success 'plink is treated specially (as putty)' '
+       copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
+       git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&
+       expect_ssh "-P 123" myhost src
+'
+
+test_expect_success 'plink.exe is treated specially (as putty)' '
+       copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
+       git clone "[myhost:123]:src" ssh-bracket-clone-plink-1 &&
+       expect_ssh "-P 123" myhost src
+'
+
+test_expect_success 'tortoiseplink is like putty, with extra arguments' '
+       copy_ssh_wrapper_as "$TRASH_DIRECTORY/tortoiseplink" &&
+       git clone "[myhost:123]:src" ssh-bracket-clone-plink-2 &&
+       expect_ssh "-batch -P 123" myhost src
+'
+
+# Reset the GIT_SSH environment variable for clone tests.
+setup_ssh_wrapper
+
 counter=0
 # $1 url
 # $2 none|host
@@ -336,7 +375,8 @@ counter=0
 test_clone_url () {
        counter=$(($counter + 1))
        test_might_fail git clone "$1" tmp$counter &&
-       expect_ssh "$2" "$3"
+       shift &&
+       expect_ssh "$@"
 }
 
 test_expect_success !MINGW 'clone c:temp is ssl' '
@@ -359,7 +399,7 @@ done
 for repo in rep rep/home/project 123
 do
        test_expect_success "clone [::1]:$repo" '
-               test_clone_url [::1]:$repo ::1 $repo
+               test_clone_url [::1]:$repo ::1 "$repo"
        '
 done
 #home directory
@@ -380,14 +420,17 @@ do
 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"
+#ignore trailing colon
+for tcol in "" :
+do
+       test_expect_success "clone ssh://host.xz$tcol/home/user/repo" '
+               test_clone_url "ssh://host.xz$tcol/home/user/repo" host.xz /home/user/repo
+       '
+       # from home directory
+       test_expect_success "clone ssh://host.xz$tcol/~repo" '
+       test_clone_url "ssh://host.xz$tcol/~repo" host.xz "~repo"
 '
+done
 
 # with port number
 test_expect_success 'clone ssh://host.xz:22/home/user/repo' '
@@ -400,24 +443,40 @@ test_expect_success 'clone ssh://host.xz:22/~repo' '
 '
 
 #IPv6
-test_expect_success 'clone ssh://[::1]/home/user/repo' '
-       test_clone_url "ssh://[::1]/home/user/repo" "::1" "/home/user/repo"
-'
+for tuah in ::1 [::1] [::1]: user@::1 user@[::1] user@[::1]: [user@::1] [user@::1]:
+do
+       ehost=$(echo $tuah | sed -e "s/1]:/1]/ "| tr -d "[]")
+       test_expect_success "clone ssh://$tuah/home/user/repo" "
+         test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo
+       "
+done
 
 #IPv6 from home directory
-test_expect_success 'clone ssh://[::1]/~repo' '
-       test_clone_url "ssh://[::1]/~repo" "::1" "~repo"
-'
+for tuah in ::1 [::1] user@::1 user@[::1] [user@::1]
+do
+       euah=$(echo $tuah | tr -d "[]")
+       test_expect_success "clone ssh://$tuah/~repo" "
+         test_clone_url ssh://$tuah/~repo $euah '~repo'
+       "
+done
 
 #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"
-'
+for tuah in [::1] user@[::1] [user@::1]
+do
+       euah=$(echo $tuah | tr -d "[]")
+       test_expect_success "clone ssh://$tuah:22/home/user/repo" "
+         test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo
+       "
+done
 
 #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"
-'
+for tuah in [::1] user@[::1] [user@::1]
+do
+       euah=$(echo $tuah | tr -d "[]")
+       test_expect_success "clone ssh://$tuah:22/~repo" "
+         test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
+       "
+done
 
 test_expect_success 'clone from a repository with two identical branches' '