Skip to content

Commit

Permalink
Merge pull request #602 from NeogitOrg/confirm-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey authored Jul 15, 2023
2 parents 4c6a51d + 64e34e1 commit 33016ad
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions lua/neogit/popups/commit/actions.lua
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
local M = {}

local notif = require("neogit.lib.notification")
local CommitSelectViewBuffer = require("neogit.buffers.commit_select_view")
local git = require("neogit.lib.git")
local client = require("neogit.client")
local input = require("neogit.lib.input")
local a = require("plenary.async")

local function do_commit(popup, cmd)
a.util.scheduler()

local notification = notif.create("Committing...", vim.log.levels.INFO, 9999)

local client = require("neogit.client")
local envs = client.get_envs_git_editor()

local result = cmd.env(envs).args(unpack(popup:get_arguments())):in_pty(true).call(true):trim()

a.util.scheduler()
if notification then
notification:delete()
end

if result.code == 0 then
notif.create("Successfully committed!")
vim.api.nvim_exec_autocmds("User", { pattern = "NeogitCommitComplete", modeline = false })
local function confirm_modifications()
if
#git.repo.unmerged.items < 1
and not input.get_confirmation(
string.format(
"This commit has already been published to %s, do you really want to modify it?",
git.repo.upstream.ref
),
{ values = { "&Yes", "&No" }, default = 2 }
)
then
return false
end

a.util.scheduler()
return true
end

require("neogit.status").refresh(true, "do_commit")
local function do_commit(popup, cmd)
client.wrap(cmd.arg_list(popup:get_arguments()), {
autocmd = "NeogitCommitComplete",
msg = {
setup = "Committing...",
success = "Committed!",
fail = "Couldn't commit",
},
})
end

local function commit_special(popup, method)
Expand All @@ -48,14 +52,26 @@ function M.commit(popup)
end

function M.extend(popup)
if not confirm_modifications() then
return
end

do_commit(popup, git.cli.commit.no_edit.amend)
end

function M.reword(popup)
if not confirm_modifications() then
return
end

do_commit(popup, git.cli.commit.amend.only)
end

function M.amend(popup)
if not confirm_modifications() then
return
end

do_commit(popup, git.cli.commit.amend)
end

Expand Down

0 comments on commit 33016ad

Please sign in to comment.