Skip to content

Commit

Permalink
refactor: attach
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Jan 21, 2025
1 parent 2914235 commit 2ff0c29
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions lua/gitsigns/attach.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2ff0c29

Please sign in to comment.