Skip to content

Commit 3aa1192

Browse files
committed
use fast impl of anything_staged/anything_unstaged
1 parent 83e72fc commit 3aa1192

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lua/neogit/lib/git/status.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ end
251251

252252
---@return boolean
253253
function M.anything_staged()
254+
local fast = config.values.commit_editor.fast or false
255+
if fast then
256+
return git.repo.state.staged.items[1] ~= nil
257+
end
258+
254259
local output = git.cli.status.porcelain(2).call({ hidden = true }).stdout
255260
return vim.iter(output):any(function(line)
256261
return line:match("^%d [^%.]")
@@ -259,6 +264,11 @@ end
259264

260265
---@return boolean
261266
function M.anything_unstaged()
267+
local fast = config.values.commit_editor.fast or false
268+
if fast then
269+
return git.repo.state.unstaged.items[1] ~= nil
270+
end
271+
262272
local output = git.cli.status.porcelain(2).call({ hidden = true }).stdout
263273
return vim.iter(output):any(function(line)
264274
return line:match("^%d %..")

lua/neogit/popups/commit/actions.lua

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ local function do_commit(popup, cmd)
5050
end
5151

5252
local function commit_special(popup, method, opts)
53-
if not git.status.anything_staged() and not allow_empty(popup) then
53+
if not allow_empty(popup) and not git.status.anything_staged() then
5454
if git.status.anything_unstaged() then
5555
if input.get_permission("Nothing is staged. Commit all uncommitted changed?") then
5656
opts.all = true
@@ -110,11 +110,9 @@ local function commit_special(popup, method, opts)
110110
end
111111

112112
function M.commit(popup)
113-
if not config.values.commit_editor.fast then
114-
if not git.status.anything_staged() and not allow_empty(popup) then
115-
notification.warn("No changes to commit.")
116-
return
117-
end
113+
if not allow_empty(popup) and not git.status.anything_staged() then
114+
notification.warn("No changes to commit.")
115+
return
118116
end
119117

120118
do_commit(popup, git.cli.commit)

0 commit comments

Comments
 (0)