From d40d801053f2f4a50514739969578a788c6fe48b Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Sat, 24 Dec 2022 15:48:50 -0600 Subject: feat(nvim,neogit): manually impl pr until it is merged Refs: #415 --- nvim/.config/nvim/lua/tobyvin/plugins/neogit.lua | 71 +++++++++++++++++++++--- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/neogit.lua b/nvim/.config/nvim/lua/tobyvin/plugins/neogit.lua index 68d1457..008d920 100644 --- a/nvim/.config/nvim/lua/tobyvin/plugins/neogit.lua +++ b/nvim/.config/nvim/lua/tobyvin/plugins/neogit.lua @@ -1,13 +1,6 @@ local M = { "TimUntersberger/neogit", dependencies = { "sindrets/diffview.nvim" }, - config = { - disable_commit_confirmation = true, - disable_signs = true, - integrations = { - diffview = true, - }, - }, } function M.init() @@ -16,4 +9,68 @@ function M.init() end, { desc = "neogit" }) end +function M.config() + -- TODO: revert once pr is merged + -- + -- Refs: #415 + local Buffer = require("neogit.lib.buffer") + local config = require("neogit.config") + local input = require("neogit.lib.input") + + local CommitEditor = require("neogit.buffers.commit_editor") + function CommitEditor:open() + local written = false + self.buffer = Buffer.create({ + name = self.filename, + filetype = "gitcommit", + buftype = "", + kind = config.values.commit_popup.kind, + modifiable = true, + readonly = false, + autocmds = { + ["BufWritePost"] = function() + written = true + end, + ["BufUnload"] = function() + if written then + if + config.values.disable_commit_confirmation + or input.get_confirmation("Are you sure you want to commit?") + then + vim.cmd("silent g/^#/d | silent w!") + end + end + if self.on_unload then + self.on_unload(written) + end + require("neogit.process").defer_show_preview_buffers() + end, + }, + mappings = { + n = { + ["q"] = function(buffer) + buffer:close(true) + end, + }, + }, + initialize = function(buffer) + buffer:set_lines(0, -1, false, self.content) + if not config.values.disable_insert_on_commit then + vim.cmd(":startinsert") + end + -- NOTE: This avoids the user having to force to save the contents of the buffer. + vim.cmd("silent w!") + end, + }) + end + + require("neogit").setup({ + disable_commit_confirmation = true, + disable_signs = true, + integrations = { + diffview = true, + }, + }) +end + return M -- cgit v1.2.3-70-g09d2