Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(blame): ensure blame object is valid when all lines are requested #1171

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/gitsigns/blame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ local function menu(name, items)
end

--- @async
M.blame = function()
function M.blame()
local __FUNC__ = 'blame'
local bufnr = api.nvim_get_current_buf()
local win = api.nvim_get_current_win()
Expand Down
25 changes: 24 additions & 1 deletion lua/gitsigns/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ function CacheEntry:run_blame(lnum, opts)
return blame, lnum0 == nil
end

--- @private
--- @param lnum? integer
--- @return boolean
function CacheEntry:blame_valid(lnum)
local blame = self.blame
if not blame then
return false
end

if lnum then
return blame[lnum] ~= nil
end

-- Need to check we have blame info for all lines
for i = 1, vim.api.nvim_buf_line_count(self.bufnr) do
if not blame[i] then
return false
end
end

return true
end

--- If lnum is nil then run blame for the entire buffer.
--- @async
--- @param lnum? integer
Expand All @@ -109,7 +132,7 @@ end
function CacheEntry:get_blame(lnum, opts)
local blame = self.blame

if not blame or (lnum and not blame[lnum]) then
if not blame or not self:blame_valid(lnum) then
self:wait_for_hunks()
blame = blame or {}
local Hunks = require('gitsigns.hunks')
Expand Down
Loading