mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 02:56:17 +00:00
ssh_exec: support GIT_SSH_COMMAND
Look for the `GIT_SSH_COMMAND` environment variable and prefer it to `GIT_SSH`. The `GIT_SSH_COMMAND` will execute via the shell, which is useful to provide additional arguments.
This commit is contained in:
@@ -121,6 +121,7 @@ GIT_INLINE(int) ensure_transport_state(
|
||||
|
||||
static int get_ssh_cmdline(
|
||||
git_vector *args,
|
||||
bool *use_shell,
|
||||
ssh_exec_subtransport *transport,
|
||||
git_net_url *url,
|
||||
const char *command)
|
||||
@@ -152,8 +153,12 @@ static int get_ssh_cmdline(
|
||||
if ((error = git_repository_config_snapshot(&cfg, repo)) < 0)
|
||||
return error;
|
||||
|
||||
if ((error = git__getenv(&ssh_cmd, "GIT_SSH")) == 0)
|
||||
;
|
||||
if ((error = git__getenv(&ssh_cmd, "GIT_SSH_COMMAND")) == 0)
|
||||
*use_shell = true;
|
||||
else if (error != GIT_ENOTFOUND)
|
||||
goto done;
|
||||
else if ((error = git__getenv(&ssh_cmd, "GIT_SSH")) == 0)
|
||||
*use_shell = false;
|
||||
else if (error != GIT_ENOTFOUND)
|
||||
goto done;
|
||||
else if ((error = git_config__get_string_buf(&ssh_cmd, cfg, "core.sshcommand")) < 0 && error != GIT_ENOTFOUND)
|
||||
@@ -213,6 +218,7 @@ static int start_ssh(
|
||||
git_process_options process_opts = GIT_PROCESS_OPTIONS_INIT;
|
||||
git_net_url url = GIT_NET_URL_INIT;
|
||||
git_vector args = GIT_VECTOR_INIT;
|
||||
bool use_shell = false;
|
||||
const char *command;
|
||||
int error;
|
||||
|
||||
@@ -243,9 +249,12 @@ static int start_ssh(
|
||||
if (error < 0)
|
||||
goto done;
|
||||
|
||||
if ((error = get_ssh_cmdline(&args, transport, &url, command)) < 0)
|
||||
if ((error = get_ssh_cmdline(&args, &use_shell,
|
||||
transport, &url, command)) < 0)
|
||||
goto done;
|
||||
|
||||
process_opts.use_shell = use_shell;
|
||||
|
||||
if ((error = git_process_new(&transport->process,
|
||||
(const char **)args.contents, args.length,
|
||||
env, ARRAY_SIZE(env), &process_opts)) < 0 ||
|
||||
|
||||
Reference in New Issue
Block a user