Skip to content

repeated calls to git rev-parse --show-toplevel for untracked directories #3171

@przepompownia

Description

@przepompownia

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.

nvim-tree-flicker3.mp4
nvim-tree-flicker2.mp4

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

65bae44

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingperformanceperformance enhancementregressionExisting functionality brokenreproducedIssue confirmed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions