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 <thomas@quinot.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Quinot committed
Nov 9, 2014 at 23:42 UTC
39942766ab9bc738f49f93d4c8ea68ffbaadc305
2 files changed
+26
-15
Documentation/git.txt
+14
-12
@@ -876,19 +876,21 @@ other
876
and the `core.editor` option in linkgit:git-config[1].
877
878
'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.
888
+
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).
894
+
895
Usually it is easier to configure any desired options through your
896
personal `.ssh/config` file. Please consult your ssh documentation
connect.c
+12
-3
@@ -700,14 +700,23 @@ struct child_process *git_connect(int fd[2], const char *url,
700
701
conn->in = conn->out = -1;
702
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;
705
char *ssh_host = hostandport;
706
const char *port = NULL;
707
get_host_and_port(&ssh_host, &port);
708
port = get_port_numeric(port);
709
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
+ }
720
721
argv_array_push(&conn->args, ssh);
722
if (putty && !strcasestr(ssh, "tortoiseplink"))