lukechilds / zsh-nvm

Zsh plugin for installing, updating and loading nvm
MIT License
2.24k stars 113 forks source link

Can't upgrade nvm #44

Closed alextes closed 5 years ago

alextes commented 6 years ago

Tracked the problem down to the _zsh_nvm_latest_release_tag function. Command is

echo $(cd "$NVM_DIR" && git fetch --quiet origin && git describe --abbrev=0 --tags --match "v[0-9]*" origin)

Specifically:

git describe --abbrev=0 --tags --match "v[0-9]*" origin

is coming back as:

fatal: Not a valid object name origin

git ls-remote --tags origin lists the tags fine.

alextes commented 6 years ago

Solved it by using git fetch --unshallow. Seems it was somehow too shallow to use origin which is weird, since I checked the remotes and origin was there.

Anyway, if more people show up, maybe zsh-nvm should clone differently, I don't recall cloning myself or messing with the repo, but then that's a very long time ago 😅 .

Have a great day Luke!

lukechilds commented 6 years ago

Hey, thanks for the detailed feedback.

I'm following the official git install/upgrade instructions from nvm:

https://github.com/creationix/nvm#manual-upgrade

Looks like it requires git v1.7.10+. What git version are you running?

runofthemill commented 6 years ago

Had the same issue, and the fix in #46 worked for me.

$ git --version
git version 2.17.0

🤙🏻

Enochenti commented 6 years ago

Used the git fetch --unshallow ,fatal: --unshallow on a complete repository does not make sense given,maybe it`s not the same issue?

alextes commented 6 years ago

@Enochenti you mean sounds like you have a different issue?

cocoonkid commented 5 years ago

Having the same Issue here. Neat and fresh installed Mojave.

$nvm upgrade
Installed version is v0.33.2
Checking latest version of nvm...
fatal: Not a valid object name origin
Updating to ...
fatal: empty string is not a valid pathspec. please use . instead if you meant to match all paths
.nvm on  tags/v0.33.2 via ⬢ v11.4.0
  git fetch --unshallow
fatal: --unshallow on a complete repository does not make sense

git version 2.20.0

alextes commented 5 years ago

Hm, so the reason why this seems to be happening. zsh-nvm offers to update nvm. It does this by opening the nvm dir, which is a git repo, and using git-describe to figure out the most recent tag as the nvm people use git tags for releases. git-describe takes a reference to a git object, which points at a commit, it checks if the commit has a tag and if not checks its parent. Give it origin which I think becomes origin/master and you should be walking from the most recent commit backward.

The problem I think is that the nvm people set the following git config:

[remote "origin"]
    url = https://github.com/creationix/nvm.git
    fetch = +refs/tags/v0.33.6:refs/tags/v0.33.6

Now given this I can imagine why git fails to pull in the origin/master tree, git-fetch is restricted to only pull in tag 0.33.6 it seems. What I don't understand is how zsh-nvm ever managed to upgrade nvm in the first place 😅 .

I went looking for how nvm updates itself. ~It doesn't.~ It pulls the install script.

The way the install.sh script manages to install a new version for you if you run it again, is because they embed the latest tag in the script itself, and tell git to fetch that specific tag. This works.

Interestingly there's actually a PR open in nvm for upgrade functionality. It, however, uses the same method zsh-nvm does.

Seems relevant to note the nvm approach, both suggested in the README and the open PR is to pull the script and run it again. Nevertheless, I opened a PR that uses a more reliable method of finding the new tag.

alextes commented 5 years ago

Closed by #46 .