diff --git a/README.md b/README.md index 4e3bcdbe3..c92e462b6 100644 --- a/README.md +++ b/README.md @@ -101,13 +101,7 @@ neogit.setup { -- Scope persisted settings on a per-project basis use_per_project_settings = true, -- Table of settings to never persist. Uses format "Filetype--cli-value" - ignored_settings = { - "NeogitPushPopup--force-with-lease", - "NeogitPushPopup--force", - "NeogitPullPopup--rebase", - "NeogitCommitPopup--allow-empty", - "NeogitRevertPopup--no-edit", - }, + ignored_settings = {}, -- Configure highlight group features highlight = { italic = true, diff --git a/doc/neogit.txt b/doc/neogit.txt index 3c0827b3c..024b59b16 100644 --- a/doc/neogit.txt +++ b/doc/neogit.txt @@ -128,13 +128,7 @@ to Neovim users. -- Scope persisted settings on a per-project basis use_per_project_settings = true, -- Table of settings to never persist. Uses format "Filetype--cli-value" - ignored_settings = { - "NeogitPushPopup--force-with-lease", - "NeogitPushPopup--force", - "NeogitPullPopup--rebase", - "NeogitCommitPopup--allow-empty", - "NeogitRevertPopup--no-edit", - }, + ignored_settings = {}, -- Configure highlight group features highlight = { italic = true, @@ -2144,5 +2138,21 @@ calling the setup function: }, }) < + +You can also customize existing popups via the Neogit config. +Below is an example of adding a custom switch, but you can use any function +from the builder API. +>lua + require("neogit").setup({ + builders = { + NeogitPushPopup = function(builder) + builder:switch('m', 'merge_request.create', 'Create merge request', { cli_prefix = '-o ', persisted = false }) + end, + }, + }) + +Keep in mind that builder hooks are executed at the end of the popup +builder, so any switches or options added will be placed at the end. + ------------------------------------------------------------------------------ vim:tw=78:ts=8:ft=help:norl: diff --git a/lua/neogit/config.lua b/lua/neogit/config.lua index 5c36209e8..1eb4593bf 100644 --- a/lua/neogit/config.lua +++ b/lua/neogit/config.lua @@ -369,6 +369,7 @@ end ---@field notification_icon? string ---@field use_default_keymaps? boolean ---@field highlight? HighlightOptions +---@field builders? { [string]: fun(builder: PopupBuilder) } ---Returns the default Neogit configuration ---@return NeogitConfig @@ -550,13 +551,7 @@ function M.get_default_values() hidden = false, }, }, - ignored_settings = { - "NeogitPushPopup--force-with-lease", - "NeogitPushPopup--force", - "NeogitPullPopup--rebase", - "NeogitPullPopup--force", - "NeogitCommitPopup--allow-empty", - }, + ignored_settings = {}, mappings = { commit_editor = { ["q"] = "Close", diff --git a/lua/neogit/lib/popup/builder.lua b/lua/neogit/lib/popup/builder.lua index 2a10b9da4..cd2920425 100644 --- a/lua/neogit/lib/popup/builder.lua +++ b/lua/neogit/lib/popup/builder.lua @@ -2,6 +2,7 @@ local git = require("neogit.lib.git") local state = require("neogit.lib.state") local util = require("neogit.lib.util") local notification = require("neogit.lib.notification") +local config = require("neogit.config") ---@class PopupBuilder ---@field state PopupState @@ -54,6 +55,7 @@ local M = {} ---@field type string ---@field user_input boolean ---@field value string? +---@field persisted? boolean ---@class PopupConfig ---@field id string @@ -90,6 +92,7 @@ local M = {} ---@field value? string Allows for pre-building cli flags that can be customized by user input ---@field user_input? boolean If true, allows user to customize the value of the cli flag ---@field dependent? string[] other switches/options with a state dependency on this one +---@field persisted? boolean Allows overwriting the default 'true' to decide if this switch should be persisted ---@class PopupOptionOpts ---@field key_prefix? string Allows overwriting the default '=' to set option @@ -222,6 +225,10 @@ function M:switch(key, cli, description, opts) opts.cli_suffix = "" end + if opts.persisted == nil then + opts.persisted = true + end + local value if opts.enabled and opts.value then value = cli .. opts.value @@ -253,6 +260,7 @@ function M:switch(key, cli, description, opts) cli_prefix = opts.cli_prefix, user_input = opts.user_input, cli_suffix = opts.cli_suffix, + persisted = opts.persisted, options = opts.options, incompatible = util.build_reverse_lookup(opts.incompatible), dependent = util.build_reverse_lookup(opts.dependent), @@ -467,6 +475,10 @@ function M:build() error("A popup needs to have a name!") end + if config.values.builders ~= nil and type(config.values.builders[self.state.name]) == "function" then + config.values.builders[self.state.name](self) + end + return self.builder_fn(self.state) end diff --git a/lua/neogit/lib/popup/init.lua b/lua/neogit/lib/popup/init.lua index 3d95c5820..e88bb6dd3 100644 --- a/lua/neogit/lib/popup/init.lua +++ b/lua/neogit/lib/popup/init.lua @@ -108,7 +108,10 @@ function M:toggle_switch(switch) switch.cli = options[(index + 1)] or options[1] switch.value = switch.cli switch.enabled = switch.cli ~= "" - state.set({ self.state.name, switch.cli_suffix }, switch.cli) + + if switch.persisted ~= false then + state.set({ self.state.name, switch.cli_suffix }, switch.cli) + end return end @@ -127,7 +130,9 @@ function M:toggle_switch(switch) end end - state.set({ self.state.name, switch.cli }, switch.enabled) + if switch.persisted ~= false then + state.set({ self.state.name, switch.cli }, switch.enabled) + end -- Ensure that other switches/options that are incompatible with this one are disabled if switch.enabled and #switch.incompatible > 0 then diff --git a/lua/neogit/popups/commit/init.lua b/lua/neogit/popups/commit/init.lua index 6b9223519..7885281ce 100644 --- a/lua/neogit/popups/commit/init.lua +++ b/lua/neogit/popups/commit/init.lua @@ -8,7 +8,7 @@ function M.create(env) .builder() :name("NeogitCommitPopup") :switch("a", "all", "Stage all modified and deleted files") - :switch("e", "allow-empty", "Allow empty commit") + :switch("e", "allow-empty", "Allow empty commit", { persisted = false }) :switch("v", "verbose", "Show diff of changes to be committed") :switch("h", "no-verify", "Disable hooks") :switch("R", "reset-author", "Claim authorship and reset author date") diff --git a/lua/neogit/popups/fetch/init.lua b/lua/neogit/popups/fetch/init.lua index 2a3371eb6..8fa17f70e 100644 --- a/lua/neogit/popups/fetch/init.lua +++ b/lua/neogit/popups/fetch/init.lua @@ -10,7 +10,7 @@ function M.create() :name("NeogitFetchPopup") :switch("p", "prune", "Prune deleted branches") :switch("t", "tags", "Fetch all tags") - :switch("F", "force", "force") + :switch("F", "force", "force", { persisted = false }) :group_heading("Fetch from") :action("p", git.branch.pushRemote_remote_label(), actions.fetch_pushremote) :action("u", git.branch.upstream_remote_label(), actions.fetch_upstream) diff --git a/lua/neogit/popups/pull/init.lua b/lua/neogit/popups/pull/init.lua index 17635cc0a..a1da91f69 100755 --- a/lua/neogit/popups/pull/init.lua +++ b/lua/neogit/popups/pull/init.lua @@ -21,10 +21,10 @@ function M.create() }, }) :switch("f", "ff-only", "Fast-forward only") - :switch("r", "rebase", "Rebase local commits") + :switch("r", "rebase", "Rebase local commits", { persisted = false }) :switch("a", "autostash", "Autostash") :switch("t", "tags", "Fetch tags") - :switch("F", "force", "Force") + :switch("F", "force", "Force", { persisted = false }) :group_heading_if(current ~= nil, "Pull into " .. current .. " from") :group_heading_if(not current, "Pull from") :action_if(current ~= nil, "p", git.branch.pushRemote_label(), actions.from_pushremote) diff --git a/lua/neogit/popups/push/init.lua b/lua/neogit/popups/push/init.lua index 72a03fb7c..6b6124154 100644 --- a/lua/neogit/popups/push/init.lua +++ b/lua/neogit/popups/push/init.lua @@ -10,8 +10,8 @@ function M.create(env) local p = popup .builder() :name("NeogitPushPopup") - :switch("f", "force-with-lease", "Force with lease") - :switch("F", "force", "Force") + :switch("f", "force-with-lease", "Force with lease", { persisted = false }) + :switch("F", "force", "Force", { persisted = false }) :switch("h", "no-verify", "Disable hooks") :switch("d", "dry-run", "Dry run") :switch("u", "set-upstream", "Set the upstream before pushing") diff --git a/lua/neogit/popups/tag/init.lua b/lua/neogit/popups/tag/init.lua index 994a32a4b..c7bbef5e7 100644 --- a/lua/neogit/popups/tag/init.lua +++ b/lua/neogit/popups/tag/init.lua @@ -8,7 +8,7 @@ function M.create(env) .builder() :name("NeogitTagPopup") :arg_heading("Arguments") - :switch("f", "force", "Force") + :switch("f", "force", "Force", { persisted = false }) :switch("a", "annotate", "Annotate") :switch("s", "sign", "Sign") :option("u", "local-user", "", "Sign as", { key_prefix = "-" })