refactor(git): make the git module self-contained under git.util

This commit is contained in:
2026-04-28 09:05:01 +02:00
parent 4390b55dfe
commit 37e5582795
10 changed files with 195 additions and 75 deletions
-25
View File
@@ -441,29 +441,4 @@ function M.split_lines(content)
return lines
end
---Run a system command synchronously and return stdout on success. On
---non-zero exit, logs stderr via `log.error` and returns nil. Pass
---`opts.silent` to suppress the auto-log when failure is expected (e.g.
---probe-style commands like `git rev-parse` against a possibly-missing
---ref).
---@param cmd string[]
---@param opts { cwd: string?, stdin: string?, silent: boolean? }?
---@return string?
function M.system_sync(cmd, opts)
opts = opts or {}
local result = vim.system(cmd, {
cwd = opts.cwd,
stdin = opts.stdin,
text = true,
}):wait()
if result.code ~= 0 then
if not opts.silent then
local label = cmd[2] and (cmd[1] .. " " .. cmd[2]) or cmd[1] or "?"
log.error("%s failed: %s", label, vim.trim(result.stderr or ""))
end
return nil
end
return result.stdout or ""
end
return M