refactor(git): route every git invocation through util.git

This commit is contained in:
2026-05-08 03:44:23 +02:00
parent ebfcaef240
commit 01a543c12f
6 changed files with 115 additions and 132 deletions
+22 -32
View File
@@ -189,16 +189,7 @@ end
---@field cwd string?
---@field stdin string?
---@field silent boolean?
---@field on_done fun(stdout: string?)?
---@param args string[]
---@param opts ow.Git.Util.ExecOpts?
---@return string?
function M.git(args, opts)
local cmd = { "git" }
vim.list_extend(cmd, args)
return M.exec(cmd, opts)
end
---@field on_exit fun(result: vim.SystemCompleted)?
---@param cmd string[]
---@param opts ow.Git.Util.ExecOpts?
@@ -207,30 +198,29 @@ function M.exec(cmd, opts)
opts = opts or {}
local sys_opts = { cwd = opts.cwd, stdin = opts.stdin, text = true }
local function handle(result)
if result.code ~= 0 then
if not opts.silent then
local label = cmd[2] and (cmd[1] .. " " .. cmd[2])
or cmd[1]
or "?"
M.error("%s failed: %s", label, vim.trim(result.stderr or ""))
end
return nil
end
return result.stdout or ""
end
if opts.on_done then
vim.system(
cmd,
sys_opts,
vim.schedule_wrap(function(result)
opts.on_done(handle(result))
end)
)
if opts.on_exit then
vim.system(cmd, sys_opts, vim.schedule_wrap(opts.on_exit))
return nil
end
return handle(vim.system(cmd, sys_opts):wait())
local result = vim.system(cmd, sys_opts):wait()
if result.code ~= 0 then
if not opts.silent then
local label = cmd[2] and (cmd[1] .. " " .. cmd[2]) or cmd[1] or "?"
M.error("%s failed: %s", label, vim.trim(result.stderr or ""))
end
return nil
end
return result.stdout or ""
end
---@param args string[]
---@param opts ow.Git.Util.ExecOpts?
---@return string?
function M.git(args, opts)
local cmd = { "git" }
vim.list_extend(cmd, args)
return M.exec(cmd, opts)
end
---@class ow.Git.Util.Emitter<T>