feat(object): use <commit>:<path> URIs when entering a file from a commit dump

This commit is contained in:
2026-05-27 00:18:55 +02:00
parent 79120ed4f7
commit c4585b7768
3 changed files with 120 additions and 26 deletions
+50 -10
View File
@@ -202,18 +202,58 @@ t.test("open_under_cursor on a 'parent <sha>' line opens the parent", function()
t.eq(vim.api.nvim_buf_get_name(0), "git://" .. parent_sha)
end)
t.test("open_under_cursor on a '+++ b/<path>' line loads the blob", function()
local dir = h.make_repo({ ["a.txt"] = "first\n" })
local r = assert(require("git.core.repo").resolve(dir))
local blob_sha = h.git(dir, "rev-parse", "HEAD:a.txt").stdout
t.test(
"open_under_cursor on a '+++ b/<path>' line opens the file at the commit",
function()
local dir = h.make_repo({ ["a.txt"] = "first\n" })
local r = assert(require("git.core.repo").resolve(dir))
local commit_sha = h.git(dir, "rev-parse", "HEAD").stdout
object.open(r, "HEAD", { split = false })
local lnum = assert(find_line(0, "+++ b/a.txt"), "expected a +++ line")
vim.api.nvim_win_set_cursor(0, { lnum, 0 })
object.open(r, "HEAD", { split = false })
local lnum = assert(find_line(0, "+++ b/a.txt"), "expected a +++ line")
vim.api.nvim_win_set_cursor(0, { lnum, 0 })
t.truthy(object.open_under_cursor())
t.eq(vim.api.nvim_buf_get_name(0), "git://" .. blob_sha)
end)
t.truthy(object.open_under_cursor())
t.eq(vim.api.nvim_buf_get_name(0), "git://" .. commit_sha .. ":a.txt")
end
)
t.test(
"open_under_cursor on a '--- a/<path>' line opens the parent at that path",
function()
local dir = h.make_repo({ ["a.txt"] = "first\n" })
t.write(dir, "a.txt", "second\n")
h.git(dir, "add", "a.txt")
h.git(dir, "commit", "-q", "-m", "second")
local r = assert(require("git.core.repo").resolve(dir))
local parent_sha = h.git(dir, "rev-parse", "HEAD~").stdout
object.open(r, "HEAD", { split = false })
local lnum = assert(find_line(0, "--- a/a.txt"), "expected a --- line")
vim.api.nvim_win_set_cursor(0, { lnum, 0 })
t.truthy(object.open_under_cursor())
t.eq(vim.api.nvim_buf_get_name(0), "git://" .. parent_sha .. ":a.txt")
end
)
t.test(
"open_under_cursor on a tree-entry blob still uses the bare blob URI",
function()
local dir = h.make_repo({ ["a.txt"] = "first\n" })
local r = assert(require("git.core.repo").resolve(dir))
local tree_sha = h.git(dir, "rev-parse", "HEAD^{tree}").stdout
local blob_sha = h.git(dir, "rev-parse", "HEAD:a.txt").stdout
object.open(r, tree_sha, { split = false })
local lnum =
assert(find_line(0, "100644 blob "), "expected a tree entry line")
vim.api.nvim_win_set_cursor(0, { lnum, 0 })
t.truthy(object.open_under_cursor())
t.eq(vim.api.nvim_buf_get_name(0), "git://" .. blob_sha)
end
)
t.test("open_under_cursor returns false on a non-dispatchable line", function()
local dir = h.make_repo({ a = "first\n" })