Skip to content
/ git Public
forked from git/git

Commit 09d60d7

Browse files
committed
Merge branch 'tq/git-ssh-command'
Allow passing extra set of arguments when ssh is invoked to create an encrypted & authenticated connection by introducing a new environment variable GIT_SSH_COMMAND, whose contents is interpreted by shells. This is not possible with existing GIT_SSH mechanism whose invocation bypasses shells, which was designed more to match what other programs with similar variables did, not necessarily to be more useful. * tq/git-ssh-command: git_connect: set ssh shell command in GIT_SSH_COMMAND
2 parents 05d7fb6 + 3994276 commit 09d60d7

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

Documentation/git.txt

+14-12
Original file line numberDiff line numberDiff line change
@@ -881,19 +881,21 @@ other
881881
and the `core.editor` option in linkgit:git-config[1].
882882

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

connect.c

+12-3
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)