-
-
Notifications
You must be signed in to change notification settings - Fork 595
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
fix(#2467): remove newline in git paths #2478
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, I'm just not certain how this works for PowerShell
@@ -40,10 +40,14 @@ function M.get_toplevel(cwd) | |||
if vim.v.shell_error ~= 0 then | |||
return nil, nil | |||
end | |||
-- remove trailing newline(\n) character added by vim.fn.system | |||
toplevel = toplevel:gsub("\n", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inside the cygpath block.
I was under the impression that you are using PowerShell. Does it see cygpath?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologize for didn't fully describe my environment before.
Yes, I use PowerShell, but I also have msys2 installed on my Windows 10.
Yes, PowerShell sees "cygpath", because the POSIX compatible environment provided msys2 is based on Cygwin. So Cygwin tools like "cygpath"(exe files you can run directly) are in the Windows path.
Update:
I have to admit, in my case, the reason PowerShell sees "cygpath" is because it's inside X:/msys2/usr/bin, and this bin path is in the Windows path environment variable.
But I actually forgot whether it's added by the official msys2 installer or manually by me.
And, the situation of this issue has changed a bit due to the new commit, which made using "cygpath" a manual option with a default value: false. This bypassed the two vim.fn.system reassigning statements which were the causes of my original issue(#2467), leaving the paths conversion to these two line:
nvim-tree.lua/lua/nvim-tree/git/utils.lua
Lines 49 to 50 in db8145c
toplevel = toplevel:gsub("/", "\\") | |
git_dir = git_dir:gsub("/", "\\") |
I thinking making "cygpath" a manual option is a good call, and will test it and report back.
Thx, alex. Peace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PowerShell sees "cygpath" is because it's inside X:/msys2/usr/bin, and this bin path is in the Windows path environment variable.
That explains a lot - a valid use case that we never expected or handled.
I'm prepared for disappointment after your testing, however we will fix this one way or another.
Big favour, if possible: please run has.lua
for neovim inside msys2. It would be great to fill out the entirety of OS Feature Flags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to do some reading about how msys2 works. Then I did the following inside the msys2 official shell, with nvim 0.9.4 installed from MSYS2 Packages using pacman, following their doc.
Flags: has_list_msys2_mingw.log
I then did quick git integration tests regarding the new cygwin_support
manual option, false and true, using the latest commit.
With the "Clean Room" lua file, test folder "project1" git initialized, which contains one untracked file "README.md".
After "Ready!" message, :NvimTreeOpen, select "project1", hit Enter, the results are:
cygwin_support = false(default):
shown error message: [NvimTree] Could not start the fs_event watcher for path \tmp\project1\.git : ENOENT
log: nvim-tree_cygwin_false.log
cygwin_support = true:
no error, but no git tracking.
log: nvim-tree_cygwin_true.log
I think we need to normalize the paths.
Thx, alex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for all your diligent testing with this unfamiliar environment. This is quite the difficult issue...
It looks like the cygwin_support = true
case is not matching any toplevel and returning nils. It's definitely hitting the use_cygpath
branch as the win32
feature flag is set and we are seeing different results.
To confirm:
- does this PR fix the above?
- do we need to do more right now or can we merge this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- does this PR fix the above?
It did. Now, I'm not so sure, because the new "cypwin_support" option affected it.
- do we need to do more right now or can we merge this?
I don't think we can merge this. But the issue is getting clearer to me. I'm working on a fix, can I have few days?
- 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().
…ee#2489) * feat(nvim-tree#2312): fire `TextYankPost` event on path copy * stylua * Bug fix --------- Co-authored-by: Alexander Courtis <alex@courtis.org>
Can I ask a big favour: #2491 is a guess to attempt some path normalisation however may be incorrect or destructive. Could you please attempt to incorporate the above into this PR? |
It's okay, alex, glad to help. As to #2491, I don't think "\r\n" is the source of the issue. vim.fn.system will always convert "\r\n" to "\n", according to:
I confirmed this vim.fn.system behavior in my previous tests. Anyway, will be back. Peace. |
And @alex-courtis, I'm not very familiar with git PR workflow, I did some git things in my fork, like, fetch upstream, merge, rebase, etc., according to some tutorials. Now, this PR page shows me, it has changed a lot files. I hope I don't break anything, did I do something wrong? |
This sounds fantastic, don't worry about CI etc. We can get this right then we tidy. I'll have a chance to look / review on the weekend. |
To avoid shell compatibility issues in msys2 environment on Windows
Finally. But I think this fixed it.
Take a look. |
This PR is seeing up phantom changes; this branch is definitely up to date: master...mj2068:nvim-tree.lua:bugfix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just fantastic, thank you for the great consideration and testing!
Closed #2491
Fixes #2467 (potentially also for #2466), regarding failed git integration on Windows.
Background: In file git/utils.lua, the two paths variables toplevel and git_dir are returned by vim.fn.system(...), which will add a trailing newline character, causing them to be invalid paths.
Fix: Added two lines of gsub function to remove any newline characters in these paths.
After preliminary tests on Ubuntu, I suggest caution for the general behavior of vim.fn.system() on all systems, where its return value seems to always contain a trailing newline, therefore its direct return value can't be used as paths.