test(git): cover resolve_sha, place_split reuse, content dispatch

This commit is contained in:
2026-05-08 00:31:57 +02:00
parent 715e47d449
commit 4649b803ab
2 changed files with 131 additions and 0 deletions
+27
View File
@@ -111,6 +111,33 @@ t.test("cache clears after deeply nested slash branch", function()
t.eq(refs, { "deep/a/b/c", "main" })
end)
t.test("resolve_sha returns ok + full sha for a known blob", function()
local dir = make_repo({ a = "hello\n" })
local r = assert(require("git.repo").resolve(dir))
local blob = vim.trim(git(dir, "rev-parse", "HEAD:a").stdout)
local short = blob:sub(1, 7)
local full, status = r:resolve_sha(short)
t.eq(status, "ok")
t.eq(full, blob)
end)
t.test("resolve_sha returns missing for an unknown prefix", function()
local dir = make_repo({ a = "x" })
local r = assert(require("git.repo").resolve(dir))
local full, status = r:resolve_sha("0000deadbeef")
t.eq(full, nil)
t.eq(status, "missing")
end)
t.test("resolve_sha caches by prefix", function()
local dir = make_repo({ a = "x" })
local r = assert(require("git.repo").resolve(dir))
local blob = vim.trim(git(dir, "rev-parse", "HEAD:a").stdout)
local short = blob:sub(1, 7)
local _, _ = r:resolve_sha(short)
t.truthy(r._cache["resolve:" .. short], "result should be cached")
end)
t.test("watcher cleans up after a slash-branch dir is removed", function()
local dir = make_repo({ a = "x" })
local r = assert(require("git.repo").resolve(dir))