feat(git): blob entries from a tree get filetype-aware loading

This commit is contained in:
2026-04-28 11:21:30 +02:00
parent 8425545087
commit a0c87b9b7b
+19 -3
View File
@@ -261,17 +261,33 @@ 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. Tree-entry lines `<mode> <type> <sha>\t<name>`
-- navigate to a child blob or subtree.
-- another git object.
local sha = line:match("^parent (%x+)$")
or line:match("^tree (%x+)$")
or line:match("^object (%x+)$")
or line:match("^%d+ %w+ (%x+)\t.+$")
if sha then
M.open_object(ctx.worktree, sha, { split = false })
return true
end
-- Tree-entry navigation: `<mode> <type> <sha>\t<name>`. Blob entries
-- route through `diff.git_show_buf` so the buffer URI carries the
-- entry name and BufReadCmd / BufReadPost resolve filetype from it.
-- Other types (subtrees, submodule commit refs, tags) fall through
-- to the generic SHA-based opener.
local entry_type, entry_sha, entry_name =
line:match("^%d+ (%w+) (%x+)\t(.+)$")
if entry_sha then
if entry_type == "blob" then
local buf = diff.git_show_buf(ctx.worktree, ctx.ref, entry_name)
vim.cmd.normal({ "m'", bang = true })
vim.api.nvim_set_current_buf(buf)
else
M.open_object(ctx.worktree, entry_sha, { split = false })
end
return true
end
local section = diff_section()
if not section then
return false