diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 5cdaad72bd1..e2c894d10bc 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -626,6 +626,7 @@ Git integration with icons and colors. *nvim-tree.git.timeout* Kills the git process after some time if it takes too long. + Git integration will be disabled after 10 git jobs exceed this timeout. Type: `number`, Default: `400` (ms) You will still need to set |renderer.icons.show.git| `= true` or diff --git a/lua/nvim-tree/git/init.lua b/lua/nvim-tree/git/init.lua index 7bf7f542d85..c5be4ef02f1 100644 --- a/lua/nvim-tree/git/init.lua +++ b/lua/nvim-tree/git/init.lua @@ -176,6 +176,13 @@ function M.purge_state() M.cwd_to_project_root = {} end +--- Disable git integration permanently +function M.disable_git_integration() + log.line("git", "disabling git integration") + M.purge_state() + M.config.git.enable = false +end + function M.setup(opts) M.config.git = opts.git M.config.filesystem_watchers = opts.filesystem_watchers diff --git a/lua/nvim-tree/git/runner.lua b/lua/nvim-tree/git/runner.lua index f71ac71f1dc..6c31995b3ee 100644 --- a/lua/nvim-tree/git/runner.lua +++ b/lua/nvim-tree/git/runner.lua @@ -1,9 +1,13 @@ local log = require "nvim-tree.log" local utils = require "nvim-tree.utils" +local notify = require "nvim-tree.notify" local Runner = {} Runner.__index = Runner +local timeouts = 0 +local MAX_TIMEOUTS = 5 + function Runner:_parse_status_output(status, path) -- replacing slashes if on windows if vim.fn.has "win32" == 1 then @@ -159,6 +163,17 @@ function Runner.run(opts) if self.rc == -1 then log.line("git", "job timed out %s %s", opts.project_root, opts.path) + timeouts = timeouts + 1 + if timeouts == MAX_TIMEOUTS then + notify.warn( + string.format( + "%d git jobs have timed out after %dms, disabling git integration. Try increasing git.timeout", + timeouts, + opts.timeout + ) + ) + require("nvim-tree.git").disable_git_integration() + end elseif self.rc ~= 0 then log.line("git", "job fail rc %d %s %s", self.rc, opts.project_root, opts.path) else