Skip to content

Commit

Permalink
Make sure sourcing nvm.sh on shells that don't support source optio…
Browse files Browse the repository at this point in the history
…ns doesn't exit nonzero.

Fixes #721
  • Loading branch information
ljharb committed May 22, 2015
1 parent c966204 commit 0f1efc8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ nvm_supports_source_options() {
[ "_$(echo 'echo $1' | . /dev/stdin yes 2> /dev/null)" = "_yes" ]
}

VERSION="$(nvm_alias default 2>/dev/null)"
VERSION="$(nvm_alias default 2>/dev/null || echo)"
if nvm_supports_source_options && [ "_$1" = "_--install" ]; then
if [ -n "$VERSION" ]; then
nvm install "$VERSION" >/dev/null
Expand Down
11 changes: 11 additions & 0 deletions test/sourcing/Sourcing nvm.sh with no default should return 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

die () { echo $@ ; exit 1; }

touch ../../alias/default
rm ../../alias/default || die 'removal of default alias failed'
nvm_alias default && die '"nvm_alias default" did not fail'

set -e # necessary to fail internally with a nonzero code

. ../../nvm.sh || die 'sourcing returned nonzero exit code'

0 comments on commit 0f1efc8

Please sign in to comment.