diff --git a/lua/neogit/config.lua b/lua/neogit/config.lua index 69023ea4c..39f731543 100644 --- a/lua/neogit/config.lua +++ b/lua/neogit/config.lua @@ -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 diff --git a/lua/neogit/lib/git/status.lua b/lua/neogit/lib/git/status.lua index 6383393cb..5eef7eae6 100644 --- a/lua/neogit/lib/git/status.lua +++ b/lua/neogit/lib/git/status.lua @@ -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 @@ -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 [^%.]") @@ -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 %..") diff --git a/lua/neogit/popups/commit/actions.lua b/lua/neogit/popups/commit/actions.lua index 252922a3e..c131d5f43 100644 --- a/lua/neogit/popups/commit/actions.lua +++ b/lua/neogit/popups/commit/actions.lua @@ -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 @@ -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