[Fix] allow `nvm unalias x` when `x` is a default alias, but shadowed
Fixes #2122.
parent
04ad1b528c
commit
73a513c389
12
nvm.sh
12
nvm.sh
|
@ -3372,6 +3372,13 @@ nvm() {
|
||||||
local NVM_NODE_PREFIX
|
local NVM_NODE_PREFIX
|
||||||
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
|
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
|
||||||
NVM_NODE_PREFIX="$(nvm_node_prefix)"
|
NVM_NODE_PREFIX="$(nvm_node_prefix)"
|
||||||
|
local NVM_ALIAS_EXISTS
|
||||||
|
NVM_ALIAS_EXISTS=0
|
||||||
|
if [ -f "${NVM_ALIAS_DIR}/${1-}" ]; then
|
||||||
|
NVM_ALIAS_EXISTS=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $NVM_ALIAS_EXISTS -eq 0 ]; then
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"stable" | "unstable" | "${NVM_IOJS_PREFIX}" | "${NVM_NODE_PREFIX}" | "system")
|
"stable" | "unstable" | "${NVM_IOJS_PREFIX}" | "${NVM_NODE_PREFIX}" | "system")
|
||||||
nvm_err "${1-} is a default (built-in) alias and cannot be deleted."
|
nvm_err "${1-} is a default (built-in) alias and cannot be deleted."
|
||||||
|
@ -3379,7 +3386,10 @@ nvm() {
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[ ! -f "${NVM_ALIAS_DIR}/${1-}" ] && nvm_err "Alias ${1-} doesn't exist!" && return
|
nvm_err "Alias ${1-} doesn't exist!"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
local NVM_ALIAS_ORIGINAL
|
local NVM_ALIAS_ORIGINAL
|
||||||
NVM_ALIAS_ORIGINAL="$(nvm_alias "${1}")"
|
NVM_ALIAS_ORIGINAL="$(nvm_alias "${1}")"
|
||||||
command rm -f "${NVM_ALIAS_DIR}/${1}"
|
command rm -f "${NVM_ALIAS_DIR}/${1}"
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
OUTPUT="$(nvm unalias node 2>&1)"
|
||||||
|
EXPECTED_OUTPUT="node is a default (built-in) alias and cannot be deleted."
|
||||||
|
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
||||||
|
|
||||||
|
nvm alias node stable || die '`nvm alias node stable` failed'
|
||||||
|
|
||||||
|
nvm unalias node || die '`nvm unalias node` failed'
|
||||||
|
|
||||||
|
OUTPUT="$(nvm unalias node 2>&1)"
|
||||||
|
EXPECTED_OUTPUT="node is a default (built-in) alias and cannot be deleted."
|
||||||
|
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
Loading…
Reference in New Issue