Skip to content

Commit 76413e1

Browse files
committed
feat: add prompt_force_push option
Allows users to disable the prompt to force push when branches diverge.
1 parent 12f78aa commit 76413e1

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ neogit.setup {
7373
disable_context_highlighting = false,
7474
-- Disables signs for sections/items/hunks
7575
disable_signs = false,
76+
-- Offer to force push when branches diverge
77+
prompt_force_push = true,
7678
-- Changes what mode the Commit Editor starts in. `true` will leave nvim in normal mode, `false` will change nvim to
7779
-- insert mode, and `"auto"` will change nvim to insert mode IF the commit message is empty, otherwise leaving it in
7880
-- normal mode.

doc/neogit.txt

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ to Neovim users.
9292
disable_context_highlighting = false,
9393
-- Disables signs for sections/items/hunks
9494
disable_signs = false,
95+
-- Offer to force push when branches diverge
96+
prompt_force_push = true,
9597
-- Changes what mode the Commit Editor starts in. `true` will leave nvim in normal mode, `false` will change nvim to
9698
-- insert mode, and `"auto"` will change nvim to insert mode IF the commit message is empty, otherwise leaving it in
9799
-- normal mode.

lua/neogit/config.lua

+2
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ end
309309
---@field disable_hint? boolean Remove the top hint in the Status buffer
310310
---@field disable_context_highlighting? boolean Disable context highlights based on cursor position
311311
---@field disable_signs? boolean Special signs to draw for sections etc. in Neogit
312+
---@field prompt_force_push? boolean Offer to force push when branches diverge
312313
---@field git_services? table Templartes to use when opening a pull request for a branch
313314
---@field fetch_after_checkout? boolean Perform a fetch if the newly checked out branch has an upstream or pushRemote set
314315
---@field telescope_sorter? function The sorter telescope will use
@@ -356,6 +357,7 @@ function M.get_default_values()
356357
disable_hint = false,
357358
disable_context_highlighting = false,
358359
disable_signs = false,
360+
prompt_force_push = true,
359361
graph_style = "ascii",
360362
commit_date_format = nil,
361363
log_date_format = nil,

lua/neogit/popups/push/actions.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local logger = require("neogit.logger")
44
local notification = require("neogit.lib.notification")
55
local input = require("neogit.lib.input")
66
local util = require("neogit.lib.util")
7+
local config = require("neogit.config")
78

89
local FuzzyFinderBuffer = require("neogit.buffers.fuzzy_finder")
910

@@ -41,8 +42,8 @@ local function push_to(args, remote, branch, opts)
4142
local using_force = vim.tbl_contains(args, "--force") or vim.tbl_contains(args, "--force-with-lease")
4243
local updates_rejected = string.find(table.concat(res.stdout), "Updates were rejected") ~= nil
4344

44-
-- Only ask the user whether to force push if not already specified
45-
if res and res.code ~= 0 and not using_force and updates_rejected then
45+
-- Only ask the user whether to force push if not already specified and feature enabled
46+
if res and res.code ~= 0 and not using_force and updates_rejected and config.values.prompt_force_push then
4647
logger.error("Attempting force push to " .. name)
4748

4849
local message = "Your branch has diverged from the remote branch. Do you want to force push?"

0 commit comments

Comments
 (0)