Skip to content

Commit

Permalink
refactor: get user confirmation for aborting a commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PriceHiller committed Jul 15, 2023
1 parent 2b99f1b commit 40c665b
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions lua/neogit/buffers/commit_editor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function M.new(filename, on_unload)
end

function M:open()
local commit_aborted = false
local written = false
self.buffer = Buffer.create {
name = self.filename,
Expand All @@ -40,11 +41,8 @@ function M:open()
modifiable = true,
readonly = false,
autocmds = {
["BufWritePre"] = function()
written = true
end,
["BufUnload"] = function(o)
if written then
if not commit_aborted and written then
if
not config.values.disable_commit_confirmation
and not input.get_confirmation("Are you sure you want to commit?")
Expand All @@ -57,8 +55,8 @@ function M:open()
end
end

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

require("neogit.process").defer_show_preview_buffers()
Expand All @@ -67,13 +65,11 @@ function M:open()
mappings = {
n = {
["q"] = function(buffer)
if buffer:get_option("modified") then
require("neogit.lib.notification").create(
"Commit message has not been saved! Try `:w`.",
vim.log.levels.WARN
)
else
self:close()
if not buffer:get_option("modified") then
written = true
buffer:close(true)
elseif input.get_confirmation("Commit message hasn't been saved. Abort?") then
commit_aborted = true
buffer:close(true)
end
end,
Expand Down

0 comments on commit 40c665b

Please sign in to comment.