Skip to content

Commit dd33e07

Browse files
segevfinergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e2824e4 commit dd33e07

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

Documentation/config.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,17 @@ Environment variable settings always override any matches. The URLs that are
19491949
matched against are those given directly to Git commands. This means any URLs
19501950
visited as a result of a redirection do not participate in matching.
19511951

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+
19521963
i18n.commitEncoding::
19531964
Character encoding the commit messages are stored in; Git itself
19541965
does not care per se, but this information is necessary e.g. when

Documentation/git.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,12 @@ Usually it is easier to configure any desired options through your
10201020
personal `.ssh/config` file. Please consult your ssh documentation
10211021
for further details.
10221022

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+
10231029
`GIT_ASKPASS`::
10241030
If this environment variable is set, then Git commands which need to
10251031
acquire passwords or passphrases (e.g. for HTTP or IMAP authentication)

connect.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,14 @@ static const char *get_ssh_command(void)
694694
static int handle_ssh_variant(const char *ssh_command, int is_cmdline,
695695
int *port_option, int *needs_batch)
696696
{
697-
const char *variant;
697+
const char *variant = getenv("GIT_SSH_VARIANT");
698698
char *p = NULL;
699699

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) {
701705
p = xstrdup(ssh_command);
702706
variant = basename(p);
703707
} else {
@@ -717,7 +721,8 @@ static int handle_ssh_variant(const char *ssh_command, int is_cmdline,
717721
}
718722

719723
if (!strcasecmp(variant, "plink") ||
720-
!strcasecmp(variant, "plink.exe"))
724+
!strcasecmp(variant, "plink.exe") ||
725+
!strcasecmp(variant, "putty"))
721726
*port_option = 'P';
722727
else if (!strcasecmp(variant, "tortoiseplink") ||
723728
!strcasecmp(variant, "tortoiseplink.exe")) {

t/t5601-clone.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,32 @@ test_expect_success 'single quoted plink.exe in GIT_SSH_COMMAND' '
401401
expect_ssh "-v -P 123" myhost src
402402
'
403403

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+
404430
# Reset the GIT_SSH environment variable for clone tests.
405431
setup_ssh_wrapper
406432

0 commit comments

Comments
 (0)