feat(git): blob entries from a tree get filetype-aware loading
This commit is contained in:
+19
-3
@@ -261,17 +261,33 @@ function M.open_under_cursor()
|
|||||||
|
|
||||||
-- Cat-file header navigation: `parent <sha>` (commit), `tree <sha>`
|
-- Cat-file header navigation: `parent <sha>` (commit), `tree <sha>`
|
||||||
-- (commit / tag), `object <sha>` (tag's referent) all reference
|
-- (commit / tag), `object <sha>` (tag's referent) all reference
|
||||||
-- another git object. Tree-entry lines `<mode> <type> <sha>\t<name>`
|
-- another git object.
|
||||||
-- navigate to a child blob or subtree.
|
|
||||||
local sha = line:match("^parent (%x+)$")
|
local sha = line:match("^parent (%x+)$")
|
||||||
or line:match("^tree (%x+)$")
|
or line:match("^tree (%x+)$")
|
||||||
or line:match("^object (%x+)$")
|
or line:match("^object (%x+)$")
|
||||||
or line:match("^%d+ %w+ (%x+)\t.+$")
|
|
||||||
if sha then
|
if sha then
|
||||||
M.open_object(ctx.worktree, sha, { split = false })
|
M.open_object(ctx.worktree, sha, { split = false })
|
||||||
return true
|
return true
|
||||||
end
|
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()
|
local section = diff_section()
|
||||||
if not section then
|
if not section then
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user