[Fix] install.sh: update from nvm's remote; nvm_ls: list versions without globs; nvm_ensure_version_installed: do not leak VERSION

`install.sh`: an existing install now fetches from the remote whose URL is nvm's source,
adding one when none matches,
instead of always fetching `origin`;
fresh installs still name it `origin`.
The remote's URL is read with `git config`,
since `git remote get-url` needs git 2.7.

`nvm_ls`: `find` lists each version directory's non-hidden subdirectories itself,
so it works under `set -f`,
which disables the globs it was given;
the directories only need to exist.

`nvm_ensure_version_installed`:
the resolved alias was assigned to `VERSION` without declaring it local.

Co-authored-by: dajiaohuang <mikewushuwen@outlook.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
This commit is contained in:
Jordan Harbandanddajiaohuang committed 2026-11-19 22:51:28 -08:00
1 parent a4fadf1eae
commit dbda4b9387
6 files changed
+109 -64

No files matched your search

@@ -70,4 +70,12 @@ EXPECTED_OUTPUT=''
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed system' with iojs installed to give $EXPECTED_OUTPUT, got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm_ensure_version_installed system' with iojs installed to exit with 0, got $EXIT_CODE"
# An unresolved installed-version check must not overwrite a caller's VERSION.
VERSION='caller-value'
nvm_resolve_alias() { [ "_${1-}" = '_nonexistent' ] || return 2; nvm_echo 'v123.4.5'; }
nvm_ensure_version_installed nonexistent >/dev/null 2>&1 && die 'expected missing version failure'
[ "${VERSION}" = 'caller-value' ] || die "VERSION leaked: ${VERSION}"
unset -f nvm_resolve_alias
unset VERSION
cleanup