diff --git a/lua/git/object.lua b/lua/git/object.lua index d14f76f..15a1643 100644 --- a/lua/git/object.lua +++ b/lua/git/object.lua @@ -261,17 +261,33 @@ function M.open_under_cursor() -- Cat-file header navigation: `parent ` (commit), `tree ` -- (commit / tag), `object ` (tag's referent) all reference - -- another git object. Tree-entry lines ` \t` - -- 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: ` \t`. 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