fix(git): guard the commit-editor :edit against silent failure

This commit is contained in:
2026-04-27 14:23:47 +02:00
parent 641d208d78
commit f653d8eafe
+13 -1
View File
@@ -34,8 +34,20 @@ function M.commit(opts)
f:write(initial)
f:close()
vim.cmd("edit " .. vim.fn.fnameescape(msg_path))
local ok, err = pcall(vim.cmd, "edit " .. vim.fn.fnameescape(msg_path))
if not ok then
log.error("failed to open %s: %s", msg_path, err or "")
return
end
local buf = vim.api.nvim_get_current_buf()
if vim.api.nvim_buf_get_name(buf) ~= msg_path then
-- `:edit` returned without surfacing an error but didn't actually
-- switch (defensive against an unusual ftplugin/autocmd path). Bail
-- before attaching a BufWriteCmd that would overwrite the wrong
-- file on the next `:w`.
log.error("failed to switch to %s", msg_path)
return
end
vim.bo[buf].filetype = "gitcommit"
vim.api.nvim_create_autocmd("BufWriteCmd", {