vscode-gitlens
vscode-gitlens copied to clipboard
MSYS2 git causes Error: spawn C:/msys64/usr/bin/git.exe ENOENT due to path format
Issue Type: Bug
Setting git.path to use git from a msys2 instalation ("C:/msys64/usr/bin/git.exe") causes extension to fail with the error:
Error: spawn C:/msys64/usr/bin/git.exe ENOENT
I have tracked the root cause for this to be that msys2 git prints paths in Unix format rather than Windows format unlike Git for Windows.
git rev-parse --show-toplevel
prints /c/Code/AeonGUI on msys2 git,
but prints C:/Code/AeonGUI on Git for Windows.
This happens regardless of if the command is issued from inside bash or cmd.exe.
I looked for external solutions, an env var that could be set or a git config setting but found nothing other than calling cygpath -w "$(git rev-parse --show-toplevel)", which is not usable as a git.path or any other setting.
Steps to reproduce:
- Install MSYS2 from https://www.msys2.org
- Run MSYS2 bash for MinGW64
- Install git:
pacman -S git
- Run vscode
- Set "git.path": "C:/msys64/usr/bin/git.exe" on settings.js
- Close and rerun vscode and open a file in a git repository
- The extension will likely fail at this point, but clicking the extension icon on the left pane will trigger more failures
Extension version: 10.2.1 VS Code version: Code 1.42.1 (c47d83b293181d9be64f27ff093689e8e7aed054, 2020-02-11T14:45:59.656Z) OS version: Windows_NT x64 10.0.18363
This isn't something that I will likely fix myself, but if the community wants to provide a PR I'm certainly open to it -- depending on the complexity and scope of the changes required.
I'd do it myself if I knew enough TypeScript, but sadly I don't.
It should be an easy solution to do something like this on all cases were a path is expected from git (bash script):
path=git rev-parse --show-toplevel
path=cygpath -w "$path"
This would go next to where you normalize the paths.
However, the path to cygpath becomes an issue, you would need to add a setting like say gitlens.cygpath, in order to be able to use cygpath without forcing C:/msys64/usr/bin to be in the PATH.
PS: By the way, Git For Windows also installs cygpath, so it wouldn't make a difference if the command gets called on git for windows installations.
It gets tricky and on top of it I don't use msysgit, so even if I put a patch together for what I think might work, I don't have a setup to test it.
If you can quickly brew an initial patch, I may be able to test and expand on it, I think just figuring out how you span processes and store their output should be enough.
I've hit this same issue, has there been a solution found? Current workaround to install git separately and use that executable, also checking path to ensure correct order.
I also get the same issue. To use 'git' installed in MSYS2, I have employed the following bath shell (suggested by mattn) to covert the /c/
prefixed-path for rev-parse command.
@echo off
setlocal
rem If you don't add path for msys2 into %PATH%, enable following line.
rem set PATH=c:\msys64\usr\bin;%PATH%
if "%1" equ "rev-parse" goto rev_parse
git %*
goto :eof
:rev_parse
for /f %%1 in ('git %*') do cygpath -w %%1
However, the issue still exists. Looking forward to the solution.
Edited:
I am having the same problem as @xjtunk.
The git-wrap.bat
suggested by @mattn is only converting path if th efirst argument is rev-parse
, but gitlens calls git with a few additional args
if "%1" equ "rev-parse" goto rev_parse
Thus resulting:
>git rev-parse --show-toplevel
D:\Desktop\Program\Gits\vscode-gitlens
>git -c core.longpaths=true rev-parse --show-toplevel
/d/Desktop/Program/Gits/vscode-gitlens
However, I tried to fix this but windows keeps recognizing core.longpaths=true
as two args core.longpaths
and true
in ('git %*')
line
Temporary solution:
@echo off
setlocal
rem If you don't add path for msys2 into %PATH%, enable following line.
rem set PATH=c:\msys64\usr\bin;%PATH%
rem https://stackoverflow.com/a/39776524/8810271
:loop
if "%~1" equ "rev-parse" goto rev_parse
shift
if not "%~1"=="" goto loop
git.exe %*
goto :eof
:rev_parse
git.exe %* | cygpath -w -f -
@AllanChain Thanks a lot, very helpful.
Thanks a lot, it works
@AllanChain @frankche88 @eshepelyuk where should this script be in?
@ronnaf
"git.path": "D:/msys64/usr/bin/git-wrap.bat"
.git-wrap.bat
setlocal
:loop if "%~1" equ "rev-parse" goto rev_parse shift if not "%~1"=="" goto loop
git.exe %* goto :eof
:rev_parse git.exe %* | cygpath -w -f -
@frankche88 thank you!
https://github.com/microsoft/vscode/pull/134146
Maybe this issue will fix this problem, and it's WIP. The git-wrapper solution is temporary.
@aaftio There is already a PR to fix this #1659. Just fyi the vscode PR does not resolve the issue in vscode-gitlens
@zcsizmadia OK, thanks for your tips. Cygwin git works with IntelliJ Idea well, I am not sure Idea have use the "git rev-parse ..." or not. But I am worry about if there is some other git sub-command which will return the file system path and used by vscode-git or gitlens. And the Cygwin-style path problem raise again.