From f653d8eafe625eb107026e3a3c8eefbc6e2ed3f7 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Mon, 27 Apr 2026 14:23:47 +0200 Subject: [PATCH] fix(git): guard the commit-editor :edit against silent failure --- lua/git/commit.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/git/commit.lua b/lua/git/commit.lua index 4c07382..3a51e7f 100644 --- a/lua/git/commit.lua +++ b/lua/git/commit.lua @@ -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", {