Skip to content

Commit 3994276

Browse files
quinotgitster
authored andcommitted
git_connect: set ssh shell command in GIT_SSH_COMMAND
It may be impractical to install a wrapper script for GIT_SSH when additional parameters need to be passed. Provide an alternative way of specifying a shell command to be run, including command line arguments, by means of the GIT_SSH_COMMAND environment variable, which behaves like GIT_SSH but is passed to the shell. The special circuitry to modify parameters in the case of using PuTTY's plink/tortoiseplink is activated only when using GIT_SSH; in the case of using GIT_SSH_COMMAND, it is deliberately left up to the user to make any required parameters adaptation before calling the underlying ssh implementation. Signed-off-by: Thomas Quinot <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66edfe9 commit 3994276

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

Documentation/git.txt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -876,19 +876,21 @@ other
876876
and the `core.editor` option in linkgit:git-config[1].
877877

878878
'GIT_SSH'::
879-
If this environment variable is set then 'git fetch'
880-
and 'git push' will use this command instead
881-
of 'ssh' when they need to connect to a remote system.
882-
The '$GIT_SSH' command will be given exactly two or
883-
four arguments: the 'username@host' (or just 'host')
884-
from the URL and the shell command to execute on that
885-
remote system, optionally preceded by '-p' (literally) and
886-
the 'port' from the URL when it specifies something other
887-
than the default SSH port.
879+
'GIT_SSH_COMMAND'::
880+
If either of these environment variables is set then 'git fetch'
881+
and 'git push' will use the specified command instead of 'ssh'
882+
when they need to connect to a remote system.
883+
The command will be given exactly two or four arguments: the
884+
'username@host' (or just 'host') from the URL and the shell
885+
command to execute on that remote system, optionally preceded by
886+
'-p' (literally) and the 'port' from the URL when it specifies
887+
something other than the default SSH port.
888888
+
889-
To pass options to the program that you want to list in GIT_SSH
890-
you will need to wrap the program and options into a shell script,
891-
then set GIT_SSH to refer to the shell script.
889+
`$GIT_SSH_COMMAND` takes precedence over `$GIT_SSH`, and is interpreted
890+
by the shell, which allows additional arguments to be included.
891+
`$GIT_SSH` on the other hand must be just the path to a program
892+
(which can be a wrapper shell script, if additional arguments are
893+
needed).
892894
+
893895
Usually it is easier to configure any desired options through your
894896
personal `.ssh/config` file. Please consult your ssh documentation

connect.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,23 @@ struct child_process *git_connect(int fd[2], const char *url,
700700

701701
conn->in = conn->out = -1;
702702
if (protocol == PROTO_SSH) {
703-
const char *ssh = getenv("GIT_SSH");
704-
int putty = ssh && strcasestr(ssh, "plink");
703+
const char *ssh;
704+
int putty;
705705
char *ssh_host = hostandport;
706706
const char *port = NULL;
707707
get_host_and_port(&ssh_host, &port);
708708
port = get_port_numeric(port);
709709

710-
if (!ssh) ssh = "ssh";
710+
ssh = getenv("GIT_SSH_COMMAND");
711+
if (ssh) {
712+
conn->use_shell = 1;
713+
putty = 0;
714+
} else {
715+
ssh = getenv("GIT_SSH");
716+
if (!ssh)
717+
ssh = "ssh";
718+
putty = !!strcasestr(ssh, "plink");
719+
}
711720

712721
argv_array_push(&conn->args, ssh);
713722
if (putty && !strcasestr(ssh, "tortoiseplink"))

0 commit comments

Comments
 (0)