fix(process): allow overriding GIT_SSH_COMMAND. Fixes #491. Fixes #492

This commit is contained in:
Folke Lemaitre 2023-02-06 09:16:49 +01:00
parent 3d2dcb2d5e
commit 452d4eb719
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 10 additions and 15 deletions

View File

@ -49,7 +49,7 @@ local uv = vim.loop
---@field on_line? fun(string) ---@field on_line? fun(string)
---@field on_exit? fun(ok:boolean, output:string) ---@field on_exit? fun(ok:boolean, output:string)
---@field timeout? number ---@field timeout? number
---@field env? string[] ---@field env? table<string,string>
---@param opts? ProcessOpts ---@param opts? ProcessOpts
---@param cmd string ---@param cmd string
@ -57,20 +57,15 @@ function M.spawn(cmd, opts)
opts = opts or {} opts = opts or {}
opts.timeout = opts.timeout or (Config.options.git and Config.options.git.timeout * 1000) opts.timeout = opts.timeout or (Config.options.git and Config.options.git.timeout * 1000)
local env = { local env = vim.tbl_extend("force", {
"GIT_TERMINAL_PROMPT=0", GIT_SSH_COMMAND = "ssh -oBatchMode=yes",
"GIT_SSH_COMMAND=ssh -oBatchMode=yes", }, uv.os_environ(), opts.env or {})
} env.GIT_DIR = nil
if opts.env then env.GIT_TERMINAL_PROMPT = "0"
vim.list_extend(env, opts.env)
end
for key, value in local env_flat = {}
pairs(uv.os_environ() --[[@as string[] ]]) for k, v in pairs(env) do
do env_flat[#env_flat + 1] = k .. "=" .. v
if key ~= "GIT_DIR" then
table.insert(env, key .. "=" .. value)
end
end end
local stdout = uv.new_pipe() local stdout = uv.new_pipe()
@ -95,7 +90,7 @@ function M.spawn(cmd, opts)
stdio = { nil, stdout, stderr }, stdio = { nil, stdout, stderr },
args = opts.args, args = opts.args,
cwd = opts.cwd, cwd = opts.cwd,
env = env, env = env_flat,
}, function(exit_code, signal) }, function(exit_code, signal)
M.running[handle] = nil M.running[handle] = nil
if timeout then if timeout then