refactor: attach
Some checks are pending
CI / commit_lint (push) Waiting to run
CI / test (nightly) (push) Waiting to run
CI / test (v0.10.0) (push) Waiting to run
CI / test (v0.9.5) (push) Waiting to run
CI / stylua (push) Waiting to run
CI / luals (push) Waiting to run
CI / doc (push) Waiting to run
release-please / release-please (push) Waiting to run
release-please / luarocks-upload (push) Blocked by required conditions
release-please / update-doc (push) Blocked by required conditions

This commit is contained in:
Lewis Russell 2025-01-21 17:32:44 +00:00 committed by Lewis Russell
parent 2914235f0e
commit 2ff0c29f2a

View File

@ -92,25 +92,6 @@ local function on_attach_pre(bufnr)
return gitdir, toplevel
end
--- @param _bufnr integer
--- @param file string
--- @param revision string?
--- @param encoding string
--- @return Gitsigns.GitObj?
local function try_worktrees(_bufnr, file, revision, encoding)
if not config.worktrees then
return
end
for _, wt in ipairs(config.worktrees) do
local git_obj = git.Obj.new(file, revision, encoding, wt.gitdir, wt.toplevel)
if git_obj and git_obj.object_name then
dprintf('Using worktree %s', vim.inspect(wt))
return git_obj
end
end
end
local setup = util.once(function()
manager.setup()
@ -237,10 +218,12 @@ local attach_throttled = throttle_by_id(function(cbuf, ctx, aucmd)
local git_obj = git.Obj.new(file, revision, encoding, ctx.gitdir, ctx.toplevel)
if not git_obj and not passed_ctx then
git_obj = try_worktrees(cbuf, file, revision, encoding)
async.scheduler()
if not api.nvim_buf_is_valid(cbuf) then
return
for _, wt in ipairs(config.worktrees or {}) do
git_obj = git.Obj.new(file, revision, encoding, wt.gitdir, wt.toplevel)
if git_obj and git_obj.object_name then
dprintf('Using worktree %s', vim.inspect(wt))
break
end
end
end