lfsapi: learn core.sshCommand

We already know how to handle GIT_SSH_COMMAND and its appurtenant shell
parsing requirements.  However, Git also knows the ability to specify an
equivalent command in the config file as core.sshCommand, which allows
for greater flexibility.  Teach git-lfs how to handle core.sshCommand as
well.  Add tests that we process it through the shell correctly and that
GIT_SSH_COMMAND overrides it correctly.

Note that when calling sshParseShellCommand, we specify the default SSH
command directly inline as the fallback command to avoid needing an
additional check for ssh being the empty string in case core.sshCommand
is not set.
This commit is contained in:
brian m. carlson 2018-09-07 17:06:30 +00:00
parent e19f951bff
commit 45954c142f
2 changed files with 46 additions and 1 deletions

@ -159,7 +159,8 @@ func sshGetExeAndArgs(osEnv config.Environment, gitEnv config.Environment, e End
ssh, cmd, needShell = sshParseShellCommand(sshCmd, ssh) ssh, cmd, needShell = sshParseShellCommand(sshCmd, ssh)
if ssh == "" { if ssh == "" {
ssh = defaultSSHCmd sshCmd, _ := gitEnv.Get("core.sshcommand")
ssh, cmd, needShell = sshParseShellCommand(sshCmd, defaultSSHCmd)
} }
if cmd == "" { if cmd == "" {

@ -414,6 +414,50 @@ func TestSSHGetExeAndArgsSshCommandCustomPort(t *testing.T) {
assert.Equal(t, []string{"-c", "sshcmd -p 8888 user@foo.com"}, args) assert.Equal(t, []string{"-c", "sshcmd -p 8888 user@foo.com"}, args)
} }
func TestSSHGetExeAndArgsCoreSshCommand(t *testing.T) {
cli, err := NewClient(NewContext(nil, map[string]string{
"GIT_SSH_COMMAND": "sshcmd --args 2",
}, map[string]string{
"core.sshcommand": "sshcmd --args 1",
}))
require.Nil(t, err)
endpoint := cli.Endpoints.Endpoint("download", "")
endpoint.SshUserAndHost = "user@foo.com"
exe, args := sshFormatArgs(sshGetExeAndArgs(cli.OSEnv(), cli.GitEnv(), endpoint))
assert.Equal(t, "sh", exe)
assert.Equal(t, []string{"-c", "sshcmd --args 2 user@foo.com"}, args)
}
func TestSSHGetExeAndArgsCoreSshCommandArgsWithMixedQuotes(t *testing.T) {
cli, err := NewClient(NewContext(nil, nil, map[string]string{
"core.sshcommand": "sshcmd foo 'bar \"baz\"'",
}))
require.Nil(t, err)
endpoint := cli.Endpoints.Endpoint("download", "")
endpoint.SshUserAndHost = "user@foo.com"
exe, args := sshFormatArgs(sshGetExeAndArgs(cli.OSEnv(), cli.GitEnv(), endpoint))
assert.Equal(t, "sh", exe)
assert.Equal(t, []string{"-c", "sshcmd foo 'bar \"baz\"' user@foo.com"}, args)
}
func TestSSHGetExeAndArgsConfigVersusEnv(t *testing.T) {
cli, err := NewClient(NewContext(nil, nil, map[string]string{
"core.sshcommand": "sshcmd --args 1",
}))
require.Nil(t, err)
endpoint := cli.Endpoints.Endpoint("download", "")
endpoint.SshUserAndHost = "user@foo.com"
exe, args := sshFormatArgs(sshGetExeAndArgs(cli.OSEnv(), cli.GitEnv(), endpoint))
assert.Equal(t, "sh", exe)
assert.Equal(t, []string{"-c", "sshcmd --args 1 user@foo.com"}, args)
}
func TestSSHGetLFSExeAndArgsWithCustomSSH(t *testing.T) { func TestSSHGetLFSExeAndArgsWithCustomSSH(t *testing.T) {
cli, err := NewClient(NewContext(nil, map[string]string{ cli, err := NewClient(NewContext(nil, map[string]string{
"GIT_SSH": "not-ssh", "GIT_SSH": "not-ssh",