feat(git/repo): add Repo:head_sha for cached HEAD blob lookups
This commit is contained in:
@@ -97,6 +97,25 @@ t.test("index_sha cache clears when the index is written", function()
|
||||
wait_cleared(r, "index:a", 2000)
|
||||
end)
|
||||
|
||||
t.test("head_sha returns the blob sha and caches it", function()
|
||||
local dir = h.make_repo({ a = "x\n" })
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
local sha = r:head_sha("a")
|
||||
t.truthy(sha and #sha > 0, "head_sha returns the HEAD blob sha")
|
||||
t.truthy(r._cache["head_blob:a"] ~= nil, "the result is cached")
|
||||
t.eq(r:head_sha("a"), sha, "a cached call returns the same sha")
|
||||
end)
|
||||
|
||||
t.test("head_sha cache clears when HEAD moves", function()
|
||||
local dir = h.make_repo({ a = "x\n" })
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
r:head_sha("a")
|
||||
t.truthy(r._cache["head_blob:a"] ~= nil, "sha is cached before the commit")
|
||||
t.write(dir, "a", "y\n")
|
||||
h.git(dir, "commit", "-aqm", "change")
|
||||
wait_cleared(r, "head_blob:a", 2000)
|
||||
end)
|
||||
|
||||
t.test("cache clears after top-level .git change (commit)", function()
|
||||
local dir = h.make_repo({ a = "x" })
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
|
||||
Reference in New Issue
Block a user