Skip to content

Commit

Permalink
Merge pull request #607 from treatybreaker/fix/commit-message-q
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey authored Jul 18, 2023
2 parents 10eaae0 + f916308 commit 7240327
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions lua/neogit/buffers/commit_editor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function M.new(filename, on_unload)
end

function M:open()
local written = false
local should_commit = false
self.buffer = Buffer.create {
name = self.filename,
filetype = "NeogitCommitMessage",
Expand All @@ -40,25 +40,25 @@ function M:open()
modifiable = true,
readonly = false,
autocmds = {
["BufWritePre"] = function()
written = true
end,
["BufUnload"] = function(o)
if written then
local buf = Buffer.create {
name = o.buf,
}
if not should_commit and buf:get_option("modified") then
if
not config.values.disable_commit_confirmation
and not input.get_confirmation("Are you sure you want to commit?")
then
-- Clear the buffer, without filling the register
vim.api.nvim_buf_set_lines(o.buf, 0, -1, false, {})
vim.api.nvim_buf_call(o.buf, function()
buf:set_lines(0, -1, false, {})
buf:call(function()
vim.cmd("silent w!")
end)
end
end

if self.on_unload then
self.on_unload(written)
if self.on_unload and not should_commit then
self.on_unload(true)
end

require("neogit.process").defer_show_preview_buffers()
Expand All @@ -67,7 +67,12 @@ function M:open()
mappings = {
n = {
["q"] = function(buffer)
buffer:close(true)
if not buffer:get_option("modified") then
buffer:close(true)
elseif input.get_confirmation("Commit message hasn't been saved. Abort?") then
should_commit = true
buffer:close(true)
end
end,
},
},
Expand Down
2 changes: 1 addition & 1 deletion lua/neogit/lib/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function Buffer:unlock()
end

function Buffer:get_option(name)
api.nvim_buf_get_option(self.handle, name)
return api.nvim_buf_get_option(self.handle, name)
end

function Buffer:set_option(name, value)
Expand Down

0 comments on commit 7240327

Please sign in to comment.