fix(git): validate placement, cache repo lookups, tighten lifecycle

This commit is contained in:
2026-05-10 04:47:35 +02:00
parent cb47177382
commit 8624f825eb
4 changed files with 35 additions and 2 deletions
+15
View File
@@ -204,6 +204,7 @@ function Repo:close()
end
self._watchers = {}
self._refresh_handle.close()
self._events:clear()
end
---@param event ow.Git.Repo.Event
@@ -344,6 +345,9 @@ end
---@type table<string, ow.Git.Repo> keyed by worktree
local repos = {}
---@type table<string, true>
local no_repo_dirs = {}
---@param event ow.Git.Repo.Event
---@param fn fun(...)
---@return fun() unsubscribe
@@ -440,8 +444,13 @@ function M.resolve(arg)
else
path = path_for_buf(expand_buf(arg))
end
local dir = vim.fs.dirname(path)
if no_repo_dirs[dir] then
return nil
end
local found = vim.fs.find(".git", { upward = true, path = path })[1]
if not found then
no_repo_dirs[dir] = true
return nil
end
local worktree = vim.fs.dirname(found)
@@ -473,6 +482,11 @@ function M.resolve(arg)
end
local r = Repo.new(gitdir, worktree)
repos[worktree] = r
for d in pairs(no_repo_dirs) do
if d == worktree or vim.startswith(d, worktree .. "/") then
no_repo_dirs[d] = nil
end
end
return r
end
@@ -547,6 +561,7 @@ function M.refresh_all()
end
function M.update_cwd_repo()
no_repo_dirs = {}
local tab = vim.api.nvim_get_current_tabpage()
local new = M.resolve(vim.fn.getcwd())
local old