From 377531fb487e4a4ca9fd317e46635970953344ec Mon Sep 17 00:00:00 2001 From: Anton Rogov Date: Wed, 21 May 2025 22:46:22 +0300 Subject: [PATCH 1/4] optional simple header for log view --- lua/neogit/buffers/log_view/init.lua | 5 +++-- lua/neogit/buffers/log_view/ui.lua | 4 ++-- lua/neogit/config.lua | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/neogit/buffers/log_view/init.lua b/lua/neogit/buffers/log_view/init.lua index 45aa1ed18..41056bb0b 100644 --- a/lua/neogit/buffers/log_view/init.lua +++ b/lua/neogit/buffers/log_view/init.lua @@ -79,7 +79,7 @@ function M:open() filetype = "NeogitLogView", kind = config.values.log_view.kind, context_highlight = false, - header = self.header, + header = not config.values.simple_headers and self.header or nil, scroll_header = false, active_item_highlight = true, status_column = not config.values.disable_signs and "" or nil, @@ -293,7 +293,8 @@ function M:open() }, }, render = function() - return ui.View(self.commits, self.remotes, self.internal_args) + local header = config.values.simple_headers and self.header or nil + return ui.View(self.commits, self.remotes, self.internal_args, header) end, after = function(buffer) -- First line is empty, so move cursor to second line. diff --git a/lua/neogit/buffers/log_view/ui.lua b/lua/neogit/buffers/log_view/ui.lua index e4f8e129f..e2a6f1200 100644 --- a/lua/neogit/buffers/log_view/ui.lua +++ b/lua/neogit/buffers/log_view/ui.lua @@ -14,7 +14,7 @@ local M = {} ---@param remotes string[] ---@param args table ---@return table -function M.View(commits, remotes, args) +function M.View(commits, remotes, args, header) args.details = true local graph = util.filter_map(commits, function(commit) @@ -25,7 +25,7 @@ function M.View(commits, remotes, args) end end) - table.insert(graph, 1, col { row { text("") } }) + table.insert(graph, 1, col { row { text(header or "") } }) table.insert( graph, diff --git a/lua/neogit/config.lua b/lua/neogit/config.lua index fd979e712..982ddde4e 100644 --- a/lua/neogit/config.lua +++ b/lua/neogit/config.lua @@ -330,6 +330,7 @@ end ---@field disable_hint? boolean Remove the top hint in the Status buffer ---@field disable_context_highlighting? boolean Disable context highlights based on cursor position ---@field disable_signs? boolean Special signs to draw for sections etc. in Neogit +---@field simple_headers? boolean Use text headers instead of windows ---@field prompt_force_push? boolean Offer to force push when branches diverge ---@field git_services? table Templartes to use when opening a pull request for a branch ---@field fetch_after_checkout? boolean Perform a fetch if the newly checked out branch has an upstream or pushRemote set @@ -378,6 +379,7 @@ function M.get_default_values() disable_hint = false, disable_context_highlighting = false, disable_signs = false, + simple_headers = false, prompt_force_push = true, graph_style = "ascii", commit_date_format = nil, @@ -1135,6 +1137,7 @@ function M.validate_config() validate_type(config.disable_hint, "disable_hint", "boolean") validate_type(config.disable_context_highlighting, "disable_context_highlighting", "boolean") validate_type(config.disable_signs, "disable_signs", "boolean") + validate_type(config.simple_headers, "simple_headers", "boolean") validate_type(config.telescope_sorter, "telescope_sorter", "function") validate_type(config.use_per_project_settings, "use_per_project_settings", "boolean") validate_type(config.remember_settings, "remember_settings", "boolean") From 0118744b1db28500095454389d20fd87b0c965fc Mon Sep 17 00:00:00 2001 From: Anton Rogov Date: Wed, 21 May 2025 22:47:29 +0300 Subject: [PATCH 2/4] config param to turn off --force-if-includes --- lua/neogit/config.lua | 3 +++ lua/neogit/popups/push/actions.lua | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/neogit/config.lua b/lua/neogit/config.lua index 982ddde4e..2a388b386 100644 --- a/lua/neogit/config.lua +++ b/lua/neogit/config.lua @@ -331,6 +331,7 @@ end ---@field disable_context_highlighting? boolean Disable context highlights based on cursor position ---@field disable_signs? boolean Special signs to draw for sections etc. in Neogit ---@field simple_headers? boolean Use text headers instead of windows +---@field force_if_includes? boolean Add --force-if-includes if --force-with-lease is set ---@field prompt_force_push? boolean Offer to force push when branches diverge ---@field git_services? table Templartes to use when opening a pull request for a branch ---@field fetch_after_checkout? boolean Perform a fetch if the newly checked out branch has an upstream or pushRemote set @@ -380,6 +381,7 @@ function M.get_default_values() disable_context_highlighting = false, disable_signs = false, simple_headers = false, + force_if_includes = true, prompt_force_push = true, graph_style = "ascii", commit_date_format = nil, @@ -1138,6 +1140,7 @@ function M.validate_config() validate_type(config.disable_context_highlighting, "disable_context_highlighting", "boolean") validate_type(config.disable_signs, "disable_signs", "boolean") validate_type(config.simple_headers, "simple_headers", "boolean") + validate_type(config.force_if_includes, "force_if_includes", "boolean") validate_type(config.telescope_sorter, "telescope_sorter", "function") validate_type(config.use_per_project_settings, "use_per_project_settings", "boolean") validate_type(config.remember_settings, "remember_settings", "boolean") diff --git a/lua/neogit/popups/push/actions.lua b/lua/neogit/popups/push/actions.lua index 4af6216e0..b884aa481 100644 --- a/lua/neogit/popups/push/actions.lua +++ b/lua/neogit/popups/push/actions.lua @@ -17,7 +17,7 @@ local function push_to(args, remote, branch, opts) table.insert(args, "--set-upstream") end - if vim.tbl_contains(args, "--force-with-lease") then + if config.values.force_if_includes and vim.tbl_contains(args, "--force-with-lease") then table.insert(args, "--force-if-includes") end From c80a53770ecd2db016c980b23dfb0ff343c397a3 Mon Sep 17 00:00:00 2001 From: Anton Rogov Date: Tue, 3 Jun 2025 11:21:12 +0300 Subject: [PATCH 3/4] option to turn off closing log view on esc --- lua/neogit/buffers/log_view/init.lua | 401 ++++++++++++++------------- lua/neogit/config.lua | 3 + 2 files changed, 206 insertions(+), 198 deletions(-) diff --git a/lua/neogit/buffers/log_view/init.lua b/lua/neogit/buffers/log_view/init.lua index 41056bb0b..61ab367b1 100644 --- a/lua/neogit/buffers/log_view/init.lua +++ b/lua/neogit/buffers/log_view/init.lua @@ -74,224 +74,229 @@ function M:open() M.instance = self - self.buffer = Buffer.create { - name = "NeogitLogView", - filetype = "NeogitLogView", - kind = config.values.log_view.kind, - context_highlight = false, - header = not config.values.simple_headers and self.header or nil, - scroll_header = false, - active_item_highlight = true, - status_column = not config.values.disable_signs and "" or nil, - mappings = { - v = { - [popups.mapping_for("CherryPickPopup")] = popups.open("cherry_pick", function(p) - p { commits = self.buffer.ui:get_commits_in_selection() } - end), - [popups.mapping_for("BranchPopup")] = popups.open("branch", function(p) - p { commits = self.buffer.ui:get_commits_in_selection() } - end), - [popups.mapping_for("CommitPopup")] = popups.open("commit", function(p) - p { commit = self.buffer.ui:get_commit_under_cursor() } - end), - [popups.mapping_for("FetchPopup")] = popups.open("fetch"), - [popups.mapping_for("MergePopup")] = popups.open("merge", function(p) - p { commit = self.buffer.ui:get_commit_under_cursor() } - end), - [popups.mapping_for("PushPopup")] = popups.open("push", function(p) - p { commit = self.buffer.ui:get_commit_under_cursor() } - end), - [popups.mapping_for("RebasePopup")] = popups.open("rebase", function(p) - p { commit = self.buffer.ui:get_commit_under_cursor() } - end), - [popups.mapping_for("RemotePopup")] = popups.open("remote"), - [popups.mapping_for("RevertPopup")] = popups.open("revert", function(p) - p { commits = self.buffer.ui:get_commits_in_selection() } - end), - [popups.mapping_for("ResetPopup")] = popups.open("reset", function(p) - p { commit = self.buffer.ui:get_commit_under_cursor() } - end), - [popups.mapping_for("TagPopup")] = popups.open("tag", function(p) - p { commit = self.buffer.ui:get_commit_under_cursor() } - end), - [popups.mapping_for("PullPopup")] = popups.open("pull"), - [popups.mapping_for("BisectPopup")] = popups.open("bisect", function(p) - p { commits = self.buffer.ui:get_commits_in_selection() } - end), - [popups.mapping_for("DiffPopup")] = popups.open("diff", function(p) - local items = self.buffer.ui:get_ordered_commits_in_selection() - p { - section = { name = "log" }, - item = { name = items }, - } - end), - }, - n = { - [popups.mapping_for("BisectPopup")] = popups.open("bisect", function(p) - p { commits = { self.buffer.ui:get_commit_under_cursor() } } - end), - [popups.mapping_for("CherryPickPopup")] = popups.open("cherry_pick", function(p) - p { commits = { self.buffer.ui:get_commit_under_cursor() } } - end), - [popups.mapping_for("BranchPopup")] = popups.open("branch", function(p) - p { commits = { self.buffer.ui:get_commit_under_cursor() } } - end), - [popups.mapping_for("CommitPopup")] = popups.open("commit", function(p) - p { commit = self.buffer.ui:get_commit_under_cursor() } - end), - [popups.mapping_for("FetchPopup")] = popups.open("fetch"), - [popups.mapping_for("MergePopup")] = popups.open("merge", function(p) - p { commit = self.buffer.ui:get_commit_under_cursor() } - end), - [popups.mapping_for("PushPopup")] = popups.open("push", function(p) - p { commit = self.buffer.ui:get_commit_under_cursor() } - end), - [popups.mapping_for("RebasePopup")] = popups.open("rebase", function(p) - p { commit = self.buffer.ui:get_commit_under_cursor() } - end), - [popups.mapping_for("RemotePopup")] = popups.open("remote"), - [popups.mapping_for("RevertPopup")] = popups.open("revert", function(p) - p { commits = { self.buffer.ui:get_commit_under_cursor() } } - end), - [popups.mapping_for("ResetPopup")] = popups.open("reset", function(p) - p { commit = self.buffer.ui:get_commit_under_cursor() } - end), - [popups.mapping_for("TagPopup")] = popups.open("tag", function(p) - p { commit = self.buffer.ui:get_commit_under_cursor() } - end), - [popups.mapping_for("DiffPopup")] = popups.open("diff", function(p) - local item = self.buffer.ui:get_commit_under_cursor() - p { - section = { name = "log" }, - item = { name = item }, - } - end), - [popups.mapping_for("PullPopup")] = popups.open("pull"), - [status_maps["YankSelected"]] = function() - local yank = self.buffer.ui:get_commit_under_cursor() - if yank then - yank = string.format("'%s'", yank) - vim.cmd.let("@+=" .. yank) - vim.cmd.echo(yank) - else - vim.cmd("echo ''") - end - end, - [""] = require("neogit.lib.ui.helpers").close_topmost(self), - [status_maps["Close"]] = require("neogit.lib.ui.helpers").close_topmost(self), - [status_maps["GoToFile"]] = function() - local commit = self.buffer.ui:get_commit_under_cursor() - if commit then - CommitViewBuffer.new(commit, self.files):open() - end - end, - [status_maps["PeekFile"]] = function() - local commit = self.buffer.ui:get_commit_under_cursor() - if commit then - CommitViewBuffer.new(commit, self.files):open() - self.buffer:focus() - end - end, - [status_maps["OpenOrScrollDown"]] = function() - local commit = self.buffer.ui:get_commit_under_cursor() - if commit then - CommitViewBuffer.open_or_scroll_down(commit, self.files) - end - end, - [status_maps["OpenOrScrollUp"]] = function() - local commit = self.buffer.ui:get_commit_under_cursor() - if commit then - CommitViewBuffer.open_or_scroll_up(commit, self.files) + local mappings = { + v = { + [popups.mapping_for("CherryPickPopup")] = popups.open("cherry_pick", function(p) + p { commits = self.buffer.ui:get_commits_in_selection() } + end), + [popups.mapping_for("BranchPopup")] = popups.open("branch", function(p) + p { commits = self.buffer.ui:get_commits_in_selection() } + end), + [popups.mapping_for("CommitPopup")] = popups.open("commit", function(p) + p { commit = self.buffer.ui:get_commit_under_cursor() } + end), + [popups.mapping_for("FetchPopup")] = popups.open("fetch"), + [popups.mapping_for("MergePopup")] = popups.open("merge", function(p) + p { commit = self.buffer.ui:get_commit_under_cursor() } + end), + [popups.mapping_for("PushPopup")] = popups.open("push", function(p) + p { commit = self.buffer.ui:get_commit_under_cursor() } + end), + [popups.mapping_for("RebasePopup")] = popups.open("rebase", function(p) + p { commit = self.buffer.ui:get_commit_under_cursor() } + end), + [popups.mapping_for("RemotePopup")] = popups.open("remote"), + [popups.mapping_for("RevertPopup")] = popups.open("revert", function(p) + p { commits = self.buffer.ui:get_commits_in_selection() } + end), + [popups.mapping_for("ResetPopup")] = popups.open("reset", function(p) + p { commit = self.buffer.ui:get_commit_under_cursor() } + end), + [popups.mapping_for("TagPopup")] = popups.open("tag", function(p) + p { commit = self.buffer.ui:get_commit_under_cursor() } + end), + [popups.mapping_for("PullPopup")] = popups.open("pull"), + [popups.mapping_for("BisectPopup")] = popups.open("bisect", function(p) + p { commits = self.buffer.ui:get_commits_in_selection() } + end), + [popups.mapping_for("DiffPopup")] = popups.open("diff", function(p) + local items = self.buffer.ui:get_ordered_commits_in_selection() + p { + section = { name = "log" }, + item = { name = items }, + } + end), + }, + n = { + [popups.mapping_for("BisectPopup")] = popups.open("bisect", function(p) + p { commits = { self.buffer.ui:get_commit_under_cursor() } } + end), + [popups.mapping_for("CherryPickPopup")] = popups.open("cherry_pick", function(p) + p { commits = { self.buffer.ui:get_commit_under_cursor() } } + end), + [popups.mapping_for("BranchPopup")] = popups.open("branch", function(p) + p { commits = { self.buffer.ui:get_commit_under_cursor() } } + end), + [popups.mapping_for("CommitPopup")] = popups.open("commit", function(p) + p { commit = self.buffer.ui:get_commit_under_cursor() } + end), + [popups.mapping_for("FetchPopup")] = popups.open("fetch"), + [popups.mapping_for("MergePopup")] = popups.open("merge", function(p) + p { commit = self.buffer.ui:get_commit_under_cursor() } + end), + [popups.mapping_for("PushPopup")] = popups.open("push", function(p) + p { commit = self.buffer.ui:get_commit_under_cursor() } + end), + [popups.mapping_for("RebasePopup")] = popups.open("rebase", function(p) + p { commit = self.buffer.ui:get_commit_under_cursor() } + end), + [popups.mapping_for("RemotePopup")] = popups.open("remote"), + [popups.mapping_for("RevertPopup")] = popups.open("revert", function(p) + p { commits = { self.buffer.ui:get_commit_under_cursor() } } + end), + [popups.mapping_for("ResetPopup")] = popups.open("reset", function(p) + p { commit = self.buffer.ui:get_commit_under_cursor() } + end), + [popups.mapping_for("TagPopup")] = popups.open("tag", function(p) + p { commit = self.buffer.ui:get_commit_under_cursor() } + end), + [popups.mapping_for("DiffPopup")] = popups.open("diff", function(p) + local item = self.buffer.ui:get_commit_under_cursor() + p { + section = { name = "log" }, + item = { name = item }, + } + end), + [popups.mapping_for("PullPopup")] = popups.open("pull"), + [status_maps["YankSelected"]] = function() + local yank = self.buffer.ui:get_commit_under_cursor() + if yank then + yank = string.format("'%s'", yank) + vim.cmd.let("@+=" .. yank) + vim.cmd.echo(yank) + else + vim.cmd("echo ''") + end + end, + [status_maps["Close"]] = require("neogit.lib.ui.helpers").close_topmost(self), + [status_maps["GoToFile"]] = function() + local commit = self.buffer.ui:get_commit_under_cursor() + if commit then + CommitViewBuffer.new(commit, self.files):open() + end + end, + [status_maps["PeekFile"]] = function() + local commit = self.buffer.ui:get_commit_under_cursor() + if commit then + CommitViewBuffer.new(commit, self.files):open() + self.buffer:focus() + end + end, + [status_maps["OpenOrScrollDown"]] = function() + local commit = self.buffer.ui:get_commit_under_cursor() + if commit then + CommitViewBuffer.open_or_scroll_down(commit, self.files) + end + end, + [status_maps["OpenOrScrollUp"]] = function() + local commit = self.buffer.ui:get_commit_under_cursor() + if commit then + CommitViewBuffer.open_or_scroll_up(commit, self.files) + end + end, + [status_maps["PeekUp"]] = function() + -- Open prev fold + pcall(vim.cmd, "normal! zc") + + vim.cmd("normal! k") + for _ = vim.fn.line("."), 0, -1 do + if vim.fn.foldlevel(".") > 0 then + break end - end, - [status_maps["PeekUp"]] = function() - -- Open prev fold - pcall(vim.cmd, "normal! zc") vim.cmd("normal! k") - for _ = vim.fn.line("."), 0, -1 do - if vim.fn.foldlevel(".") > 0 then - break - end + end - vim.cmd("normal! k") + if CommitViewBuffer.is_open() then + local commit = self.buffer.ui:get_commit_under_cursor() + if commit then + CommitViewBuffer.instance:update(commit, self.files) end + else + pcall(vim.cmd, "normal! zo") + vim.cmd("normal! zz") + end + end, + [status_maps["PeekDown"]] = function() + pcall(vim.cmd, "normal! zc") - if CommitViewBuffer.is_open() then - local commit = self.buffer.ui:get_commit_under_cursor() - if commit then - CommitViewBuffer.instance:update(commit, self.files) - end - else - pcall(vim.cmd, "normal! zo") - vim.cmd("normal! zz") + vim.cmd("normal! j") + for _ = vim.fn.line("."), vim.fn.line("$"), 1 do + if vim.fn.foldlevel(".") > 0 then + break end - end, - [status_maps["PeekDown"]] = function() - pcall(vim.cmd, "normal! zc") vim.cmd("normal! j") - for _ = vim.fn.line("."), vim.fn.line("$"), 1 do - if vim.fn.foldlevel(".") > 0 then - break - end + end - vim.cmd("normal! j") + if CommitViewBuffer.is_open() then + local commit = self.buffer.ui:get_commit_under_cursor() + if commit then + CommitViewBuffer.instance:update(commit, self.files) end + else + pcall(vim.cmd, "normal! zo") + vim.cmd("normal! zz") + end + end, + ["+"] = a.void(function() + local permit = self.refresh_lock:acquire() - if CommitViewBuffer.is_open() then - local commit = self.buffer.ui:get_commit_under_cursor() - if commit then - CommitViewBuffer.instance:update(commit, self.files) - end - else - pcall(vim.cmd, "normal! zo") - vim.cmd("normal! zz") - end - end, - ["+"] = a.void(function() - local permit = self.refresh_lock:acquire() + self.commits = util.merge(self.commits, self.fetch_func(self:commit_count())) + self.buffer.ui:render(unpack(ui.View(self.commits, self.remotes, self.internal_args))) - self.commits = util.merge(self.commits, self.fetch_func(self:commit_count())) - self.buffer.ui:render(unpack(ui.View(self.commits, self.remotes, self.internal_args))) + permit:forget() + end), + [""] = function() + pcall(vim.cmd, "normal! za") + end, + ["j"] = function() + if vim.v.count > 0 then + vim.cmd("norm! " .. vim.v.count .. "j") + else + vim.cmd("norm! j") + end - permit:forget() - end), - [""] = function() - pcall(vim.cmd, "normal! za") - end, - ["j"] = function() - if vim.v.count > 0 then - vim.cmd("norm! " .. vim.v.count .. "j") - else - vim.cmd("norm! j") + while self.buffer:get_current_line()[1]:sub(1, 1) == " " do + if vim.fn.line(".") == vim.fn.line("$") then + break end - while self.buffer:get_current_line()[1]:sub(1, 1) == " " do - if vim.fn.line(".") == vim.fn.line("$") then - break - end + vim.cmd("norm! j") + end + end, + ["k"] = function() + if vim.v.count > 0 then + vim.cmd("norm! " .. vim.v.count .. "k") + else + vim.cmd("norm! k") + end - vim.cmd("norm! j") + while self.buffer:get_current_line()[1]:sub(1, 1) == " " do + if vim.fn.line(".") == 1 then + break end - end, - ["k"] = function() - if vim.v.count > 0 then - vim.cmd("norm! " .. vim.v.count .. "k") - else - vim.cmd("norm! k") - end - - while self.buffer:get_current_line()[1]:sub(1, 1) == " " do - if vim.fn.line(".") == 1 then - break - end - vim.cmd("norm! k") - end - end, - }, + vim.cmd("norm! k") + end + end, }, + } + + if config.values.log_view_esc_close ~= false then + mappings.n[""] = require("neogit.lib.ui.helpers").close_topmost(self) + end + + self.buffer = Buffer.create { + name = "NeogitLogView", + filetype = "NeogitLogView", + kind = config.values.log_view.kind, + context_highlight = false, + header = not config.values.simple_headers and self.header or nil, + scroll_header = false, + active_item_highlight = true, + status_column = not config.values.disable_signs and "" or nil, + mappings = mappings, render = function() local header = config.values.simple_headers and self.header or nil return ui.View(self.commits, self.remotes, self.internal_args, header) diff --git a/lua/neogit/config.lua b/lua/neogit/config.lua index 2a388b386..26a8b7a23 100644 --- a/lua/neogit/config.lua +++ b/lua/neogit/config.lua @@ -332,6 +332,7 @@ end ---@field disable_signs? boolean Special signs to draw for sections etc. in Neogit ---@field simple_headers? boolean Use text headers instead of windows ---@field force_if_includes? boolean Add --force-if-includes if --force-with-lease is set +---@field log_view_esc_close? boolean If this is set to false ESC doesn't close log view ---@field prompt_force_push? boolean Offer to force push when branches diverge ---@field git_services? table Templartes to use when opening a pull request for a branch ---@field fetch_after_checkout? boolean Perform a fetch if the newly checked out branch has an upstream or pushRemote set @@ -382,6 +383,7 @@ function M.get_default_values() disable_signs = false, simple_headers = false, force_if_includes = true, + log_view_esc_close = true, prompt_force_push = true, graph_style = "ascii", commit_date_format = nil, @@ -1141,6 +1143,7 @@ function M.validate_config() validate_type(config.disable_signs, "disable_signs", "boolean") validate_type(config.simple_headers, "simple_headers", "boolean") validate_type(config.force_if_includes, "force_if_includes", "boolean") + validate_type(config.log_view_esc_close, "log_view_esc_close", "boolean") validate_type(config.telescope_sorter, "telescope_sorter", "function") validate_type(config.use_per_project_settings, "use_per_project_settings", "boolean") validate_type(config.remember_settings, "remember_settings", "boolean") From 6403450764a7449342f9aeae867101c9b5ddc1fa Mon Sep 17 00:00:00 2001 From: Anton Rogov Date: Thu, 5 Jun 2025 06:37:05 +0300 Subject: [PATCH 4/4] option to turn off hard reset backups --- lua/neogit/config.lua | 3 +++ lua/neogit/lib/git/reset.lua | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/neogit/config.lua b/lua/neogit/config.lua index 26a8b7a23..43a8063de 100644 --- a/lua/neogit/config.lua +++ b/lua/neogit/config.lua @@ -332,6 +332,7 @@ end ---@field disable_signs? boolean Special signs to draw for sections etc. in Neogit ---@field simple_headers? boolean Use text headers instead of windows ---@field force_if_includes? boolean Add --force-if-includes if --force-with-lease is set +---@field hard_reset_backup? boolean Do a backup commit before a hard reset ---@field log_view_esc_close? boolean If this is set to false ESC doesn't close log view ---@field prompt_force_push? boolean Offer to force push when branches diverge ---@field git_services? table Templartes to use when opening a pull request for a branch @@ -383,6 +384,7 @@ function M.get_default_values() disable_signs = false, simple_headers = false, force_if_includes = true, + hard_reset_backup = true, log_view_esc_close = true, prompt_force_push = true, graph_style = "ascii", @@ -1143,6 +1145,7 @@ function M.validate_config() validate_type(config.disable_signs, "disable_signs", "boolean") validate_type(config.simple_headers, "simple_headers", "boolean") validate_type(config.force_if_includes, "force_if_includes", "boolean") + validate_type(config.hard_reset_backup, "hard_reset_backup", "boolean") validate_type(config.log_view_esc_close, "log_view_esc_close", "boolean") validate_type(config.telescope_sorter, "telescope_sorter", "function") validate_type(config.use_per_project_settings, "use_per_project_settings", "boolean") diff --git a/lua/neogit/lib/git/reset.lua b/lua/neogit/lib/git/reset.lua index 22dd6a8e8..9fb76aa79 100644 --- a/lua/neogit/lib/git/reset.lua +++ b/lua/neogit/lib/git/reset.lua @@ -1,4 +1,5 @@ local git = require("neogit.lib.git") +local config = require("neogit.config") ---@class NeogitGitReset local M = {} @@ -20,7 +21,9 @@ end ---@param target string ---@return boolean function M.hard(target) - git.index.create_backup() + if config.values.hard_reset_backup then + git.index.create_backup() + end local result = git.cli.reset.hard.args(target).call() return result.code == 0