]> git.ipfire.org Git - thirdparty/git.git/commitdiff
connect: read $GIT_SSH_COMMAND from config file
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sun, 26 Jun 2016 11:16:35 +0000 (13:16 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Jul 2016 21:04:09 +0000 (14:04 -0700)
Similar to $GIT_ASKPASS or $GIT_PROXY_COMMAND, we also read from
config file first then fall back to $GIT_SSH_COMMAND.

This is useful for selecting different private keys targetting the
same host (e.g. github)

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
connect.c

index 2e1b2e486e615981c14f7e591f3f32aa06cdee7a..4a870d832d683564d65e0ec8233473769c1c6f09 100644 (file)
@@ -443,6 +443,13 @@ specify that no proxy be used for a given domain pattern.
 This is useful for excluding servers inside a firewall from
 proxy use, while defaulting to a common proxy for external domains.
 
+core.sshCommand::
+       If this variable is set, `git fetch` and `git push` will
+       use the specified command instead of `ssh` when they need to
+       connect to a remote system. The command is in the same form as
+       the `GIT_SSH_COMMAND` environment variable and is overridden
+       when the environment variable is set.
+
 core.ignoreStat::
        If true, Git will avoid using lstat() calls to detect if files have
        changed by setting the "assume-unchanged" bit for those tracked files
index c53f3f1c55243feae8affbb268af689b35b9169f..722dc3fc546056be199f5d6a59c556833be58286 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -658,6 +658,19 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
 
 static struct child_process no_fork = CHILD_PROCESS_INIT;
 
+static const char *get_ssh_command(void)
+{
+       const char *ssh;
+
+       if ((ssh = getenv("GIT_SSH_COMMAND")))
+               return ssh;
+
+       if (!git_config_get_string_const("core.sshcommand", &ssh))
+               return ssh;
+
+       return NULL;
+}
+
 /*
  * This returns a dummy child_process if the transport protocol does not
  * need fork(2), or a struct child_process object if it does.  Once done,
@@ -758,7 +771,7 @@ struct child_process *git_connect(int fd[2], const char *url,
                                return NULL;
                        }
 
-                       ssh = getenv("GIT_SSH_COMMAND");
+                       ssh = get_ssh_command();
                        if (!ssh) {
                                const char *base;
                                char *ssh_dup;