fix(git): guard the commit-editor :edit against silent failure
This commit is contained in:
+13
-1
@@ -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", {
|
||||
|
||||
Reference in New Issue
Block a user