18 lines
781 B
Lua
18 lines
781 B
Lua
-- The built-in `git` filetype is reused for our `:G show` / `:G cat-file -p`
|
|
-- output buffers and for commits opened from the log window. We set
|
|
-- `vim.b.git_worktree` before assigning the filetype on those buffers; the
|
|
-- guard below keeps the <CR> dispatcher off any unrelated git buffer (a
|
|
-- real `.git/HEAD` file, etc.) so the default normal-mode <CR> still works.
|
|
if not vim.b.git_worktree then
|
|
return
|
|
end
|
|
|
|
local cr = vim.api.nvim_replace_termcodes("<CR>", true, false, true)
|
|
|
|
vim.keymap.set("n", "<CR>", function()
|
|
if not require("git.object").open_under_cursor() then
|
|
-- "n" mode = no remap, so this doesn't recurse into our mapping.
|
|
vim.api.nvim_feedkeys(cr, "n", false)
|
|
end
|
|
end, { buffer = 0, silent = true, desc = "Open file at commit" })
|