connect: Add the envvar GIT_SSH_VARIANT and ssh.variant config

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>

Segev Finer committed Feb 1, 2017 at 13:01 UTC dd33e07766f883c1bbfd20482123e143028f0af6
4 files changed +51 -3
Documentation/config.txt
+11
@@ -1949,6 +1949,17 @@ Environment variable settings always override any matches. The URLs that are
1949 matched against are those given directly to Git commands. This means any URLs
1950 visited as a result of a redirection do not participate in matching.
1951
1952 +ssh.variant::
1953 + Depending on the value of the environment variables `GIT_SSH` or
1954 + `GIT_SSH_COMMAND`, or the config setting `core.sshCommand`, Git
1955 + auto-detects whether to adjust its command-line parameters for use
1956 + with plink or tortoiseplink, as opposed to the default (OpenSSH).
1957 ++
1958 +The config variable `ssh.variant` can be set to override this auto-detection;
1959 +valid values are `ssh`, `plink`, `putty` or `tortoiseplink`. Any other value
1960 +will be treated as normal ssh. This setting can be overridden via the
1961 +environment variable `GIT_SSH_VARIANT`.
1962 +
1963 i18n.commitEncoding::
1964 Character encoding the commit messages are stored in; Git itself
1965 does not care per se, but this information is necessary e.g. when
Documentation/git.txt
+6
@@ -1020,6 +1020,12 @@ Usually it is easier to configure any desired options through your
1020 personal `.ssh/config` file. Please consult your ssh documentation
1021 for further details.
1022
1023 +`GIT_SSH_VARIANT`::
1024 + If this environment variable is set, it overrides Git's autodetection
1025 + whether `GIT_SSH`/`GIT_SSH_COMMAND`/`core.sshCommand` refer to OpenSSH,
1026 + plink or tortoiseplink. This variable overrides the config setting
1027 + `ssh.variant` that serves the same purpose.
1028 +
1029 `GIT_ASKPASS`::
1030 If this environment variable is set, then Git commands which need to
1031 acquire passwords or passphrases (e.g. for HTTP or IMAP authentication)
connect.c
+8 -3
@@ -694,10 +694,14 @@ static const char *get_ssh_command(void)
694 static int handle_ssh_variant(const char *ssh_command, int is_cmdline,
695 int *port_option, int *needs_batch)
696 {
697 - const char *variant;
697 + const char *variant = getenv("GIT_SSH_VARIANT");
698 char *p = NULL;
699
700 - if (!is_cmdline) {
700 + if (variant)
701 + ; /* okay, fall through */
702 + else if (!git_config_get_string("ssh.variant", &p))
703 + variant = p;
704 + else if (!is_cmdline) {
705 p = xstrdup(ssh_command);
706 variant = basename(p);
707 } else {
@@ -717,7 +721,8 @@ static int handle_ssh_variant(const char *ssh_command, int is_cmdline,
721 }
722
723 if (!strcasecmp(variant, "plink") ||
720 - !strcasecmp(variant, "plink.exe"))
724 + !strcasecmp(variant, "plink.exe") ||
725 + !strcasecmp(variant, "putty"))
726 *port_option = 'P';
727 else if (!strcasecmp(variant, "tortoiseplink") ||
728 !strcasecmp(variant, "tortoiseplink.exe")) {
t/t5601-clone.sh
+26
@@ -401,6 +401,32 @@ test_expect_success 'single quoted plink.exe in GIT_SSH_COMMAND' '
401 expect_ssh "-v -P 123" myhost src
402 '
403
404 +test_expect_success 'GIT_SSH_VARIANT overrides plink detection' '
405 + copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
406 + GIT_SSH_VARIANT=ssh \
407 + git clone "[myhost:123]:src" ssh-bracket-clone-variant-1 &&
408 + expect_ssh "-p 123" myhost src
409 +'
410 +
411 +test_expect_success 'ssh.variant overrides plink detection' '
412 + copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
413 + git -c ssh.variant=ssh \
414 + clone "[myhost:123]:src" ssh-bracket-clone-variant-2 &&
415 + expect_ssh "-p 123" myhost src
416 +'
417 +
418 +test_expect_success 'GIT_SSH_VARIANT overrides plink detection to plink' '
419 + GIT_SSH_VARIANT=plink \
420 + git clone "[myhost:123]:src" ssh-bracket-clone-variant-3 &&
421 + expect_ssh "-P 123" myhost src
422 +'
423 +
424 +test_expect_success 'GIT_SSH_VARIANT overrides plink to tortoiseplink' '
425 + GIT_SSH_VARIANT=tortoiseplink \
426 + git clone "[myhost:123]:src" ssh-bracket-clone-variant-4 &&
427 + expect_ssh "-batch -P 123" myhost src
428 +'
429 +
430 # Reset the GIT_SSH environment variable for clone tests.
431 setup_ssh_wrapper
432