From ba1be9b4eaa1429ef61735283398ad8ff2e6002b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 5 May 2014 22:46:46 -0700 Subject: [PATCH] Making `nvm install` use the version, even if it's already installed. Fixes #410 --- nvm.sh | 6 ++++- .../install already installed uses it | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 test/slow/nvm install/install already installed uses it diff --git a/nvm.sh b/nvm.sh index ec5c6e4..645de86 100644 --- a/nvm.sh +++ b/nvm.sh @@ -306,7 +306,11 @@ nvm() { shift done - [ -d "$NVM_DIR/$VERSION" ] && echo "$VERSION is already installed." && return + if [ -d "$NVM_DIR/$VERSION" ]; then + echo "$VERSION is already installed." + nvm use "$VERSION" + return $? + fi if [ "$VERSION" = "N/A" ]; then echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." diff --git a/test/slow/nvm install/install already installed uses it b/test/slow/nvm install/install already installed uses it new file mode 100755 index 0000000..7e42c07 --- /dev/null +++ b/test/slow/nvm install/install already installed uses it @@ -0,0 +1,24 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +[ "$(nvm install invalid.invalid)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message" + +# Remove the stuff we're clobbering. +[ -e ../../../v0.9.7 ] && rm -R ../../../v0.9.7 +[ -e ../../../v0.9.12 ] && rm -R ../../../v0.9.12 + +# Install from binary +nvm install 0.9.7 +nvm install 0.9.12 + +nvm use 0.9.7 + +node --version | grep v0.9.7 || die "precondition failed: node doesn't start at 0.9.7" + +nvm install 0.9.12 + +node --version | grep v0.9.12 || die "nvm install on already installed version doesn't use it" +