feat(git): navigate any git object from cat-file headers

This commit is contained in:
2026-04-28 13:55:33 +02:00
parent 68f2ad1b52
commit 03c6cb9ddc
2 changed files with 19 additions and 9 deletions
+7 -1
View File
@@ -119,7 +119,13 @@ local function run_in_split(worktree, args, conf)
vim.b[buf].git_parent_ref =
repo.rev_parse(worktree, user_ref .. "^", true)
end
pcall(vim.api.nvim_buf_set_name, buf, "git://" .. (sha or user_ref))
-- Per-subcommand scheme so `:G show <sha>` doesn't collide with
-- the cat-file URI form `git://<sha>` used by the gitlog flow.
pcall(
vim.api.nvim_buf_set_name,
buf,
"git" .. args[1] .. "://" .. (sha or user_ref)
)
vim.bo[buf].filetype = conf.ft
else
vim.bo[buf].filetype = conf.ft
+12 -8
View File
@@ -115,18 +115,21 @@ local function show_diff(ctx, section)
return
end
local parent = ctx.parent_ref or "0"
-- blob_buf handles the absent (zero-blob) case by returning an empty
-- buffer, which keeps `:diffsplit` from triggering BufReadCmd against
-- a non-existent revspec and logging an error.
local left =
blob_buf(ctx.worktree, section.pre_blob, section.pre_path, parent)
local right =
blob_buf(ctx.worktree, section.post_blob, section.post_path, ctx.ref)
vim.cmd.normal({ "m'", bang = true })
local left_win = vim.api.nvim_get_current_win()
vim.api.nvim_set_current_buf(left)
vim.wo[left_win].diff = true
local right_win =
vim.api.nvim_open_win(right, true, { split = "right", win = left_win })
vim.wo[right_win].diff = true
vim.api.nvim_set_current_win(left_win)
vim.api.nvim_set_current_buf(right)
-- `:diffsplit` is the same path `M.split` uses; Vim's built-in diff
-- machinery handles the diff option setup on both windows.
vim.cmd(
"leftabove vert diffsplit "
.. vim.fn.fnameescape(vim.api.nvim_buf_get_name(left))
)
end
---@class ow.Git.OpenCommitOpts
@@ -265,7 +268,8 @@ function M.open_under_cursor()
-- Cat-file header navigation: `parent <sha>` (commit), `tree <sha>`
-- (commit / tag), `object <sha>` (tag's referent) all reference
-- another git object.
local sha = line:match("^parent (%x+)$")
local sha = line:match("^commit (%x+)$")
or line:match("^parent (%x+)$")
or line:match("^tree (%x+)$")
or line:match("^object (%x+)$")
if sha then