Skip to content

Commit 3c8ede3

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 05219a1 commit 3c8ede3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Documentation/config.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,13 @@ specify that no proxy be used for a given domain pattern.
443443
This is useful for excluding servers inside a firewall from
444444
proxy use, while defaulting to a common proxy for external domains.
445445

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+
446453
core.ignoreStat::
447454
If true, Git will avoid using lstat() calls to detect if files have
448455
changed by setting the "assume-unchanged" bit for those tracked files

connect.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,19 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
658658

659659
static struct child_process no_fork = CHILD_PROCESS_INIT;
660660

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+
661674
/*
662675
* This returns a dummy child_process if the transport protocol does not
663676
* 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,
758771
return NULL;
759772
}
760773

761-
ssh = getenv("GIT_SSH_COMMAND");
774+
ssh = get_ssh_command();
762775
if (!ssh) {
763776
const char *base;
764777
char *ssh_dup;

0 commit comments

Comments
 (0)