From 8dca67e5ae14e17d967de2a9ad835c77afc0bbd7 Mon Sep 17 00:00:00 2001 From: dumch Date: Sun, 10 Nov 2024 20:23:16 +0300 Subject: [PATCH 1/4] Breaking!: rename disable_* config properties to enable_* --- README.md | 20 +++++------ doc/neogit.txt | 10 +++--- .../buffers/commit_select_view/init.lua | 2 +- lua/neogit/buffers/commit_view/init.lua | 4 +-- lua/neogit/buffers/diff/init.lua | 4 +-- lua/neogit/buffers/editor/init.lua | 8 ++--- lua/neogit/buffers/log_view/init.lua | 2 +- lua/neogit/buffers/rebase_editor/init.lua | 6 ++-- lua/neogit/buffers/reflog_view/init.lua | 2 +- lua/neogit/buffers/status/init.lua | 8 ++--- lua/neogit/buffers/status/ui.lua | 2 +- lua/neogit/config.lua | 36 +++++++++---------- lua/neogit/lib/buffer.lua | 10 +++--- lua/neogit/lib/signs.lua | 2 +- tests/specs/neogit/config_spec.lua | 22 ++++++------ 15 files changed, 69 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 904f4e150..244bbaf5a 100644 --- a/README.md +++ b/README.md @@ -67,16 +67,16 @@ You can configure neogit by running the `neogit.setup()` function, passing a tab local neogit = require("neogit") neogit.setup { - -- Hides the hints at the top of the status buffer - disable_hint = false, - -- Disables changing the buffer highlights based on where the cursor is. - disable_context_highlighting = false, - -- Disables signs for sections/items/hunks - disable_signs = false, - -- Changes what mode the Commit Editor starts in. `true` will leave nvim in normal mode, `false` will change nvim to + -- Shows the hints at the top of the status buffer + enable_hint = true, + -- Enable changing the buffer highlights based on where the cursor is. + enable_context_highlighting = true, + -- Shows signs for sections/items/hunks + enable_signs = true, + -- Changes what mode the Commit Editor starts in. `false` will leave nvim in normal mode, `true` will change nvim to -- insert mode, and `"auto"` will change nvim to insert mode IF the commit message is empty, otherwise leaving it in -- normal mode. - disable_insert_on_commit = "auto", + enable_insert_on_commit = "auto", -- When enabled, will watch the `.git/` directory for changes and refresh the status buffer in response to filesystem -- events. filewatcher = { @@ -131,8 +131,8 @@ neogit.setup { initial_branch_name = "", -- Change the default way of opening neogit kind = "tab", - -- Disable line numbers and relative line numbers - disable_line_numbers = true, + -- Show line numbers and relative line numbers + enable_line_numbers = false, -- The time after which an output console is shown for slow running commands console_timeout = 2000, -- Automatically show console if a command takes more than console_timeout milliseconds diff --git a/doc/neogit.txt b/doc/neogit.txt index b331cb1ba..6f15469f0 100644 --- a/doc/neogit.txt +++ b/doc/neogit.txt @@ -85,9 +85,9 @@ to Neovim users. TODO: Detail what these do use_default_keymaps = true, - disable_hint = false, - disable_context_highlighting = false, - disable_signs = false, + enable_hint = true, + enable_context_highlighting = true, + enable_signs = true, graph_style = "ascii", filewatcher = { enabled = true, @@ -106,7 +106,7 @@ TODO: Detail what these do bold = true, underline = true, }, - disable_insert_on_commit = "auto", + enable_insert_on_commit = "auto", use_per_project_settings = true, show_head_commit_hash = true, remember_settings = true, @@ -115,7 +115,7 @@ TODO: Detail what these do sort_branches = "-committerdate", initial_branch_name = "", kind = "tab", - disable_line_numbers = true, + enable_line_numbers = false, -- The time after which an output console is shown for slow running commands console_timeout = 2000, -- Automatically show console if a command takes more than console_timeout milliseconds diff --git a/lua/neogit/buffers/commit_select_view/init.lua b/lua/neogit/buffers/commit_select_view/init.lua index 006207319..c1e700a00 100644 --- a/lua/neogit/buffers/commit_select_view/init.lua +++ b/lua/neogit/buffers/commit_select_view/init.lua @@ -59,7 +59,7 @@ function M:open(action) self.buffer = Buffer.create { name = "NeogitCommitSelectView", filetype = "NeogitCommitSelectView", - status_column = not config.values.disable_signs and "" or nil, + status_column = config.values.enable_signs and "" or nil, kind = config.values.commit_select_view.kind, header = self.header or "Select a commit with , or to abort", scroll_header = true, diff --git a/lua/neogit/buffers/commit_view/init.lua b/lua/neogit/buffers/commit_view/init.lua index ef6e63859..c2968b108 100644 --- a/lua/neogit/buffers/commit_view/init.lua +++ b/lua/neogit/buffers/commit_view/init.lua @@ -151,8 +151,8 @@ function M:open(kind) name = "NeogitCommitView", filetype = "NeogitCommitView", kind = kind, - status_column = not config.values.disable_signs and "" or nil, - context_highlight = not config.values.disable_context_highlighting, + status_column = config.values.enable_signs and "" or nil, + context_highlight = config.values.enable_context_highlighting, autocmds = { ["WinLeave"] = function() if self.buffer and self.buffer.kind == "floating" then diff --git a/lua/neogit/buffers/diff/init.lua b/lua/neogit/buffers/diff/init.lua index 987378d7f..b3eb032df 100644 --- a/lua/neogit/buffers/diff/init.lua +++ b/lua/neogit/buffers/diff/init.lua @@ -54,9 +54,9 @@ function M:open() self.buffer = Buffer.create { name = "NeogitDiffView", filetype = "NeogitDiffView", - status_column = not config.values.disable_signs and "" or nil, + status_column = config.values.enable_signs and "" or nil, kind = config.values.commit_editor.staged_diff_split_kind, - context_highlight = not config.values.disable_context_highlighting, + context_highlight = config.values.enable_context_highlighting, mappings = { n = { ["{"] = function() -- Goto Previous diff --git a/lua/neogit/buffers/editor/init.lua b/lua/neogit/buffers/editor/init.lua index b33ccd113..d8f8f508f 100644 --- a/lua/neogit/buffers/editor/init.lua +++ b/lua/neogit/buffers/editor/init.lua @@ -71,7 +71,7 @@ function M:open(kind) buftype = "", kind = kind, modifiable = true, - status_column = not config.values.disable_signs and "" or nil, + status_column = config.values.enable_signs and "" or nil, readonly = false, autocmds = { ["QuitPre"] = function() -- For :wq compatibility @@ -148,10 +148,10 @@ function M:open(kind) footer = buffer:get_lines(1, -1) -- Start insert mode if user has configured it - local disable_insert = config.values.disable_insert_on_commit + local enable_insert = config.values.enable_insert_on_commit if - (disable_insert == "auto" and vim.fn.prevnonblank(".") ~= vim.fn.line(".")) - or not disable_insert + (enable_insert == "auto" and vim.fn.prevnonblank(".") ~= vim.fn.line(".")) + or enable_insert then vim.cmd(":startinsert") end diff --git a/lua/neogit/buffers/log_view/init.lua b/lua/neogit/buffers/log_view/init.lua index c73c033e6..954000a54 100644 --- a/lua/neogit/buffers/log_view/init.lua +++ b/lua/neogit/buffers/log_view/init.lua @@ -81,7 +81,7 @@ function M:open() context_highlight = false, header = self.header, scroll_header = false, - status_column = not config.values.disable_signs and "" or nil, + status_column = config.values.enable_signs and "" or nil, mappings = { v = { [popups.mapping_for("CherryPickPopup")] = popups.open("cherry_pick", function(p) diff --git a/lua/neogit/buffers/rebase_editor/init.lua b/lua/neogit/buffers/rebase_editor/init.lua index 10149c304..193d68972 100644 --- a/lua/neogit/buffers/rebase_editor/init.lua +++ b/lua/neogit/buffers/rebase_editor/init.lua @@ -71,11 +71,11 @@ function M:open(kind) load = true, filetype = "gitrebase", buftype = "", - status_column = not config.values.disable_signs and "" or nil, + status_column = config.values.enable_signs and "" or nil, kind = kind, modifiable = true, - disable_line_numbers = config.values.disable_line_numbers, - disable_relative_line_numbers = config.values.disable_relative_line_numbers, + enable_line_numbers = config.values.enable_line_numbers, + enable_relative_line_numbers = config.values.enable_relative_line_numbers, readonly = false, on_detach = function() if self.on_unload then diff --git a/lua/neogit/buffers/reflog_view/init.lua b/lua/neogit/buffers/reflog_view/init.lua index d740c63b4..becd25d6c 100644 --- a/lua/neogit/buffers/reflog_view/init.lua +++ b/lua/neogit/buffers/reflog_view/init.lua @@ -54,7 +54,7 @@ function M:open(_) kind = config.values.reflog_view.kind, header = self.header, scroll_header = true, - status_column = not config.values.disable_signs and "" or nil, + status_column = config.values.enable_signs and "" or nil, context_highlight = true, mappings = { v = { diff --git a/lua/neogit/buffers/status/init.lua b/lua/neogit/buffers/status/init.lua index 2839850c2..e76e17aeb 100644 --- a/lua/neogit/buffers/status/init.lua +++ b/lua/neogit/buffers/status/init.lua @@ -94,11 +94,11 @@ function M:open(kind) name = "NeogitStatus", filetype = "NeogitStatus", cwd = self.cwd, - context_highlight = not config.values.disable_context_highlighting, + context_highlight = config.values.enable_context_highlighting, kind = kind or config.values.kind or "tab", - disable_line_numbers = config.values.disable_line_numbers, - disable_relative_line_numbers = config.values.disable_relative_line_numbers, - foldmarkers = not config.values.disable_signs, + enable_line_numbers = config.values.enable_line_numbers, + enable_relative_line_numbers = config.values.enable_relative_line_numbers, + foldmarkers = config.values.enable_signs, on_detach = function() Watcher.instance(self.root):unregister(self) diff --git a/lua/neogit/buffers/status/ui.lua b/lua/neogit/buffers/status/ui.lua index bfc26046e..0fe08de89 100755 --- a/lua/neogit/buffers/status/ui.lua +++ b/lua/neogit/buffers/status/ui.lua @@ -459,7 +459,7 @@ end) function M.Status(state, config) -- stylua: ignore start - local show_hint = not config.disable_hint + local show_hint = config.enable_hint local show_upstream = state.upstream.ref and not state.head.detached diff --git a/lua/neogit/config.lua b/lua/neogit/config.lua index 60db9ecd3..390595fd8 100644 --- a/lua/neogit/config.lua +++ b/lua/neogit/config.lua @@ -300,21 +300,21 @@ end ---@class NeogitConfig Neogit configuration settings ---@field filewatcher? NeogitFilewatcherConfig Values for filewatcher ---@field graph_style? NeogitGraphStyle Style for graph ----@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 enable_hint? boolean Shows the top hint in the Status buffer +---@field enable_context_highlighting? boolean Enable context highlights based on cursor position +---@field enable_signs? boolean Special signs to draw for sections etc. in Neogit ---@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 ---@field telescope_sorter? function The sorter telescope will use ---@field process_spinner? boolean Hide/Show the process spinner ----@field disable_insert_on_commit? boolean|"auto" Disable automatically entering insert mode in commit dialogues +---@field enable_insert_on_commit? boolean|"auto" Enables automatically entering insert mode in commit dialogues ---@field use_per_project_settings? boolean Scope persisted settings on a per-project basis ---@field remember_settings? boolean Whether neogit should persist flags from popups, e.g. git push flags ---@field sort_branches? string Value used for `--sort` for the `git branch` command ---@field initial_branch_name? string Default for new branch name prompts ---@field kind? WindowKind The default type of window neogit should open in ----@field disable_line_numbers? boolean Whether to disable line numbers ----@field disable_relative_line_numbers? boolean Whether to disable line numbers +---@field enable_line_numbers? boolean Whether to enable line numbers +---@field enable_relative_line_numbers? boolean Whether to enable relative line numbers ---@field console_timeout? integer Time in milliseconds after a console is created for long running commands ---@field auto_show_console? boolean Automatically show the console if a command takes longer than console_timeout ---@field auto_close_console? boolean Automatically hide the console if the process exits with a 0 status @@ -346,9 +346,9 @@ end function M.get_default_values() return { use_default_keymaps = true, - disable_hint = false, - disable_context_highlighting = false, - disable_signs = false, + enable_hint = true, + enable_context_highlighting = true, + enable_signs = true, graph_style = "ascii", process_spinner = true, filewatcher = { @@ -364,15 +364,15 @@ function M.get_default_values() ["azure.com"] = "https://dev.azure.com/${owner}/_git/${repository}/pullrequestcreate?sourceRef=${branch_name}&targetRef=${target}", }, highlight = {}, - disable_insert_on_commit = "auto", + enable_insert_on_commit = "auto", use_per_project_settings = true, remember_settings = true, fetch_after_checkout = false, sort_branches = "-committerdate", kind = "tab", initial_branch_name = "", - disable_line_numbers = true, - disable_relative_line_numbers = true, + enable_line_numbers = false, + enable_relative_line_numbers = false, -- The time after which an output console is shown for slow running commands console_timeout = 2000, -- Automatically show console if a command takes more than console_timeout milliseconds @@ -1092,9 +1092,9 @@ function M.validate_config() end if validate_type(config, "base config", "table") then - 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.enable_hint, "enable_hint", "boolean") + validate_type(config.enable_context_highlighting, "enable_context_highlighting", "boolean") + validate_type(config.enable_signs, "enable_signs", "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") @@ -1103,8 +1103,8 @@ function M.validate_config() validate_type(config.notification_icon, "notification_icon", "string") validate_type(config.console_timeout, "console_timeout", "number") validate_kind(config.kind, "kind") - validate_type(config.disable_line_numbers, "disable_line_numbers", "boolean") - validate_type(config.disable_relative_line_numbers, "disable_relative_line_numbers", "boolean") + validate_type(config.enable_line_numbers, "enable_line_numbers", "boolean") + validate_type(config.enable_relative_line_numbers, "enable_relative_line_numbers", "boolean") validate_type(config.auto_show_console, "auto_show_console", "boolean") validate_type(config.auto_close_console, "auto_close_console", "boolean") if validate_type(config.status, "status", "table") then @@ -1115,7 +1115,7 @@ function M.validate_config() validate_type(config.status.mode_text, "status.mode_text", "table") end validate_signs() - validate_trinary_auto(config.disable_insert_on_commit, "disable_insert_on_commit") + validate_trinary_auto(config.enable_insert_on_commit, "enable_insert_on_commit") -- Commit Editor if validate_type(config.commit_editor, "commit_editor", "table") then validate_type(config.commit_editor.show_staged_diff, "show_staged_diff", "boolean") diff --git a/lua/neogit/lib/buffer.lua b/lua/neogit/lib/buffer.lua index 8cc5a95c3..27017a664 100644 --- a/lua/neogit/lib/buffer.lua +++ b/lua/neogit/lib/buffer.lua @@ -615,9 +615,9 @@ end ---@field load boolean|nil ---@field context_highlight boolean|nil ---@field open boolean|nil ----@field disable_line_numbers boolean|nil ----@field disable_relative_line_numbers boolean|nil ----@field disable_signs boolean|nil +---@field enable_line_numbers boolean|nil +---@field enable_relative_line_numbers boolean|nil +---@field enable_signs boolean|nil ---@field swapfile boolean|nil ---@field modifiable boolean|nil ---@field readonly boolean|nil @@ -722,11 +722,11 @@ function Buffer.create(config) vim.opt_local.fillchars:append("fold: ") end) - if (config.disable_line_numbers == nil) or config.disable_line_numbers then + if not config.enable_line_numbers then buffer:set_window_option("number", false) end - if (config.disable_relative_line_numbers == nil) or config.disable_relative_line_numbers then + if not config.enable_relative_line_numbers then buffer:set_window_option("relativenumber", false) end diff --git a/lua/neogit/lib/signs.lua b/lua/neogit/lib/signs.lua index e3dbcf55e..a9a302cf4 100644 --- a/lua/neogit/lib/signs.lua +++ b/lua/neogit/lib/signs.lua @@ -12,7 +12,7 @@ function M.get(name) end function M.setup(config) - if not config.disable_signs then + if config.enable_signs then for key, val in pairs(config.signs) do if key == "hunk" or key == "item" or key == "section" then signs["NeogitClosed" .. key] = val[1] diff --git a/tests/specs/neogit/config_spec.lua b/tests/specs/neogit/config_spec.lua index 942401e06..0b8a9c989 100644 --- a/tests/specs/neogit/config_spec.lua +++ b/tests/specs/neogit/config_spec.lua @@ -11,18 +11,18 @@ describe("Neogit config", function() assert.True(vim.tbl_count(require("neogit.config").validate_config()) ~= 0) end) - it("should return invalid when disable_hint isn't a boolean", function() - config.values.disable_hint = "not a boolean" + it("should return invalid when enable_hint isn't a boolean", function() + config.values.enable_hint = "not a boolean" assert.True(vim.tbl_count(require("neogit.config").validate_config()) ~= 0) end) - it("should return invalid when disable_context_highlighting isn't a boolean", function() - config.values.disable_context_highlighting = "not a boolean" + it("should return invalid when enable_context_highlighting isn't a boolean", function() + config.values.enable_context_highlighting = "not a boolean" assert.True(vim.tbl_count(require("neogit.config").validate_config()) ~= 0) end) - it("should return invalid when disable_signs isn't a boolean", function() - config.values.disable_signs = "not a boolean" + it("should return invalid when enable_signs isn't a boolean", function() + config.values.enable_signs = "not a boolean" assert.True(vim.tbl_count(require("neogit.config").validate_config()) ~= 0) end) @@ -31,7 +31,7 @@ describe("Neogit config", function() assert.True(vim.tbl_count(require("neogit.config").validate_config()) ~= 0) end) - it("should return invalid when disable_insert_on_commit isn't a boolean", function() + it("should return invalid when enable_insert_on_commit isn't a boolean", function() config.values.telescope_sorter = "not a boolean" assert.True(vim.tbl_count(require("neogit.config").validate_config()) ~= 0) end) @@ -71,8 +71,8 @@ describe("Neogit config", function() assert.True(vim.tbl_count(require("neogit.config").validate_config()) ~= 0) end) - it("should return invalid when disable_line_numbers isn't a boolean", function() - config.values.disable_line_numbers = "not a boolean" + it("should return invalid when enable_line_numbers isn't a boolean", function() + config.values.enable_line_numbers = "not a boolean" assert.True(vim.tbl_count(require("neogit.config").validate_config()) ~= 0) end) @@ -489,8 +489,8 @@ describe("Neogit config", function() assert.True(vim.tbl_count(require("neogit.config").validate_config()) == 0) end) - it("should return valid when disable_line_numbers is a boolean", function() - config.values.disable_line_numbers = true + it("should return valid when enable_line_numbers is a boolean", function() + config.values.enable_line_numbers = true assert.True(vim.tbl_count(require("neogit.config").validate_config()) == 0) end) From cbe29941f953cbb17e2190c839926c0e3de910ac Mon Sep 17 00:00:00 2001 From: dumch Date: Sun, 10 Nov 2024 20:45:37 +0300 Subject: [PATCH 2/4] Fix linting issue --- lua/neogit/buffers/editor/init.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lua/neogit/buffers/editor/init.lua b/lua/neogit/buffers/editor/init.lua index d8f8f508f..91fa9aeec 100644 --- a/lua/neogit/buffers/editor/init.lua +++ b/lua/neogit/buffers/editor/init.lua @@ -149,10 +149,7 @@ function M:open(kind) -- Start insert mode if user has configured it local enable_insert = config.values.enable_insert_on_commit - if - (enable_insert == "auto" and vim.fn.prevnonblank(".") ~= vim.fn.line(".")) - or enable_insert - then + if (enable_insert == "auto" and vim.fn.prevnonblank(".") ~= vim.fn.line(".")) or enable_insert then vim.cmd(":startinsert") end From 954bc3ce7ea15262bc81767358428c9c5e4edbbd Mon Sep 17 00:00:00 2001 From: dumch Date: Sun, 10 Nov 2024 22:58:15 +0300 Subject: [PATCH 3/4] Trying to fix rspec tests --- lua/neogit/buffers/editor/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/neogit/buffers/editor/init.lua b/lua/neogit/buffers/editor/init.lua index 91fa9aeec..28050fa50 100644 --- a/lua/neogit/buffers/editor/init.lua +++ b/lua/neogit/buffers/editor/init.lua @@ -149,7 +149,9 @@ function M:open(kind) -- Start insert mode if user has configured it local enable_insert = config.values.enable_insert_on_commit - if (enable_insert == "auto" and vim.fn.prevnonblank(".") ~= vim.fn.line(".")) or enable_insert then + if + (enable_insert == "auto" and vim.fn.prevnonblank(".") ~= vim.fn.line(".")) or (enable_insert == true) + then vim.cmd(":startinsert") end From 2fb8f3ba5d6578997286dc39ef854bf05f757744 Mon Sep 17 00:00:00 2001 From: dumch Date: Sun, 8 Dec 2024 00:21:23 +0300 Subject: [PATCH 4/4] Move line to the same place (after merging conflicts) --- lua/neogit/buffers/log_view/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/neogit/buffers/log_view/init.lua b/lua/neogit/buffers/log_view/init.lua index df77e8149..9f4b253ef 100644 --- a/lua/neogit/buffers/log_view/init.lua +++ b/lua/neogit/buffers/log_view/init.lua @@ -81,8 +81,8 @@ function M:open() context_highlight = false, header = self.header, scroll_header = false, - status_column = config.values.enable_signs and "" or nil, active_item_highlight = true, + status_column = config.values.enable_signs and "" or nil, mappings = { v = { [popups.mapping_for("CherryPickPopup")] = popups.open("cherry_pick", function(p)