Skip to content
Myr

[Fix] allow `nvm unalias x` when `x` is a default alias, but shadowed

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes #2122.

authored by Jordan Harband · committed by Jordan Harband · parent 04ad1b5 · Browse files · 2 files+34 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+34 added−7 removed

  • tests:+17 added−0 removed
  • other:+17 added−7 removed

2 files+34 added−7 removed

added:test/fast/Aliases/"nvm unalias" should accept aliases when they shadow a built-in alias+17 added
1#!/bin/sh23\. ../../../nvm.sh45die () { echo "$@" ; exit 1; }67OUTPUT="$(nvm unalias node 2>&1)"8EXPECTED_OUTPUT="node is a default (built-in) alias and cannot be deleted."9[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"1011nvm alias node stable || die '`nvm alias node stable` failed'1213nvm unalias node || die '`nvm unalias node` failed'1415OUTPUT="$(nvm unalias node 2>&1)"16EXPECTED_OUTPUT="node is a default (built-in) alias and cannot be deleted."17[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
modified:nvm.sh+17 added-7 removed
3370 unmodified lines
3371 local NVM_IOJS_PREFIX3372 local NVM_NODE_PREFIX3373 NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"3374 NVM_NODE_PREFIX="$(nvm_node_prefix)"3375 case "$1" in3376 "stable" | "unstable" | "${NVM_IOJS_PREFIX}" | "${NVM_NODE_PREFIX}" | "system")3377 nvm_err "${1-} is a default (built-in) alias and cannot be deleted."3378 return 13379 ;;3380 esac3375 local NVM_ALIAS_EXISTS3376 NVM_ALIAS_EXISTS=03377 if [ -f "${NVM_ALIAS_DIR}/${1-}" ]; then3378 NVM_ALIAS_EXISTS=13379 fi33803382 [ ! -f "${NVM_ALIAS_DIR}/${1-}" ] && nvm_err "Alias ${1-} doesn't exist!" && return3381 if [ $NVM_ALIAS_EXISTS -eq 0 ]; then3382 case "$1" in3383 "stable" | "unstable" | "${NVM_IOJS_PREFIX}" | "${NVM_NODE_PREFIX}" | "system")3384 nvm_err "${1-} is a default (built-in) alias and cannot be deleted."3385 return 13386 ;;3387 esac33883389 nvm_err "Alias ${1-} doesn't exist!"3390 return3391 fi33923393 local NVM_ALIAS_ORIGINAL3394 NVM_ALIAS_ORIGINAL="$(nvm_alias "${1}")"3395 command rm -f "${NVM_ALIAS_DIR}/${1}"3396 nvm_echo "Deleted alias ${1} - restore it with \`nvm alias \"${1}\" \"${NVM_ALIAS_ORIGINAL}\"\`"
293 unmodified lines