connect: read $GIT_SSH_COMMAND from config file

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>

Nguyễn Thái Ngọc Duy committed Jun 26, 2016 at 13:16 UTC 3c8ede3ff312134e84d1b23a309cd7d2a7c98e9c
2 files changed +21 -1
Documentation/config.txt
+7
@@ -443,6 +443,13 @@ specify that no proxy be used for a given domain pattern.
443 This is useful for excluding servers inside a firewall from
444 proxy use, while defaulting to a common proxy for external domains.
445
446 +core.sshCommand::
447 + If this variable is set, `git fetch` and `git push` will
448 + use the specified command instead of `ssh` when they need to
449 + connect to a remote system. The command is in the same form as
450 + the `GIT_SSH_COMMAND` environment variable and is overridden
451 + when the environment variable is set.
452 +
453 core.ignoreStat::
454 If true, Git will avoid using lstat() calls to detect if files have
455 changed by setting the "assume-unchanged" bit for those tracked files
connect.c
+14 -1
@@ -658,6 +658,19 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
658
659 static struct child_process no_fork = CHILD_PROCESS_INIT;
660
661 +static const char *get_ssh_command(void)
662 +{
663 + const char *ssh;
664 +
665 + if ((ssh = getenv("GIT_SSH_COMMAND")))
666 + return ssh;
667 +
668 + if (!git_config_get_string_const("core.sshcommand", &ssh))
669 + return ssh;
670 +
671 + return NULL;
672 +}
673 +
674 /*
675 * This returns a dummy child_process if the transport protocol does not
676 * 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,
771 return NULL;
772 }
773
761 - ssh = getenv("GIT_SSH_COMMAND");
774 + ssh = get_ssh_command();
775 if (!ssh) {
776 const char *base;
777 char *ssh_dup;