Open avengerx opened 3 months ago
The nvm@0.0.4
output indicates you have an npm-installed nvm, which isn't actually a working version of anything.
The issue with the git syntax suggests your git version is unsupported - we require v1.7.10, per the readme. What version do you have?
I had installed the nvm@0.0.4 where it informed me I needed to install it from the shell script. I understand it didn't do anything, I just didn't bother to remove it back then.
Git is 2.45.2 as I stated in the top (operating system/version).
I don't know, to me it really look like just a cygwin-to-git4win path conversion issue. Again, it installed when I switched to -C
(which should be equivalent to the pair of git arguments). Thing is, I am calling git for windows with linux(cygwin) paths, thus the paths (in /home/user/.nvm
format) doesn't work, as it would expect something like c:\cygwin64\home\user\.nvm
, which cygwin can translate when -C
is passed.
Unless I'm mistaken, cygwin automatically translates paths passed to non-cygwin commands. When it's in the format -C /home/user/.nvm
. But it doesn't really try it when the arguments are tied --git-dir="/home/user/.nvm"
.
This issue should only trigger when using WSL or cygwin with non-native builds of git. The solution that works for me though, probably doesn't for WSL.
What happens if you use a cygwin-installed git, so that it's not using the windows git?
Using cygwin-installed git (yet, of course, Windows-installed node), it works. Tested in a somewhat similar station with git 2.31.1, node 14.17.6, and cygwin1.dll 3.2.0.
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Windows-installed node shouldn't matter because nvm doesn't itself use node.
OK, thanks! That means that nvm's install script either needs to detect windows-installed git, ideally with feature detection, and either a) error out, or b) change the git commands so they work.
Alternatively, cygwin could (and probably should) add support for --git-dir
if it already supports -C
?
Windows-installed node shouldn't matter because nvm doesn't itself use node.
Oh, sure, right!
OK, thanks! That means that nvm's install script either needs to detect windows-installed git, ideally with feature detection, and either a) error out, or b) change the git commands so they work.
Ya, erroring (a) could be frustrating to the user, but not bulldozing directories where they shouldn't will definitively help at least measure the worth of treating this edge case. Adapting the commands (b) should involve some magic I'm not sure is worth for the script maintainability over the long run.
It would involve, after resolving ${INSTALL_DIR}
something like this
So, not sure this edgy case is worth this much trouble.
Alternatively, cygwin could (and probably should) add support for
--git-dir
if it already supports-C
?
This brings us to another long piece. In summary, I was mistaken. Cygwin doesn't do any path conversion and it worked by luck. The -C
was required to get rid of the bad object
error, though, which I'm still not completely sure why it happened, as all other git steps were "going through". Details follows.
I was double-checking this... and seems cygwin doesn't really do any path translation.
The output of
[ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm"
is
/home/user/.nvm
And I tried some commands to see what happens. And turns out that git-for-windows version does interpret the path and creates the directories.
Say, I have /home/user/
as my home directory, which from cygwin would translate to C:\cygwin64\home\user\
.
I noticed what happened here was, all stuff was installed and set up in C:\home\user\.nvm
.
When I tried git init /home/user/.nvm
(based on v0.39.7's install.sh), what I got was:
Initialized empty Git repository in C:/home/user/.nvm/.git/
Thus, I see there's no conversion made by cygwin at all, git-for-win just install everything outside of the actual user's home. Just, for some reason, --git-dir=
and/or --work-tree=
mostly works. It clones in that "foreign" directory, checks stuff out. All having the "build environment" actually outside actual user home.
But then that step to check out the tag fails. Even though it shouldn't by looking into C:\home\user\.nvm
(which is not the same ascygwin's /home/user/.nvm
)
Then I believe -C
does work because it is equivalent to the syntax used for git clone
, that just passes the install path (that means, "change to that directory and do the commands").
In the end, I had /home/user/.nvm
(install.sh:152)[https://github.com/nvm-sh/nvm/blob/v0.39.7/install.sh#L152] but also had C:\home\user\.nvm
(which corresponds to /cygdrive/c/home/user/.nvm
in cygwin).
It indeed worked because, at least
(a) I manually cloned nvm-sh/nvm into real cygwin /home/user/.nvm
and checked out tag
(b) The commands from the install script succeeded with -C /home/user/.nvm
being interpreted as -C C:\home\user\.nvm
So I had very close branches in both directories, so whenever the script called git-win, it worked on the "foreign" repo, but whenever the rest of the script referred to the actual directory, it found what it expected. 😄
Then again, no telling what else was left not done in one directory but done in another, if you follow the thought. It seemed to have worked, but I didn't try too many things, I'm new with nvm.
In the end, for my use case, I was setting up a server service, something I'd need to run as network service, so as nvm is something user-scoped it wouldn't really help and I will need to keep node up-to-date in the server the oldschool way.
So that's another reason it could be safer to just error out and see if more people raise here hitting this wall.
This issue might also be affected by git-bash-here (git for windows context menu item). I believe they use MSYS, and it seems this one does auto path conversion so...
Operating system and version:
Windows Server 2012 R2 NodeJS 20.15.1 Git for Windows 2.45.2.windows.1 Cygwin1.dll 3.4.5
nvm debug
output:nvm ls
output:How did you install
nvm
?curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
What steps did you perform?
Ran the install command
What happened?
install.sh script output
``` % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 16555 100 16555 0 0 140k 0 --:--:-- --:--:-- --:--:-- 141k => Downloading nvm from git to '/home/avenger/.nvm' => Cloning into '/home/avenger/.nvm'... remote: Enumerating objects: 369, done. remote: Counting objects: 100% (369/369), done. remote: Compressing objects: 100% (315/315), done. remote: Total 369 (delta 42), reused 166 (delta 27), pack-reused 0 Receiving objects: 100% (369/369), 368.22 KiB | 30.68 MiB/s, done. Resolving deltas: 100% (42/42), done. remote: Enumerating objects: 366, done. remote: Counting objects: 100% (366/366), done. remote: Compressing objects: 100% (315/315), done. remote: Total 366 (delta 42), reused 162 (delta 25), pack-reused 0 Receiving objects: 100% (366/366), 365.90 KiB | 30.49 MiB/s, done. Resolving deltas: 100% (42/42), done. fatal: bad object cdc56687ada0c47f97632b0049b0446aadbe3a3a error: remote did not send all necessary objects Failed to fetch origin with v0.39.7. Please report this! ```What did you expect to happen?
Install nvm.
Is there anything in any of your profile files that modifies the
PATH
?~/.bash_profile
If you are having installation issues, or getting "N/A", what does
curl -I --compressed -v https://nodejs.org/dist/
print out?bottomline
If I download/checkout and edit
install.sh
and change all--git-dir="${INSTALL_DIR}/.git" --work-tree="${INSTALL_DIR}"
with just-C "${INSTALL_DIR}"
the script runs to completion.`$ cat install.sh | bash`
``` => nvm is already installed in /home/user/.nvm, trying to update using git => * (HEAD detached at FETCH_HEAD) master => Compressing and cleaning up git repository => Appending nvm source string to /home/user/.bashrc => Appending bash_completion source string to /home/user/.bashrc => You currently have modules installed globally with `npm`. These will no => longer be linked to the active version of Node when you install a new node => with `nvm`; and they may (depending on how you construct your `$PATH`) => override the binaries of modules installed with `nvm`: C:\Users\user\AppData\Roaming\npm └── nvm@0.0.4 => If you wish to uninstall them at a later point (or re-install them under your => `nvm` Nodes), you can remove them from the system Node as follows: $ nvm use system $ npm uninstall -g a_module => Close and reopen your terminal to start using nvm or run the following to use it now: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion ``` This happens because I'm running git for windows from a cygwin shell, so the linux-like path provided in `--git-dir` doesn't get translated correctly. It seems both `-C` and `--work-tree` are translated correctly. I didn't retry the script just dropping `--git-dir` as it would probably fail as my current working directory was not `~/.nvm`. So, perhaps replacing the command to use `-C` could be a bit more portable. Maybe checking `"${OSTYPE}" == "cygwin"` could create an exception, if using both work-tree and git-dir is meant to solve issues with a specific OS/environment. Hope this helps improve NVM! *edit:* this issue is probably the same reported in #3329.