connect: Add the envvar GIT_SSH_VARIANT and ssh.variant config
authorSegev Finer <segev208@gmail.com>
Wed, 1 Feb 2017 12:01:16 +0000 (13:01 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Feb 2017 18:57:53 +0000 (10:57 -0800)
This environment variable and configuration value allow to
override the autodetection of plink/tortoiseplink in case that
Git gets it wrong.

[jes: wrapped overly-long lines, factored out and changed
get_ssh_variant() to handle_ssh_variant() to accomodate the
change from the putty/tortoiseplink variables to
port_option/needs_batch, adjusted the documentation, free()d
value obtained from the config.]

Signed-off-by: Segev Finer <segev208@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
Documentation/git.txt
connect.c
t/t5601-clone.sh
index af2ae4cc02af75c5cf9395e228ff8bbc6e390181..b88df57ab6adc4b7af5c1b0ec43262d1ab393768 100644 (file)
@@ -1949,6 +1949,17 @@ Environment variable settings always override any matches.  The URLs that are
 matched against are those given directly to Git commands.  This means any URLs
 visited as a result of a redirection do not participate in matching.
 
 matched against are those given directly to Git commands.  This means any URLs
 visited as a result of a redirection do not participate in matching.
 
+ssh.variant::
+       Depending on the value of the environment variables `GIT_SSH` or
+       `GIT_SSH_COMMAND`, or the config setting `core.sshCommand`, Git
+       auto-detects whether to adjust its command-line parameters for use
+       with plink or tortoiseplink, as opposed to the default (OpenSSH).
++
+The config variable `ssh.variant` can be set to override this auto-detection;
+valid values are `ssh`, `plink`, `putty` or `tortoiseplink`. Any other value
+will be treated as normal ssh. This setting can be overridden via the
+environment variable `GIT_SSH_VARIANT`.
+
 i18n.commitEncoding::
        Character encoding the commit messages are stored in; Git itself
        does not care per se, but this information is necessary e.g. when
 i18n.commitEncoding::
        Character encoding the commit messages are stored in; Git itself
        does not care per se, but this information is necessary e.g. when
index 4f208fab925cc00535c23c40d38ad6e3d56eeaab..a0c6728d1af307dda73ad9eaa01f6970b32529dc 100644 (file)
@@ -1020,6 +1020,12 @@ Usually it is easier to configure any desired options through your
 personal `.ssh/config` file.  Please consult your ssh documentation
 for further details.
 
 personal `.ssh/config` file.  Please consult your ssh documentation
 for further details.
 
+`GIT_SSH_VARIANT`::
+       If this environment variable is set, it overrides Git's autodetection
+       whether `GIT_SSH`/`GIT_SSH_COMMAND`/`core.sshCommand` refer to OpenSSH,
+       plink or tortoiseplink. This variable overrides the config setting
+       `ssh.variant` that serves the same purpose.
+
 `GIT_ASKPASS`::
        If this environment variable is set, then Git commands which need to
        acquire passwords or passphrases (e.g. for HTTP or IMAP authentication)
 `GIT_ASKPASS`::
        If this environment variable is set, then Git commands which need to
        acquire passwords or passphrases (e.g. for HTTP or IMAP authentication)
index 2734b9a1ca5a3bc154c4b0dbe509a61c37927cde..7f1f80239646cbf6fe2c971a63a21143dbf041e8 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -694,10 +694,14 @@ static const char *get_ssh_command(void)
 static int handle_ssh_variant(const char *ssh_command, int is_cmdline,
                              int *port_option, int *needs_batch)
 {
 static int handle_ssh_variant(const char *ssh_command, int is_cmdline,
                              int *port_option, int *needs_batch)
 {
-       const char *variant;
+       const char *variant = getenv("GIT_SSH_VARIANT");
        char *p = NULL;
 
        char *p = NULL;
 
-       if (!is_cmdline) {
+       if (variant)
+               ; /* okay, fall through */
+       else if (!git_config_get_string("ssh.variant", &p))
+               variant = p;
+       else if (!is_cmdline) {
                p = xstrdup(ssh_command);
                variant = basename(p);
        } else {
                p = xstrdup(ssh_command);
                variant = basename(p);
        } else {
@@ -717,7 +721,8 @@ static int handle_ssh_variant(const char *ssh_command, int is_cmdline,
        }
 
        if (!strcasecmp(variant, "plink") ||
        }
 
        if (!strcasecmp(variant, "plink") ||
-           !strcasecmp(variant, "plink.exe"))
+           !strcasecmp(variant, "plink.exe") ||
+           !strcasecmp(variant, "putty"))
                *port_option = 'P';
        else if (!strcasecmp(variant, "tortoiseplink") ||
                 !strcasecmp(variant, "tortoiseplink.exe")) {
                *port_option = 'P';
        else if (!strcasecmp(variant, "tortoiseplink") ||
                 !strcasecmp(variant, "tortoiseplink.exe")) {
index 9335e10c2ad7c1fff996c240e7469dceeb0003d6..b52b8acf9859b0084ea10ebf184ed95cafb0b2d8 100755 (executable)
@@ -401,6 +401,32 @@ test_expect_success 'single quoted plink.exe in GIT_SSH_COMMAND' '
        expect_ssh "-v -P 123" myhost src
 '
 
        expect_ssh "-v -P 123" myhost src
 '
 
+test_expect_success 'GIT_SSH_VARIANT overrides plink detection' '
+       copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
+       GIT_SSH_VARIANT=ssh \
+       git clone "[myhost:123]:src" ssh-bracket-clone-variant-1 &&
+       expect_ssh "-p 123" myhost src
+'
+
+test_expect_success 'ssh.variant overrides plink detection' '
+       copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
+       git -c ssh.variant=ssh \
+               clone "[myhost:123]:src" ssh-bracket-clone-variant-2 &&
+       expect_ssh "-p 123" myhost src
+'
+
+test_expect_success 'GIT_SSH_VARIANT overrides plink detection to plink' '
+       GIT_SSH_VARIANT=plink \
+       git clone "[myhost:123]:src" ssh-bracket-clone-variant-3 &&
+       expect_ssh "-P 123" myhost src
+'
+
+test_expect_success 'GIT_SSH_VARIANT overrides plink to tortoiseplink' '
+       GIT_SSH_VARIANT=tortoiseplink \
+       git clone "[myhost:123]:src" ssh-bracket-clone-variant-4 &&
+       expect_ssh "-batch -P 123" myhost src
+'
+
 # Reset the GIT_SSH environment variable for clone tests.
 setup_ssh_wrapper
 
 # Reset the GIT_SSH environment variable for clone tests.
 setup_ssh_wrapper