{"thread":{"id":"42715","subject":"[PATCH] connect: read $GIT_SSH_COMMAND from config file","startedAt":"2016-06-26T11:16:53Z","lastAt":"2016-06-28T19:01:30Z","messageCount":5,"participants":["Nguyễn Thái Ngọc Duy","Jeff King","Matthieu Moy","Junio C Hamano","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"290185","messageId":"20160626111635.6809-1-pclouds@gmail.com","threadId":"42715","inReplyTo":null,"subject":"[PATCH] connect: read $GIT_SSH_COMMAND from config file","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2016-06-26T11:16:35Z","receivedAt":"2016-06-26T11:16:53Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Similar to $GIT_ASKPASS or $GIT_PROXY_COMMAND, we also read from\nconfig file first then fall back to $GIT_SSH_COMMAND.\n\nThis is useful for selecting different private keys targetting the\nsame host (e.g. github)\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n core.gitProxy can also be used for my purpose (I need pushing, not\n fetching though; the document says for fetching but I guess\n core.gitProxy always works for pushing), but then the key file\n is hidden behind the script. And writing a script for this seems a\n bit overkill.\n\n Documentation/config.txt |  7 +++++++\n connect.c                | 15 ++++++++++++++-\n 2 files changed, 21 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 58673cf..3bf070c 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -443,6 +443,13 @@ specify that no proxy be used for a given domain pattern.\n This is useful for excluding servers inside a firewall from\n proxy use, while defaulting to a common proxy for external domains.\n \n+core.sshCommand::\n+\tIf this variable is set then 'git fetch' and 'git push' will\n+\tuse the specified command instead of 'ssh' when they need to\n+\tconnect to a remote system. The command is in the same form as\n+\t'GIT_SSH_COMMAND' environment variable and is overriden when\n+\tthe environment variable is set.\n+\n core.ignoreStat::\n \tIf true, Git will avoid using lstat() calls to detect if files have\n \tchanged by setting the \"assume-unchanged\" bit for those tracked files\ndiff --git a/connect.c b/connect.c\nindex c53f3f1..722dc3f 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -658,6 +658,19 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,\n \n static struct child_process no_fork = CHILD_PROCESS_INIT;\n \n+static const char *get_ssh_command(void)\n+{\n+\tconst char *ssh;\n+\n+\tif ((ssh = getenv(\"GIT_SSH_COMMAND\")))\n+\t\treturn ssh;\n+\n+\tif (!git_config_get_string_const(\"core.sshcommand\", &ssh))\n+\t\treturn ssh;\n+\n+\treturn NULL;\n+}\n+\n /*\n  * This returns a dummy child_process if the transport protocol does not\n  * need fork(2), or a struct child_process object if it does.  Once done,\n@@ -758,7 +771,7 @@ struct child_process *git_connect(int fd[2], const char *url,\n \t\t\t\treturn NULL;\n \t\t\t}\n \n-\t\t\tssh = getenv(\"GIT_SSH_COMMAND\");\n+\t\t\tssh = get_ssh_command();\n \t\t\tif (!ssh) {\n \t\t\t\tconst char *base;\n \t\t\t\tchar *ssh_dup;\n-- \n2.8.2.530.g66e63ce\n\n"},{"id":"290317","messageId":"20160627193322.GB10877@sigill.intra.peff.net","threadId":"42715","inReplyTo":"20160626111635.6809-1-pclouds@gmail.com","subject":"Re: [PATCH] connect: read $GIT_SSH_COMMAND from config file","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-06-27T19:33:23Z","receivedAt":"2016-06-27T19:33:29Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jun 26, 2016 at 01:16:35PM +0200, Nguyễn Thái Ngọc Duy wrote:\n\n> Similar to $GIT_ASKPASS or $GIT_PROXY_COMMAND, we also read from\n> config file first then fall back to $GIT_SSH_COMMAND.\n> \n> This is useful for selecting different private keys targetting the\n> same host (e.g. github)\n> \n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  core.gitProxy can also be used for my purpose (I need pushing, not\n>  fetching though; the document says for fetching but I guess\n>  core.gitProxy always works for pushing), but then the key file\n>  is hidden behind the script. And writing a script for this seems a\n>  bit overkill.\n\nThis patch makes sense to me. The way I have done this in the past is to\nuse ssh's config. So I set my remote in one repo to \"foo:repo1.git\" and\nanother to \"bar:repo2.git\", and then:\n\n  Host foo\n    Hostname actual-host.example.com\n    SomeOption ...\n\n  Host bar\n    Hostname actual-host.example.com\n    SomeOption ...\n\n(or more likely, most repos are fine with the defaults, and you only\nneed one fake host block for the oddball repo).\n\nBut I think your solution is a more direct and less confusing way of\naccomplishing the same thing.\n\n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> index 58673cf..3bf070c 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -443,6 +443,13 @@ specify that no proxy be used for a given domain pattern.\n>  This is useful for excluding servers inside a firewall from\n>  proxy use, while defaulting to a common proxy for external domains.\n>  \n> +core.sshCommand::\n> +\tIf this variable is set then 'git fetch' and 'git push' will\n\nProbably s/set/set,/.\n\n> +\tuse the specified command instead of 'ssh' when they need to\n> +\tconnect to a remote system. The command is in the same form as\n> +\t'GIT_SSH_COMMAND' environment variable and is overriden when\n> +\tthe environment variable is set.\n\nProbably s/'GIT_SSH_COMMAND'/the &/.\n\nAre we using backticks for typesetting environment variables now? That\nhas always been my preference, but I haven't kept up with the typography\npatches that have been flying lately. +cc Matthieu.\n\n(Similar question for commands like 'git fetch').\n\n> diff --git a/connect.c b/connect.c\n> index c53f3f1..722dc3f 100644\n> --- a/connect.c\n> +++ b/connect.c\n\nThe code itself looks obviously correct. :)\n\n-Peff\n"},{"id":"290350","messageId":"vpqwpl9yal3.fsf@anie.imag.fr","threadId":"42715","inReplyTo":"20160627193322.GB10877@sigill.intra.peff.net","subject":"Re: [PATCH] connect: read $GIT_SSH_COMMAND from config file","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2016-06-28T08:35:52Z","receivedAt":"2016-06-28T08:36:24Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Sun, Jun 26, 2016 at 01:16:35PM +0200, Nguyễn Thái Ngọc Duy wrote:\n>\n>> +\tuse the specified command instead of 'ssh' when they need to\n>> +\tconnect to a remote system. The command is in the same form as\n>> +\t'GIT_SSH_COMMAND' environment variable and is overriden when\n>> +\tthe environment variable is set.\n>\n> Probably s/'GIT_SSH_COMMAND'/the &/.\n\nI think so. I'd write either \"same form as `GIT_SSH_COMMAND`\" or \"same\nform as the `GIT_SSH_COMMAND` environment variable`.\n\n> Are we using backticks for typesetting environment variables now? That\n> has always been my preference, but I haven't kept up with the typography\n> patches that have been flying lately. +cc Matthieu.\n\nYes, we've tried to make the docs a bit more consistant, and to document\nthat better in Documentation/CodingGuidelines:\n\n An environment variable must be prefixed with \"$\" only when referring to its\n value and not when referring to the variable itself, in this case there is\n nothing to add except the backticks:\n   `GIT_DIR` is specified\n   `$GIT_DIR/hooks/pre-receive`\n\n> (Similar question for commands like 'git fetch').\n\nBackticks too:\n\n   Literal examples (e.g. use of command-line options, command names,\n branch names, configuration and environment variables) must be\n typeset in monospace (i.e. wrapped with backticks):\n   `--pretty=oneline`\n   `git rev-list`\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"290406","messageId":"xmqqtwgd8ab0.fsf@gitster.mtv.corp.google.com","threadId":"42715","inReplyTo":"vpqwpl9yal3.fsf@anie.imag.fr","subject":"Re: [PATCH] connect: read $GIT_SSH_COMMAND from config file","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-06-28T17:58:43Z","receivedAt":"2016-06-28T17:58:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:\n\n> Jeff King <peff@peff.net> writes:\n>\n>> On Sun, Jun 26, 2016 at 01:16:35PM +0200, Nguyễn Thái Ngọc Duy wrote:\n>>\n>>> +\tuse the specified command instead of 'ssh' when they need to\n>>> +\tconnect to a remote system. The command is in the same form as\n>>> +\t'GIT_SSH_COMMAND' environment variable and is overriden when\n>>> +\tthe environment variable is set.\n>>\n>> Probably s/'GIT_SSH_COMMAND'/the &/.\n>\n> I think so. I'd write either \"same form as `GIT_SSH_COMMAND`\" or \"same\n> form as the `GIT_SSH_COMMAND` environment variable`.\n\nLet's then squash this in.\n\n Documentation/config.txt | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex bd32069..fe7c9c4 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -444,11 +444,11 @@ This is useful for excluding servers inside a firewall from\n proxy use, while defaulting to a common proxy for external domains.\n \n core.sshCommand::\n-\tIf this variable is set then 'git fetch' and 'git push' will\n-\tuse the specified command instead of 'ssh' when they need to\n+\tIf this variable is set, `git fetch` and `git push` will\n+\tuse the specified command instead of `ssh` when they need to\n \tconnect to a remote system. The command is in the same form as\n-\t'GIT_SSH_COMMAND' environment variable and is overriden when\n-\tthe environment variable is set.\n+\tthe `GIT_SSH_COMMAND` environment variable and is overriden\n+\twhen the environment variable is set.\n \n core.ignoreStat::\n \tIf true, Git will avoid using lstat() calls to detect if files have\n"},{"id":"290424","messageId":"CAPig+cRtmk_yukPGOTOn7CR7U_FY=ThbaMEc632L=yYz98zhVw@mail.gmail.com","threadId":"42715","inReplyTo":"xmqqtwgd8ab0.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] connect: read $GIT_SSH_COMMAND from config file","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-06-28T19:01:11Z","receivedAt":"2016-06-28T19:01:30Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Jun 28, 2016 at 1:58 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Let's then squash this in.\n>\n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> @@ -444,11 +444,11 @@ This is useful for excluding servers inside a firewall from\n>  core.sshCommand::\n> -       If this variable is set then 'git fetch' and 'git push' will\n> -       use the specified command instead of 'ssh' when they need to\n> +       If this variable is set, `git fetch` and `git push` will\n> +       use the specified command instead of `ssh` when they need to\n>         connect to a remote system. The command is in the same form as\n> -       'GIT_SSH_COMMAND' environment variable and is overriden when\n> -       the environment variable is set.\n> +       the `GIT_SSH_COMMAND` environment variable and is overriden\n\ns/overriden/overridden/\n\n> +       when the environment variable is set.\n"}]}