feat(git): highlight only fatal/error lines in failure dump

This commit is contained in:
2026-05-09 00:25:10 +02:00
parent 295803779a
commit 9bbbd1b1c8
2 changed files with 51 additions and 17 deletions
+28 -3
View File
@@ -321,6 +321,32 @@ local function clean_progress_line(line)
return ""
end
---@param lines string[]
---@param fallback string
---@return [string, string?][]
local function format_error_dump(lines, fallback)
if #lines == 0 then
return { { fallback, "ErrorMsg" } }
end
local chunks = {}
local matched = false
for i, line in ipairs(lines) do
if i > 1 then
table.insert(chunks, { "\n" })
end
if line:match("^fatal:") or line:match("^error:") then
table.insert(chunks, { line, "ErrorMsg" })
matched = true
else
table.insert(chunks, { line })
end
end
if not matched then
return { { table.concat(lines, "\n"), "ErrorMsg" } }
end
return chunks
end
---@param r ow.Git.Repo
---@param args string[]
local function run_streaming(r, args)
@@ -387,9 +413,8 @@ local function run_streaming(r, args)
)
else
emit_progress(("exit %d"):format(code), "failed")
local body = #accum > 0 and table.concat(accum, "\n")
or ("%s failed: exit %d"):format(title, code)
vim.api.nvim_echo({ { body, "ErrorMsg" } }, true, {})
local fallback = ("%s failed: exit %d"):format(title, code)
vim.api.nvim_echo(format_error_dump(accum, fallback), true, {})
end
end