Skip to content
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

Any git directory will report [NvimTree] Could not start the fs_event watcher for path C:\test_project\.git : ENOENT #2467

Closed
mj2068 opened this issue Oct 14, 2023 · 7 comments · Fixed by #2478
Labels
bug Something isn't working OS Windows PowerShell specific to windows powershell

Comments

@mj2068
Copy link
Contributor

mj2068 commented Oct 14, 2023

Description

After a few months without updating any plugins, today i did a :PackerUpdate, opened a random git directory, got this warning:
[NvimTree] Could not start the fs_event watcher for path C:\test_project\.git : ENOENT
After some reading, and comparing the logs with a no-issue ubuntu with mostly the same config. i think there is a newline/return issue there.
I don't think i'm skillful enough to dig deeper, I hope the info i provided here is useful, Thanks.

Neovim version

NVIM v0.9.1
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Operating system and version

Windows 10

nvim-tree version

4054fc4

Clean room replication

unmodified

Steps to reproduce

  1. nvim -nu /tmp/nvt-min.lua C:/any_dir_has_a_.git
  2. :NvimTreeOpen
  3. console pop up, issue arise:
    [NvimTree]
    Could not start the fs_event watcher for path C:\test_project.git
    : ENOENT

Expected behavior

No response

Actual behavior

nvim-tree.zip

@mj2068 mj2068 added the bug Something isn't working label Oct 14, 2023
@alex-courtis
Copy link
Member

alex-courtis commented Oct 15, 2023

i think there is a newline/return issue there.

A newline issue seems plausible. The multiline message is only shown when there is genuinely a newline.

Unfortunately I don't have access to or expertise with windows.

I'd be most grateful if you could test whether we can actally watch a path with that slash pattern:

Please open the following and :source it, with various combinations of a valid directory/file PATH as well as with some newlines.

fs_event_test.lua.gz

@alex-courtis alex-courtis added awaiting feedback OS Windows PowerShell specific to windows powershell labels Oct 15, 2023
@mj2068
Copy link
Contributor Author

mj2068 commented Oct 15, 2023

Ok, @alex-courtis, first of all, thanks for dealing with us "Windows PowerShell/Terminal niche market customers"😛.

I did this on both Ubuntu and Windows, with the a same folder structure like this:
/tmp/test
├── fs_event_test.lua
├── nvt-min.lua
├── project1
│   └── .git
└── project2

I expected and confirmed on ubuntu everything went well, i can give PATH anything, project1, project2, etc. and it will print "success". I can also :NvimTreeOpen, and navigate to any folder, entering them. git tracking also works, untracked file or modified file will have icons before file name.
As to newline characters, if PATH contain either \r or \n, it will fail and print the error message, but i think that is to be expected, because newline characters is not allowed in paths.

Interestingly on Windows, everything worked fine as well, the PATHs i tried all printed "success", which are as follow:
C:/tmp/test
/tmp/test
C:\tmp\test
\tmp\test
It too fails when PATH is given like "C:/tmp/test\r" or "\tmp\test/n", both results printed that "Could not..."message in the fs_event_test.lua script, with a slight difference due do how neovim treats "\r"(display as ^M) and "\n"(actual line change).
console-cr-char
console-newline-char

The problem here on Windows, occurs when in NvimTree File Explorer windows, navigate to a folder that's git initialized(contain a real .git folder) and hit Enter, red error text message will pop up in the console.
console-error

log: nvim-tree_10151730.zip
and i checked the log, it seems that from a certain point(log line 35) the code has received a path with a trailing newline char, which caused subsequent functions to fail.
I then tracked to the source code, and found the line i thought was the source of log line 35, here:
https://github.com/nvim-tree/nvim-tree.lua/blob/aaee4cd896b74f85a81bed7eef2db7869960c4d0/lua/nvim-tree/git/utils.lua#L62C1-L62C1
the function: M.should_show_untracked(cwd) was given that path with a trailing newline char.

that's what I have so far.

@alex-courtis
Copy link
Member

This is great, thank you for testing. It seems that we can be flexible around path formats, just not any sort of newline.

I'll take a look at normalising paths on the weekend.

@alex-courtis
Copy link
Member

I'd be most grateful if you ran a feature flag audit for your windows powershell, to assist us in dealing with this future issues.

Having feature flags we can confidently query may make resolution faster.

Please open and :source this feature flag enumerator:
has.lua.gz

@mj2068
Copy link
Contributor Author

mj2068 commented Oct 16, 2023

feature flags log:
has_list.zip

But, I think I found the problem. Here, line 39 and 43::

-- git always returns path with forward slashes
if vim.fn.has "win32" == 1 then
-- msys2 git support
if has_cygpath then
toplevel = vim.fn.system("cygpath -w " .. vim.fn.shellescape(toplevel))
if vim.v.shell_error ~= 0 then
return nil, nil
end
git_dir = vim.fn.system("cygpath -w " .. vim.fn.shellescape(git_dir))
if vim.v.shell_error ~= 0 then
return nil, nil
end
end
toplevel = toplevel:gsub("/", "\\")
git_dir = git_dir:gsub("/", "\\")
end

Updates for toplevel and git_dir. These two lines of vim.fn.system function use cygpath to convert the paths to Windows form, but the return value of vim.fn.system would add a trailing \n char to the paths, causing them to be invalid.

Initially, I thought this is probably a Windows only cygpath quirk that added the \n char. But, then i tried similar thing on Ubuntu, there too, vim.fn.system added trailing \n char, you can try this:

$ nvim -c "lua print(string.byte(vim.fn.system('echo hello'),1,-1))"
output: 104 101 108 108 111 10

notice the trailing 10 for \n char.

The two vim.fn.system calls are inside a if vim.fn.has "win32" == 1 then check, so that's why it only affected Windows.
But if this is the general behavior of vim.fn.system, it could affect Linux somewhere else, right?

Can you confirm this?
Much appreciated <3.

@alex-courtis
Copy link
Member

That's fantastic investigation, thank you.

I'd be most grateful if you could submit a PR with that fix. I can try, however we will need to go back and forth to test etc.

@alex-courtis
Copy link
Member

Many thanks for the feature flags @mj2068 , it was very enlightening: https://github.com/nvim-tree/nvim-tree.lua/wiki/Development#os-feature-flags

mj2068 added a commit to mj2068/nvim-tree.lua that referenced this issue Oct 23, 2023
mj2068 added a commit to mj2068/nvim-tree.lua that referenced this issue Oct 25, 2023
To avoid shell compatibility issues in msys2 environment on Windows
alex-courtis added a commit that referenced this issue Oct 30, 2023
)

* fix(#2467): remove newline in git paths

* fix: info size suffix and formatting (#2492)

- Now there is a whitespace between value and unit.
- Now values >= 1024 YiB are shown in YiB instead of B.
- To reuse same code a new local function was added: round().

* feat(#2312): fire `TextYankPost` event on path copy (#2489)

* feat(#2312): fire `TextYankPost` event on path copy

* stylua

* Bug fix

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>

* feat: mapping and options to sort entries in help window (#2482)

* feat: add option to sort entries in help window

* stylua

* Add keymap to toggle sorting methods

* Bug fix

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>

* fix(#2467): remove newline in git paths

* fix(#2467): change cygpath calls to array format
To avoid shell compatibility issues in msys2 environment on Windows

* stylua nit

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
Co-authored-by: Andrew Voynov <37143421+Andrew15-5@users.noreply.github.com>
Co-authored-by: Azad <49314270+Akmadan23@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working OS Windows PowerShell specific to windows powershell
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants