nvim-tree / nvim-tree/nvim-tree.lua
repeated calls to git rev-parse --show-toplevel for untracked directories
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 8.6k
- Forks
- 639
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 2
Description
Description
Before excluding /tmp from git watcher I noticed cursor flickering and unneeded autocommands repeated for every few seconds. It happens only when I use Nvim as root and some additional root-owned directories are accessible in /tmp.
https://github.com/user-attachments/assets/013bc931-0363-4564-8dab-b17718af02d1
https://github.com/user-attachments/assets/c36aad56-1291-473d-8f97-32042a759280
It's a side effect of checking why NvimTree switches the root directory without user interaction.
Neovim version
v0.12.0-dev-914+gb79ff967ac
Operating system and version
Debian Sid
Windows variant
No response
nvim-tree version
65bae449224b8a3bc149471b96587b23b13a9946
Clean room replication
local thisInitFile = debug.getinfo(1).source:match('@?(.*)')
local cwd = vim.fs.dirname(thisInitFile)
local appname = vim.env.NVIM_APPNAME or 'nvim'
vim.env.XDG_CONFIG_HOME = cwd
vim.env.XDG_DATA_HOME = vim.fs.joinpath(cwd, '.xdg', 'data')
vim.env.XDG_STATE_HOME = vim.fs.joinpath(cwd, '.xdg', 'state')
vim.env.XDG_CACHE_HOME = vim.fs.joinpath(cwd, '.xdg', 'cache')
vim.fn.mkdir(vim.fs.joinpath(vim.env.XDG_CACHE_HOME, appname), 'p')
local stdPathConfig = vim.fn.stdpath('config')
vim.opt.runtimepath:prepend(stdPathConfig)
vim.opt.packpath:prepend(stdPathConfig)
local extuiExists, extui = pcall(require, 'vim._extui')
if extuiExists then
extui.enable({enable = true, msg = {target = 'msg'}})
end
local function gitClone(url, installPath, branch)
if vim.fn.isdirectory(installPath) ~= 0 then
return
end
local command = {'git', 'clone', '--', url, installPath}
if branch then
table.insert(command, 3, '--branch')
table.insert(command, 4, branch)
end
vim.notify(('Cloning %s dependency into %s...'):format(url, installPath), vim.log.levels.INFO, {})
local sysObj = vim.system(command, {}):wait()
if sysObj.code ~= 0 then
error(sysObj.stderr)
end
vim.notify(sysObj.stdout)
vim.notify(sysObj.stderr, vim.log.levels.WARN)
end
local pluginsPath = vim.fs.joinpath(cwd, 'nvim/pack/plugins/opt')
vim.fn.mkdir(pluginsPath, 'p')
pluginsPath = vim.uv.fs_realpath(pluginsPath)
--- @type table<string, {url:string, branch: string?}>
local plugins = {
['nvim-tree'] = {url = 'https://github.com/przepompownia/nvim-tree.lua'},
}
for name, repo in pairs(plugins) do
local installPath = vim.fs.joinpath(pluginsPath, name)
gitClone(repo.url, installPath, repo.branch)
vim.opt.runtimepath:append(installPath)
end
vim.api.nvim_create_autocmd('UIEnter', {
once = true,
callback = function ()
require('nvim-tree').setup({
})
end,
})
vim._extui is used only for convenience and isn't necessary.
Steps to reproduce
With the above init.lua (and probably specific /tmp subdirs generated by systemd services) I need the following steps (as root only):
nvim --clean -u init.lua:NvimTreeOpen /tmp- observe flickering, and optionally autocommand logs with
set verbose=9
I'm aware that the reproduction can depend on the presence of some specific directories. At the moment I have no idea how to create reproducible directory structure for a regular user.
Expected behavior
No unneeded events and flickering.
Actual behavior
As in the title and description. Flickering continues even after closing NvimTree, and seems to be related to executing git command (don't know why only on the *apache* subdirectory).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied init.lua and the nvim-tree setup, then reproduce with :NvimTreeOpen /tmp as root while reviewing the verbose autocommand log. Trace the repeated git rev-parse --show-toplevel calls around untracked directories; done means opening and closing NvimTree causes no unnecessary events or cursor flickering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, lua
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100