Skip to content

Commit

Permalink
fix(git_status): correctly count result on_complete (#3321)
Browse files Browse the repository at this point in the history
The previous implementation with `self.manager:num_results()` could return
0 despite having results due to suspected async/event loop issues
(#3316). This change counts valid entries manually to ensure accurate
result count.
  • Loading branch information
jamestrew authored Oct 10, 2024
1 parent dc6fc32 commit df534c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lua/telescope/builtin/__git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,18 @@ git.status = function(opts)
sorter = conf.file_sorter(opts),
on_complete = {
function(self)
local lines = self.manager:num_results()
local prompt = action_state.get_current_line()
if lines == 0 and prompt == "" then

-- HACK: self.manager:num_results() can return 0 despite having results
-- due to some async/event loop shenanigans (#3316)
local count = 0
for _, entry in pairs(self.finder.results) do
if entry and entry.valid ~= false then
count = count + 1
end
end

if count == 0 and prompt == "" then
utils.notify("builtin.git_status", {
msg = "No changes found",
level = "ERROR",
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/make_entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ function make_entry.gen_from_git_status(opts)
return nil
end

return setmetatable({
return make_entry.set_default_entry_mt({
value = file,
status = mod,
ordinal = entry,
Expand Down

0 comments on commit df534c3

Please sign in to comment.