Skip to content

Commit 36e29c3

Browse files
authored
fix(#1970): disable git integration after 5 timeouts (#1990)
* fix(#1970): additional log function gating for efficiency when not logging * fix(#1970): additional log function gating for efficiency when not logging * fix(#1970): disable git integration after 10 timeouts * fix(#1970): disable git integration after 10 timeouts * fix(#1970): disable git integration after 10 timeouts * fix(#1970): cleanly kill timed out git processes * fix(#1970): revert git kill, to be completed via #1974 experiment * fix(#1970): revert git kill, to be completed via #1974 experiment
1 parent b712b82 commit 36e29c3

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

doc/nvim-tree-lua.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ Git integration with icons and colors.
626626

627627
*nvim-tree.git.timeout*
628628
Kills the git process after some time if it takes too long.
629+
Git integration will be disabled after 10 git jobs exceed this timeout.
629630
Type: `number`, Default: `400` (ms)
630631

631632
You will still need to set |renderer.icons.show.git| `= true` or

lua/nvim-tree/git/init.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ function M.purge_state()
176176
M.cwd_to_project_root = {}
177177
end
178178

179+
--- Disable git integration permanently
180+
function M.disable_git_integration()
181+
log.line("git", "disabling git integration")
182+
M.purge_state()
183+
M.config.git.enable = false
184+
end
185+
179186
function M.setup(opts)
180187
M.config.git = opts.git
181188
M.config.filesystem_watchers = opts.filesystem_watchers

lua/nvim-tree/git/runner.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
local log = require "nvim-tree.log"
22
local utils = require "nvim-tree.utils"
3+
local notify = require "nvim-tree.notify"
34

45
local Runner = {}
56
Runner.__index = Runner
67

8+
local timeouts = 0
9+
local MAX_TIMEOUTS = 5
10+
711
function Runner:_parse_status_output(status, path)
812
-- replacing slashes if on windows
913
if vim.fn.has "win32" == 1 then
@@ -159,6 +163,17 @@ function Runner.run(opts)
159163

160164
if self.rc == -1 then
161165
log.line("git", "job timed out %s %s", opts.project_root, opts.path)
166+
timeouts = timeouts + 1
167+
if timeouts == MAX_TIMEOUTS then
168+
notify.warn(
169+
string.format(
170+
"%d git jobs have timed out after %dms, disabling git integration. Try increasing git.timeout",
171+
timeouts,
172+
opts.timeout
173+
)
174+
)
175+
require("nvim-tree.git").disable_git_integration()
176+
end
162177
elseif self.rc ~= 0 then
163178
log.line("git", "job fail rc %d %s %s", self.rc, opts.project_root, opts.path)
164179
else

0 commit comments

Comments
 (0)