chore(git): consistent error reporting on git failures

This commit is contained in:
2026-04-27 13:33:09 +02:00
parent 20dc6cc3c9
commit 6e0e05ae56
5 changed files with 81 additions and 14 deletions
+45 -4
View File
@@ -145,6 +145,9 @@ local function fetch_status(worktree, callback)
Unpushed = {},
Unpulled = {},
}
if obj.code ~= 0 then
log.error("git status failed: %s", vim.trim(obj.stderr or ""))
end
if obj.code == 0 then
for line in (obj.stdout or ""):gmatch("[^\r\n]+") do
if line:sub(1, 2) == "##" then
@@ -237,6 +240,12 @@ local function fetch_status(worktree, callback)
})
end
end
else
log.error(
"git log %s failed: %s",
f.range,
vim.trim(log_obj.stderr or "")
)
end
pending = pending - 1
if pending == 0 then
@@ -643,7 +652,17 @@ local function action_stage()
if entry.section == "Staged" then
return
end
vim.system({ "git", "add", "--", entry.path }, { cwd = s.worktree })
vim.system(
{ "git", "add", "--", entry.path },
{ cwd = s.worktree },
function(obj)
if obj.code ~= 0 then
vim.schedule(function()
log.error("git add failed: %s", vim.trim(obj.stderr or ""))
end)
end
end
)
end
local function action_unstage()
@@ -660,7 +679,16 @@ local function action_unstage()
table.insert(cmd, entry.orig)
end
table.insert(cmd, entry.path)
vim.system(cmd, { cwd = s.worktree })
vim.system(cmd, { cwd = s.worktree }, function(obj)
if obj.code ~= 0 then
vim.schedule(function()
log.error(
"git restore --staged failed: %s",
vim.trim(obj.stderr or "")
)
end)
end
end)
end
local function action_discard()
@@ -678,7 +706,10 @@ local function action_discard()
if entry.section == "Untracked" then
prompt = string.format("Delete untracked file %s?", entry.path)
action = function()
os.remove(vim.fs.joinpath(s.worktree, entry.path))
local ok, err = os.remove(vim.fs.joinpath(s.worktree, entry.path))
if not ok then
log.error("failed to remove %s: %s", entry.path, err or "")
end
refresh(vim.api.nvim_get_current_buf())
end
elseif entry.section == "Unstaged" then
@@ -686,7 +717,17 @@ local function action_discard()
action = function()
vim.system(
{ "git", "checkout", "--", entry.path },
{ cwd = s.worktree }
{ cwd = s.worktree },
function(obj)
if obj.code ~= 0 then
vim.schedule(function()
log.error(
"git checkout failed: %s",
vim.trim(obj.stderr or "")
)
end)
end
end
)
end
else