Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lua/neogit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ end
---@class NeogitCommitEditorConfigPopup Popup window options
---@field kind WindowKind The type of window that should be opened
---@field show_staged_diff? boolean Display staged changes in a buffer when committing
---@field fast? boolean Enter commit message in a non-interactive way (much faster in large repositories)
---@field staged_diff_split_kind? StagedDiffSplitKind Whether to show staged changes in a vertical or horizontal split
---@field spell_check? boolean Enable/Disable spell checking

Expand Down
11 changes: 11 additions & 0 deletions lua/neogit/lib/git/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local git = require("neogit.lib.git")
local util = require("neogit.lib.util")
local Collection = require("neogit.lib.collection")
local logger = require("neogit.logger")
local config = require("neogit.config")

---@class StatusItem
---@field mode string
Expand Down Expand Up @@ -251,6 +252,11 @@ end

---@return boolean
function M.anything_staged()
local fast = config.values.commit_editor.fast or false
if fast then
return git.repo.state.staged.items[1] ~= nil
end

local output = git.cli.status.porcelain(2).call({ hidden = true }).stdout
return vim.iter(output):any(function(line)
return line:match("^%d [^%.]")
Expand All @@ -259,6 +265,11 @@ end

---@return boolean
function M.anything_unstaged()
local fast = config.values.commit_editor.fast or false
if fast then
return git.repo.state.unstaged.items[1] ~= nil
end

local output = git.cli.status.porcelain(2).call({ hidden = true }).stdout
return vim.iter(output):any(function(line)
return line:match("^%d %..")
Expand Down
4 changes: 2 additions & 2 deletions lua/neogit/popups/commit/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ local function do_commit(popup, cmd)
end

local function commit_special(popup, method, opts)
if not git.status.anything_staged() and not allow_empty(popup) then
if not allow_empty(popup) and not git.status.anything_staged() 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 @@ -105,7 +105,7 @@ local function commit_special(popup, method, opts)
end

function M.commit(popup)
if not git.status.anything_staged() and not allow_empty(popup) then
if not allow_empty(popup) and not git.status.anything_staged() then
notification.warn("No changes to commit.")
return
end
Expand Down
Loading