Skip to content

Commit

Permalink
Merge branch 'master' into test/git-branch-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
PriceHiller committed Jul 16, 2023
2 parents 7e018d6 + 700e38d commit 7ce8680
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 15 deletions.
1 change: 1 addition & 0 deletions lua/neogit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,5 @@ return {
close = status.close,
setup = setup,
complete = complete,
autocmd_group = vim.api.nvim_create_augroup("Neogit", { clear = false }),
}
3 changes: 1 addition & 2 deletions lua/neogit/autocmds.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
local M = {}

local api = vim.api
local group = api.nvim_create_augroup("Neogit", { clear = true })

local a = require("plenary.async")
local status = require("neogit.status")
local fs = require("neogit.lib.fs")
local group = require("neogit").autocmd_group

function M.setup()
api.nvim_create_autocmd({ "BufWritePost", "ShellCmdPost", "VimResume" }, {
Expand Down
4 changes: 4 additions & 0 deletions lua/neogit/config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
local M = {}

function M.get_reversed_status_maps()
return vim.tbl_add_reverse_lookup(vim.tbl_deep_extend("force", M.values.mappings.status, {}))
end

M.values = {
disable_hint = false,
disable_context_highlighting = false,
Expand Down
3 changes: 2 additions & 1 deletion lua/neogit/lib/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,9 @@ function Buffer.create(config)
buffer.ui:render(unpack(config.render(buffer)))
end

local neogit_augroup = require("neogit").autocmd_group
for event, callback in pairs(config.autocmds or {}) do
api.nvim_create_autocmd(event, { callback = callback, buffer = buffer.handle })
api.nvim_create_autocmd(event, { callback = callback, buffer = buffer.handle, group = neogit_augroup })
end

buffer.mmanager.register()
Expand Down
8 changes: 8 additions & 0 deletions lua/neogit/lib/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,14 @@ function M:show()
},
}
end,
autocmds = {
["WinLeave"] = function()
if self.buffer.kind == "floating" then
-- We pcall this because it's possible the window was closed by a command invocation, e.g. "cc" for commits
pcall(self.close, self)
end
end,
},
}
end

Expand Down
5 changes: 5 additions & 0 deletions lua/neogit/lib/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ local function lists_equal(l1, l2)
return true
end

local function pad_right(s, len)
return s .. string.rep(" ", math.max(len - #s, 0))
end

return {
time = time,
time_async = time_async,
Expand Down Expand Up @@ -307,4 +311,5 @@ return {
str_clamp = str_clamp,
remove_item_from_table = remove_item_from_table,
lists_equal = lists_equal,
pad_right = pad_right,
}
4 changes: 1 addition & 3 deletions lua/neogit/popups/help/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ local util = require("neogit.lib.util")
local NONE = function() end

-- Using deep extend this way creates a copy of the mapping values
local status_mappings = vim.tbl_add_reverse_lookup(
vim.tbl_deep_extend("force", require("neogit.config").values.mappings.status, {})
)
local status_mappings = require("neogit.config").get_reversed_status_maps()

local function present(commands)
local presenter = util.map(commands, function(command)
Expand Down
2 changes: 1 addition & 1 deletion lua/neogit/popups/rebase/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function M.create(commit)
:action_if(not in_rebase, "f", "to autosquash")
:env({
commit = commit,
highlight = { branch, git.repo.upstream.ref },
highlight = { branch, git.repo.upstream.ref, base_branch },
bold = { "@{upstream}", "pushRemote" },
})
:build()
Expand Down
4 changes: 2 additions & 2 deletions lua/neogit/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ local function create_preview_buffer()
-- May be called multiple times due to scheduling
if preview_buffer then
if preview_buffer.buffer then
logger.debug("Preview buffer already exists. Focusing the existing one")
logger.trace("[PROCESS] Preview buffer already exists. Focusing the existing one")
preview_buffer.buffer:focus()
end
return
Expand Down Expand Up @@ -360,7 +360,7 @@ function Process:spawn(cb)
end
end

logger.debug("Spawning: " .. vim.inspect(self.cmd))
logger.trace("[PROCESS] Spawning: " .. vim.inspect(self.cmd))
local job = vim.fn.jobstart(self.cmd, {
cwd = self.cwd,
env = self.env,
Expand Down
24 changes: 18 additions & 6 deletions lua/neogit/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local F = require("neogit.lib.functional")
local LineBuffer = require("neogit.lib.line_buffer")
local fs = require("neogit.lib.fs")
local input = require("neogit.lib.input")
local util = require("neogit.lib.util")

local map = require("neogit.lib.util").map
local api = vim.api
Expand Down Expand Up @@ -145,17 +146,28 @@ local function format_mode(mode)
return mode
end

local function pad_right(s, len)
return s .. string.rep(" ", math.max(len - #s, 0))
end

local function draw_buffer()
M.status_buffer:clear_sign_group("hl")
M.status_buffer:clear_sign_group("fold_markers")

local output = LineBuffer.new()
if not config.values.disable_hint then
output:append("Hint: [<tab>] toggle diff | [s]tage | [u]nstage | [x] discard | [c]ommit | [?] more help")
local reversed_status_map = config.get_reversed_status_maps()

local function hint_label(map_name, hint)
return "[" .. reversed_status_map[map_name] .. "] " .. hint
end

local hints = {
hint_label("Toggle", "toggle diff"),
hint_label("Stage", "stage"),
hint_label("Unstage", "unstage"),
hint_label("Discard", "discard"),
hint_label("CommitPopup", "commit"),
hint_label("HelpPopup", "help"),
}

output:append("Hint: " .. table.concat(hints, " | "))
output:append("")
end

Expand Down Expand Up @@ -207,7 +219,7 @@ local function draw_buffer()
location.files = {}

for _, f in ipairs(data.items) do
local label = pad_right(format_mode(f.mode), max_len)
local label = util.pad_right(format_mode(f.mode), max_len)
if label and vim.o.columns < 120 then
label = vim.trim(label)
end
Expand Down

0 comments on commit 7ce8680

Please sign in to comment.