Skip to content

1970 disable git after 5 timeouts #1990

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

Merged
merged 9 commits into from
Feb 12, 2023
Merged
1 change: 1 addition & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lua/nvim-tree/git/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions lua/nvim-tree/git/runner.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down