From f4e6abc5fbb3baffb7a278cb9daa1dccc0cae296 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Fri, 15 Mar 2024 23:21:44 -0500 Subject: [PATCH] fix(nvim): ensure Neogit's status is refreshed as necessary --- dots/.config/nvim/lua/plugins/configs/git.lua | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/dots/.config/nvim/lua/plugins/configs/git.lua b/dots/.config/nvim/lua/plugins/configs/git.lua index 49650397..a69c8634 100644 --- a/dots/.config/nvim/lua/plugins/configs/git.lua +++ b/dots/.config/nvim/lua/plugins/configs/git.lua @@ -36,11 +36,36 @@ return { end, }) + local ensure_neogit_refresh = function() + local times_to_repeat = 10 + local neogit = require("neogit") + if not neogit then + return + end + + neogit.dispatch_refresh() + local repeat_attempt = 0 + while repeat_attempt < times_to_repeat do + repeat_attempt = repeat_attempt + 1 + vim.wait(100, function() + pcall(neogit.dispatch_refresh) + return true + end) + end + end + vim.api.nvim_create_autocmd("BufEnter", { pattern = "*Neogit*", callback = function() - require("neogit").dispatch_refresh() - end + ensure_neogit_refresh() + end, + }) + + vim.api.nvim_create_autocmd("User", { + pattern = "^Neogit*", + callback = function() + ensure_neogit_refresh() + end, }) ---@type NeogitConfig