From 83e72fca6a125da45fa44349db593c4aeca4fc90 Mon Sep 17 00:00:00 2001 From: benji Date: Sun, 9 Nov 2025 00:55:28 +0100 Subject: [PATCH 1/4] add fast commit --- lua/neogit/config.lua | 1 + lua/neogit/popups/commit/actions.lua | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) 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/popups/commit/actions.lua b/lua/neogit/popups/commit/actions.lua index 252922a3e..713938f36 100644 --- a/lua/neogit/popups/commit/actions.lua +++ b/lua/neogit/popups/commit/actions.lua @@ -33,13 +33,18 @@ local function confirm_modifications() end local function do_commit(popup, cmd) - client.wrap(cmd.arg_list(popup:get_arguments()), { + cmd.arg_list(popup:get_arguments()) + if config.values.commit_editor.fast then + local message = vim.fn.input("Commit message: ") + cmd.message(message) + end + client.wrap(cmd, { autocmd = "NeogitCommitComplete", msg = { success = "Committed", fail = "Commit failed", }, - interactive = true, + interactive = not config.values.commit_editor.fast, show_diff = config.values.commit_editor.show_staged_diff, }) end @@ -105,9 +110,11 @@ local function commit_special(popup, method, opts) end function M.commit(popup) - if not git.status.anything_staged() and not allow_empty(popup) then - notification.warn("No changes to commit.") - return + if not config.values.commit_editor.fast then + if not git.status.anything_staged() and not allow_empty(popup) then + notification.warn("No changes to commit.") + return + end end do_commit(popup, git.cli.commit) From 487687cd1deca0605877eb53781f45c5e40c92af Mon Sep 17 00:00:00 2001 From: benji Date: Mon, 17 Nov 2025 23:36:05 +0100 Subject: [PATCH 2/4] use fast impl of anything_staged/anything_unstaged --- lua/neogit/lib/git/status.lua | 11 +++++++++++ lua/neogit/popups/commit/actions.lua | 10 ++++------ 2 files changed, 15 insertions(+), 6 deletions(-) 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 713938f36..aa01cca95 100644 --- a/lua/neogit/popups/commit/actions.lua +++ b/lua/neogit/popups/commit/actions.lua @@ -50,7 +50,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 @@ -110,11 +110,9 @@ local function commit_special(popup, method, opts) end function M.commit(popup) - if not config.values.commit_editor.fast then - if not git.status.anything_staged() and not allow_empty(popup) then - notification.warn("No changes to commit.") - return - end + if not allow_empty(popup) and not git.status.anything_staged() then + notification.warn("No changes to commit.") + return end do_commit(popup, git.cli.commit) From b28d682884caccc45348360a52befdfdf2878fcc Mon Sep 17 00:00:00 2001 From: benji Date: Mon, 17 Nov 2025 23:54:37 +0100 Subject: [PATCH 3/4] revert special fast commit prompt --- lua/neogit/popups/commit/actions.lua | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lua/neogit/popups/commit/actions.lua b/lua/neogit/popups/commit/actions.lua index aa01cca95..400c948b2 100644 --- a/lua/neogit/popups/commit/actions.lua +++ b/lua/neogit/popups/commit/actions.lua @@ -33,12 +33,7 @@ local function confirm_modifications() end local function do_commit(popup, cmd) - cmd.arg_list(popup:get_arguments()) - if config.values.commit_editor.fast then - local message = vim.fn.input("Commit message: ") - cmd.message(message) - end - client.wrap(cmd, { + client.wrap(cmd.arg_list(popup:get_arguments()), { autocmd = "NeogitCommitComplete", msg = { success = "Committed", From d9025b0ceceeb3f67c8844db4d29585bd8d20882 Mon Sep 17 00:00:00 2001 From: benji Date: Tue, 18 Nov 2025 00:01:57 +0100 Subject: [PATCH 4/4] fix interactive --- lua/neogit/popups/commit/actions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/neogit/popups/commit/actions.lua b/lua/neogit/popups/commit/actions.lua index 400c948b2..c131d5f43 100644 --- a/lua/neogit/popups/commit/actions.lua +++ b/lua/neogit/popups/commit/actions.lua @@ -39,7 +39,7 @@ local function do_commit(popup, cmd) success = "Committed", fail = "Commit failed", }, - interactive = not config.values.commit_editor.fast, + interactive = true, show_diff = config.values.commit_editor.show_staged_diff, }) end