Skip to content

Commit

Permalink
Fix: Commit --allow-empty shouldn't return early because you have no
Browse files Browse the repository at this point in the history
changes staged. Thats the whole point...
  • Loading branch information
CKolkey committed Dec 8, 2024
1 parent ed01faa commit 568415f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lua/neogit/popups/commit/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ local notification = require("neogit.lib.notification")
local config = require("neogit.config")
local a = require("plenary.async")

---@param popup PopupData
---@return boolean
local function allow_empty(popup)
return vim.tbl_contains(popup:get_arguments(), "--allow-empty")
end

local function confirm_modifications()
if
git.branch.upstream()
Expand Down Expand Up @@ -37,7 +43,7 @@ local function do_commit(popup, cmd)
end

local function commit_special(popup, method, opts)
if not git.status.anything_staged() then
if not git.status.anything_staged() and not allow_empty(popup) then
if git.status.anything_unstaged() then
if input.get_permission("Nothing is staged. Commit all uncommitted changed?") then
opts.all = true
Expand Down Expand Up @@ -97,7 +103,7 @@ local function commit_special(popup, method, opts)
end

function M.commit(popup)
if not git.status.anything_staged() then
if not git.status.anything_staged() and not allow_empty(popup) then
notification.warn("No changes to commit.")
return
end
Expand All @@ -106,7 +112,7 @@ function M.commit(popup)
end

function M.extend(popup)
if not git.status.anything_staged() then
if not git.status.anything_staged() and not allow_empty(popup) then
if git.status.anything_unstaged() then
if input.get_permission("Nothing is staged. Commit all uncommitted changes?") then
git.status.stage_modified()
Expand Down Expand Up @@ -175,7 +181,7 @@ function M.absorb(popup)
return
end

if not git.status.anything_staged() then
if not git.status.anything_staged() and not allow_empty(popup) then
if git.status.anything_unstaged() then
if input.get_permission("Nothing is staged. Absorb all unstaged changes?") then
git.status.stage_modified()
Expand Down

0 comments on commit 568415f

Please sign in to comment.