Skip to content

Commit ec84915

Browse files
authored
Merge branch 'NeogitOrg:master' into margin
2 parents 85a75eb + 7a3daec commit ec84915

File tree

17 files changed

+222
-82
lines changed

17 files changed

+222
-82
lines changed

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Here's an example spec for [Lazy](https://github.com/folke/lazy.nvim), but you'r
3838
"nvim-telescope/telescope.nvim", -- optional
3939
"ibhagwan/fzf-lua", -- optional
4040
"echasnovski/mini.pick", -- optional
41+
"folke/snacks.nvim", -- optional
4142
},
4243
}
4344
```
@@ -101,13 +102,7 @@ neogit.setup {
101102
-- Scope persisted settings on a per-project basis
102103
use_per_project_settings = true,
103104
-- Table of settings to never persist. Uses format "Filetype--cli-value"
104-
ignored_settings = {
105-
"NeogitPushPopup--force-with-lease",
106-
"NeogitPushPopup--force",
107-
"NeogitPullPopup--rebase",
108-
"NeogitCommitPopup--allow-empty",
109-
"NeogitRevertPopup--no-edit",
110-
},
105+
ignored_settings = {},
111106
-- Configure highlight group features
112107
highlight = {
113108
italic = true,
@@ -128,6 +123,14 @@ neogit.setup {
128123
initial_branch_name = "",
129124
-- Change the default way of opening neogit
130125
kind = "tab",
126+
-- Floating window style
127+
floating = {
128+
relative = "editor",
129+
width = 0.8,
130+
height = 0.7,
131+
style = "minimal",
132+
border = "rounded",
133+
},
131134
-- Disable line numbers
132135
disable_line_numbers = true,
133136
-- Disable relative line numbers
@@ -238,6 +241,11 @@ neogit.setup {
238241
-- is also selected then telescope is used instead
239242
-- Requires you to have `echasnovski/mini.pick` installed.
240243
mini_pick = nil,
244+
245+
-- If enabled, uses snacks.picker for menu selection. If the telescope integration
246+
-- is also selected then telescope is used instead
247+
-- Requires you to have `folke/snacks.nvim` installed.
248+
snacks = nil,
241249
},
242250
sections = {
243251
-- Reverting/Cherry Picking

doc/neogit.txt

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,7 @@ to Neovim users.
128128
-- Scope persisted settings on a per-project basis
129129
use_per_project_settings = true,
130130
-- Table of settings to never persist. Uses format "Filetype--cli-value"
131-
ignored_settings = {
132-
"NeogitPushPopup--force-with-lease",
133-
"NeogitPushPopup--force",
134-
"NeogitPullPopup--rebase",
135-
"NeogitCommitPopup--allow-empty",
136-
"NeogitRevertPopup--no-edit",
137-
},
131+
ignored_settings = {},
138132
-- Configure highlight group features
139133
highlight = {
140134
italic = true,
@@ -155,6 +149,14 @@ to Neovim users.
155149
initial_branch_name = "",
156150
-- Change the default way of opening neogit
157151
kind = "tab",
152+
-- Floating window style
153+
floating = {
154+
relative = "editor",
155+
width = 0.8,
156+
height = 0.7,
157+
style = "minimal",
158+
border = "rounded",
159+
},
158160
-- Disable line numbers
159161
disable_line_numbers = true,
160162
-- Disable relative line numbers
@@ -265,6 +267,11 @@ to Neovim users.
265267
-- is also selected then telescope is used instead
266268
-- Requires you to have `echasnovski/mini.pick` installed.
267269
mini_pick = nil,
270+
271+
-- If enabled, uses snacks.picker for menu selection. If the telescope integration
272+
-- is also selected then telescope is used instead
273+
-- Requires you to have `folke/snacks.nvim` installed.
274+
snacks = nil,
268275
},
269276
sections = {
270277
-- Reverting/Cherry Picking
@@ -2136,5 +2143,21 @@ calling the setup function:
21362143
},
21372144
})
21382145
<
2146+
2147+
You can also customize existing popups via the Neogit config.
2148+
Below is an example of adding a custom switch, but you can use any function
2149+
from the builder API.
2150+
>lua
2151+
require("neogit").setup({
2152+
builders = {
2153+
NeogitPushPopup = function(builder)
2154+
builder:switch('m', 'merge_request.create', 'Create merge request', { cli_prefix = '-o ', persisted = false })
2155+
end,
2156+
},
2157+
})
2158+
2159+
Keep in mind that builder hooks are executed at the end of the popup
2160+
builder, so any switches or options added will be placed at the end.
2161+
21392162
------------------------------------------------------------------------------
21402163
vim:tw=78:ts=8:ft=help:norl:

lua/neogit.lua

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ end
186186
---@return function
187187
function M.action(popup, action, args)
188188
local util = require("neogit.lib.util")
189+
local git = require("neogit.lib.git")
189190
local a = require("plenary.async")
190191

191192
args = args or {}
@@ -202,15 +203,19 @@ function M.action(popup, action, args)
202203
if ok then
203204
local fn = actions[action]
204205
if fn then
205-
fn {
206-
state = { env = {} },
207-
get_arguments = function()
208-
return args
209-
end,
210-
get_internal_arguments = function()
211-
return internal_args
212-
end,
213-
}
206+
local action = function()
207+
fn {
208+
state = { env = {} },
209+
get_arguments = function()
210+
return args
211+
end,
212+
get_internal_arguments = function()
213+
return internal_args
214+
end,
215+
}
216+
end
217+
218+
git.repo:dispatch_refresh { source = "action", callback = action }
214219
else
215220
M.notification.error(
216221
string.format(

lua/neogit/buffers/status/actions.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,10 +1077,6 @@ M.n_stage = function(self)
10771077
if not git.merge.is_conflicted(selection.item.name) then
10781078
git.status.stage { selection.item.name }
10791079
self:dispatch_refresh({ update_diffs = { "*:" .. selection.item.name } }, "n_stage")
1080-
1081-
if not git.merge.any_conflicted() then
1082-
popups.open("merge")()
1083-
end
10841080
end
10851081
end,
10861082
},

lua/neogit/client.lua

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,7 @@ function M.client(opts)
6464
local client = fn.serverstart()
6565
logger.debug(("[CLIENT] Client address: %s"):format(client))
6666

67-
local lua_cmd =
68-
fmt('lua require("neogit.client").editor("%s", "%s", %s)', file_target, client, opts.show_diff)
69-
70-
if vim.uv.os_uname().sysname == "Windows_NT" then
71-
lua_cmd = lua_cmd:gsub("\\", "/")
72-
end
73-
67+
local lua_cmd = fmt('lua require("neogit.client").editor(%q, %q, %s)', file_target, client, opts.show_diff)
7468
local rpc_server = RPC.create_connection(nvim_server)
7569
rpc_server:send_cmd(lua_cmd)
7670
end

lua/neogit/config.lua

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ end
102102
---@class NeogitConfigPopup Popup window options
103103
---@field kind WindowKind The type of window that should be opened
104104

105+
---@class NeogitConfigFloating
106+
---@field relative? string
107+
---@field width? number
108+
---@field height? number
109+
---@field col? number
110+
---@field row? number
111+
---@field style? string
112+
---@field border? string
113+
105114
---@alias StagedDiffSplitKind
106115
---| "split" Open in a split
107116
---| "vsplit" Open in a vertical split
@@ -332,6 +341,7 @@ end
332341
---@field sort_branches? string Value used for `--sort` for the `git branch` command
333342
---@field initial_branch_name? string Default for new branch name prompts
334343
---@field kind? WindowKind The default type of window neogit should open in
344+
---@field floating? NeogitConfigFloating The floating window style
335345
---@field disable_line_numbers? boolean Whether to disable line numbers
336346
---@field disable_relative_line_numbers? boolean Whether to disable line numbers
337347
---@field console_timeout? integer Time in milliseconds after a console is created for long running commands
@@ -353,13 +363,14 @@ end
353363
---@field preview_buffer? NeogitConfigPopup Preview options
354364
---@field popup? NeogitConfigPopup Set the default way of opening popups
355365
---@field signs? NeogitConfigSigns Signs used for toggled regions
356-
---@field integrations? { diffview: boolean, telescope: boolean, fzf_lua: boolean, mini_pick: boolean } Which integrations to enable
366+
---@field integrations? { diffview: boolean, telescope: boolean, fzf_lua: boolean, mini_pick: boolean, snacks: boolean } Which integrations to enable
357367
---@field sections? NeogitConfigSections
358368
---@field ignored_settings? string[] Settings to never persist, format: "Filetype--cli-value", i.e. "NeogitCommitPopup--author"
359369
---@field mappings? NeogitConfigMappings
360370
---@field notification_icon? string
361371
---@field use_default_keymaps? boolean
362372
---@field highlight? HighlightOptions
373+
---@field builders? { [string]: fun(builder: PopupBuilder) }
363374

364375
---Returns the default Neogit configuration
365376
---@return NeogitConfig
@@ -393,6 +404,13 @@ function M.get_default_values()
393404
fetch_after_checkout = false,
394405
sort_branches = "-committerdate",
395406
kind = "tab",
407+
floating = {
408+
relative = "editor",
409+
width = 0.8,
410+
height = 0.7,
411+
style = "minimal",
412+
border = "rounded",
413+
},
396414
initial_branch_name = "",
397415
disable_line_numbers = true,
398416
disable_relative_line_numbers = true,
@@ -483,6 +501,7 @@ function M.get_default_values()
483501
diffview = nil,
484502
fzf_lua = nil,
485503
mini_pick = nil,
504+
snacks = nil,
486505
},
487506
sections = {
488507
sequencer = {
@@ -534,13 +553,7 @@ function M.get_default_values()
534553
hidden = false,
535554
},
536555
},
537-
ignored_settings = {
538-
"NeogitPushPopup--force-with-lease",
539-
"NeogitPushPopup--force",
540-
"NeogitPullPopup--rebase",
541-
"NeogitPullPopup--force",
542-
"NeogitCommitPopup--allow-empty",
543-
},
556+
ignored_settings = {},
544557
mappings = {
545558
commit_editor = {
546559
["q"] = "Close",
@@ -793,7 +806,7 @@ function M.validate_config()
793806
end
794807

795808
local function validate_integrations()
796-
local valid_integrations = { "diffview", "telescope", "fzf_lua", "mini_pick" }
809+
local valid_integrations = { "diffview", "telescope", "fzf_lua", "mini_pick", "snacks" }
797810
if not validate_type(config.integrations, "integrations", "table") or #config.integrations == 0 then
798811
return
799812
end
@@ -1138,6 +1151,13 @@ function M.validate_config()
11381151
validate_type(config.notification_icon, "notification_icon", "string")
11391152
validate_type(config.console_timeout, "console_timeout", "number")
11401153
validate_kind(config.kind, "kind")
1154+
if validate_type(config.floating, "floating", "table") then
1155+
validate_type(config.floating.relative, "relative", "string")
1156+
validate_type(config.floating.width, "width", "number")
1157+
validate_type(config.floating.height, "height", "number")
1158+
validate_type(config.floating.style, "style", "string")
1159+
validate_type(config.floating.border, "border", "string")
1160+
end
11411161
validate_type(config.disable_line_numbers, "disable_line_numbers", "boolean")
11421162
validate_type(config.disable_relative_line_numbers, "disable_relative_line_numbers", "boolean")
11431163
validate_type(config.auto_show_console, "auto_show_console", "boolean")

lua/neogit/lib/buffer.lua

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local util = require("neogit.lib.util")
55

66
local signs = require("neogit.lib.signs")
77
local Ui = require("neogit.lib.ui")
8+
local config = require("neogit.config")
89

910
local Path = require("plenary.path")
1011

@@ -317,24 +318,22 @@ function Buffer:show()
317318
elseif self.kind == "vsplit_left" then
318319
win = api.nvim_open_win(self.handle, true, { split = "left", vertical = true })
319320
elseif self.kind == "floating" then
320-
-- Creates the border window
321+
local width = config.values.floating.width
322+
local height = config.values.floating.height
321323
local vim_height = vim.o.lines
322324
local vim_width = vim.o.columns
323-
324-
local width = math.floor(vim_width * 0.8) + 3
325-
local height = math.floor(vim_height * 0.7)
326-
local col = vim_width * 0.1 - 1
327-
local row = vim_height * 0.15
325+
width = width > 1 and width or math.floor(vim_width * width)
326+
height = height > 1 and height or math.floor(vim_height * height)
328327

329328
local content_window = api.nvim_open_win(self.handle, true, {
330-
relative = "editor",
331329
width = width,
332330
height = height,
333-
col = col,
334-
row = row,
335-
style = "minimal",
331+
relative = config.values.floating.relative,
332+
border = config.values.floating.border,
333+
style = config.values.floating.style,
334+
col = config.values.floating.col or (vim_width - width) / 2,
335+
row = config.values.floating.row or (vim_height - height) / 2,
336336
focusable = true,
337-
border = "rounded",
338337
})
339338

340339
api.nvim_win_set_cursor(content_window, { 1, 0 })
@@ -431,7 +430,12 @@ end
431430

432431
function Buffer:set_buffer_option(name, value)
433432
if self.handle ~= nil then
434-
api.nvim_set_option_value(name, value, { scope = "local" })
433+
-- TODO: Remove this at some point. Nvim 0.10 throws an error if using both buf and scope
434+
if vim.fn.has("nvim-0.11") == 1 then
435+
api.nvim_set_option_value(name, value, { scope = "local", buf = self.handle })
436+
else
437+
api.nvim_set_option_value(name, value, { buf = self.handle })
438+
end
435439
end
436440
end
437441

@@ -718,8 +722,8 @@ function Buffer.create(config)
718722
end
719723

720724
if config.status_column then
721-
buffer:set_buffer_option("statuscolumn", config.status_column)
722-
buffer:set_buffer_option("signcolumn", "no")
725+
buffer:set_window_option("statuscolumn", config.status_column)
726+
buffer:set_window_option("signcolumn", "no")
723727
end
724728

725729
if config.user_mappings then
@@ -907,7 +911,7 @@ function Buffer.create(config)
907911
end
908912

909913
if config.foldmarkers then
910-
buffer:set_buffer_option("signcolumn", "auto")
914+
buffer:set_window_option("signcolumn", "auto")
911915

912916
logger.debug("[BUFFER:" .. buffer.handle .. "] Setting up foldmarkers")
913917
buffer:create_namespace("FoldSigns")

0 commit comments

Comments
 (0)