[Fix] ensure --reinstall-packages-from has a version number.

Fixes #1760.
Jordan Harband 2018-03-14 00:13:07 -07:00
parent 2850e65b62
commit 0e3bb2cc47
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
2 changed files with 22 additions and 0 deletions

8
nvm.sh
View File

@ -2558,8 +2558,16 @@ nvm() {
case "$1" in
--reinstall-packages-from=*)
PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 27-)"
if [ -z "${PROVIDED_REINSTALL_PACKAGES_FROM}" ]; then
nvm_err 'If --reinstall-packages-from is provided, it must point to an installed version of node.'
return 6
fi
REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")" ||:
;;
--reinstall-packages-from)
nvm_err 'If --reinstall-packages-from is provided, it must point to an installed version of node using `=`.'
return 6
;;
--copy-packages-from=*)
PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 22-)"
REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")" ||:

View File

@ -39,4 +39,18 @@ set -e
[ $INSTALL_EXIT_CODE -eq 4 ] \
|| die ""nvm install --reinstall-packages-from" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE"
set +ex # needed for stderr
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from 2>&1)"
set -ex
EXPECTED_ERROR_MSG='If --reinstall-packages-from is provided, it must point to an installed version of node using `=`.'
[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \
|| die ""nvm install --reinstall-packages-from" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'"
set +ex # needed for stderr
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from= 2>&1)"
set -ex
EXPECTED_ERROR_MSG="If --reinstall-packages-from is provided, it must point to an installed version of node."
[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \
|| die ""nvm install --reinstall-packages-from" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'"
cleanup