Nvim-tree.lua: attempt to concatenate local 'git_root' (a nil value)

Created on 1 Jun 2020  路  24Comments  路  Source: kyazdani42/nvim-tree.lua

Error detected while processing VimEnter Autocommands for "*":
E5108: Error executing lua ...e/lks/.config/nvim/plugged/nvim-tree.lua/lua/lib/git.lua:68: attempt to concatenate local 'git_root' (a nil value)

bug

All 24 comments

i did not manage to reproduce, even with your nvim configuration.
Could you give me the name of the folder in which you try to open neovim so i can see why this is happening ?

Hi @theHamsta @chmln @rickysaurav @Akin909 @marekkon @kyazdani42
i'm running nvim v0.5.0-590-gb39edb5b6 and nvim-tree.lua in the latest version, i'm able to replicate this issue in long nested path git repositories, below the confusion directory inside a long nested path throw the error
i
2020-07-09 18 26 51
unlike the same confusion directory inside the home ~ directory
2020-07-09 18 27 38

Yep this one is definitely happening I've seen it loads, It seems to happen when you switch directories i.e. project1/buffer1 to project2/bufffer1 if they are in different parts of the file system that seems to cause a big issue

is this still relevant ?

@kyazdani42 I haven't personally seen it since but I also haven't been trying to reproduce it nor have I used the steps @juangabrielr4 mentioned above, but I work in a fairly nested and enormous monorepo and I haven't seen this for at least a day now

allright, we'll leave this open in case it appears again.

@kyazdani42, this error pops up when I'm working in a Git worktree. Saving any files without any changes in a worktree directory is enough to trigger the error.

i'll push a fix when i have some time. I've never used such git feature but will likely do :)

@gbrlsnchs i did not manage to reproduce the error with a git worktree.
Could you try to make a more detailed step by step way to trigger the error ?
Also which neovim version are you using, and which version of the plugin ?

Got this one again today, the context was I made a new project then initialised it as a git repo from the nvim terminal after having opened lua tree. I saved the session, then whenever I open it again now it errors
git-root-bug

Seems to happen specifically BufEnter when switching buffers, or if I try and interact with the tree at all once the first error appears

馃 Just tried to reproduce it in a completely new project that I then turned into a repo but it didn't seem to happen again 馃槙 not sure how this is happening tbh

Hi! I seem to be experiencing this issue as well:

If I start Neovim from my home directory and try to edit a file anywhere on my system, I get this error each time I try to write the file:

"/tmp/test" [New] 0L, 0C written
Error detected while processing BufWritePost Autocommands for "*":
E5108: Error executing lua .../.config/nvim/dein/.cache/init.vim/.dein/lua/lib/git.lua:67: attempt to concatenate local 'git_root' (a nil value)
Press ENTER or type command to continue

It doesn't matter where the file I'm editing is, whether it's within a git repository or not, or whether it exists or not. The only thing that seems to matter is whether I start vim while my $PWD is $HOME. My home directory is not a git repository, nor is it contained within one.

Oddly, if I launch vim from my home directory and :cd to /tmp/, the error still occurs upon saving a file. However, if I launch vim from /tmp/ and :cd to my home directory, the error does not occur.

So far I am not aware of any directory other than my home directory which exhibits this behavior.

Also, it does not matter if LuaTree has been opened or not.

Versions:

  • nvim: v0.5.0-763-geaee3d929

  • nvim-tree.lua: 87a4d60bbcdf1161cb70d54a700106fd84b07f0f

ill take a look when if have some time :) thanks for the repro

I cannot reproduce. I thought this issue was fixed long ago, maybe there are some files with characters i don't properly match. I'm not sure wich those are.

Odd. Maybe a workaround would be to check if git_root is nil before trying to concatenate it inside M.updateStatus?

https://github.com/kyazdani42/nvim-tree.lua/blob/6c2ee962079b51a868770560fde3e734eadcf91c/lua/lib/git.lua#L67

It seems that you're checking git_root once, then if it's nil you try to create_root, but you don't check if it's nil again after doing so.

https://github.com/kyazdani42/nvim-tree.lua/blob/6c2ee962079b51a868770560fde3e734eadcf91c/lua/lib/git.lua#L57-L65

So maybe this would work?

  local git_root, git_status = get_git_root(cwd)
  if not git_root then
    if not create_root(cwd) then
      return
    end
    git_root, git_status = get_git_root(cwd)
    if not git_root then
      return
    end
  elseif git_status == not_git then
    return
  end

I haven't looked much into the code, this is just a guess.

Edit: I tested this locally and it seems to have fixed the error.

i know about that, but i like keeping this kind of errors so i can fix the underlying issue. I know this might be caused by a matching gone wrong, but i cannot fix it if i don't have more informations about the filesystem (specially file names that might have weird characters which would cause the lua matching to break).
But i'm working on a big rewrite, and i'll probably use libgit2 which has bindings for lua.

Ok, I just looked through my home directory. I unknowingly had a directory literally named $HOME due to a typo in a configuration causing that variable not to be expanded before creating a directory. Removing that directory resolved the error.

I'll keep this open in the meanwhile :) i could not reproduce de git root error but i had other kind of errors popping in.

hi, I have some error:

attempt to concatenate local 'git_root' (a nil value)

I test path.
I find my path include '_',this error is happen!
I'm sorry I will not lua to fix this bug,
if you Want more information, tell me ,
oh, I use mac.

nvim/luatree version (commit) ?
underscore is handled, it never was an issue, the problem might come from somewhere else.
Anyway in the next version, it will be handled in a different way that will not require escaping strings, because it won't rely on matching anymore. please check #123 which will normally fix most issues.

yes, not underscore,
I have this error is in web program,
they has node_modules folder,
I delete node_modules folder, It's not error.
and I checkout rewrite branch, and error too.

please see #123, when it's done, everything will be fixed, i wont spend time on these issues anymore sorry.

Same issue when open nvim.
image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kristijanhusak picture kristijanhusak  路  5Comments

gmr458 picture gmr458  路  5Comments

chinnkarahoi picture chinnkarahoi  路  7Comments

AckslD picture AckslD  路  5Comments

CantoroMC picture CantoroMC  路  7Comments