From 3fa5e0d07a979dfd1a1095a9dda4904c62189e00 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 20 Nov 2017 13:31:01 -0800 Subject: [PATCH] ssh: 'simple' variant does not support --port When trying to connect to an ssh:// URL with port explicitly specified and the ssh command configured with GIT_SSH does not support such a setting, it is less confusing to error out than to silently suppress the port setting and continue. This requires updating the GIT_SSH setting in t5603-clone-dirname.sh. That test is about the directory name produced when cloning various URLs. It uses an ssh wrapper that ignores all its arguments but does not declare that it supports a port argument; update it to set GIT_SSH_VARIANT=ssh to do so. (Real-life ssh wrappers that pass a port argument to OpenSSH would also support -G and would not require such an update.) Reported-by: William Yan Signed-off-by: Jonathan Nieder Acked-by: Stefan Beller Signed-off-by: Junio C Hamano --- connect.c | 15 ++++++++++++--- t/t5601-clone.sh | 10 ++++++++-- t/t5603-clone-dirname.sh | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/connect.c b/connect.c index c3d1cd3787..d6033861b3 100644 --- a/connect.c +++ b/connect.c @@ -967,11 +967,20 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env, if (variant == VARIANT_TORTOISEPLINK) argv_array_push(args, "-batch"); - if (port && variant != VARIANT_SIMPLE) { - if (variant == VARIANT_SSH) + if (port) { + switch (variant) { + case VARIANT_AUTO: + BUG("VARIANT_AUTO passed to push_ssh_options"); + case VARIANT_SIMPLE: + die("ssh variant 'simple' does not support setting port"); + case VARIANT_SSH: argv_array_push(args, "-p"); - else + break; + case VARIANT_PLINK: + case VARIANT_PUTTY: + case VARIANT_TORTOISEPLINK: argv_array_push(args, "-P"); + } argv_array_push(args, port); } diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 9ae1606ee5..66784fc8ff 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -378,12 +378,18 @@ test_expect_success 'variant=auto picks based on basename' ' test_expect_success 'simple does not support -4/-6' ' copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" && - test_must_fail git clone -4 "[myhost:123]:src" ssh-bracket-clone-simple + test_must_fail git clone -4 "myhost:src" ssh-4-clone-simple +' + +test_expect_success 'simple does not support port' ' + copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" && + test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-simple ' test_expect_success 'uplink is treated as simple' ' copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" && - git clone "[myhost:123]:src" ssh-bracket-clone-uplink && + test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-uplink && + git clone "myhost:src" ssh-clone-uplink && expect_ssh myhost src ' diff --git a/t/t5603-clone-dirname.sh b/t/t5603-clone-dirname.sh index d5af758129..13b5e5eb9b 100755 --- a/t/t5603-clone-dirname.sh +++ b/t/t5603-clone-dirname.sh @@ -11,7 +11,9 @@ test_expect_success 'setup ssh wrapper' ' git upload-pack "$TRASH_DIRECTORY" EOF GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" && + GIT_SSH_VARIANT=ssh && export GIT_SSH && + export GIT_SSH_VARIANT && export TRASH_DIRECTORY ' -- 2.11.4.GIT