From f9e14b7d4d54679599490e6fbe06d229b6481955 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 4 Oct 2016 01:43:24 -0700 Subject: [PATCH] [Fix] `nvm uninstall`: work around `nomatch` `zsh` option. Fixes #1228. --- nvm.sh | 15 +++++++++++++++ ...g \"nvm uninstall 0.12.6\" uninstalls v0.12.6" | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/nvm.sh b/nvm.sh index 63a1be2..bd07619 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2041,16 +2041,31 @@ nvm_is_natural_num() { # Check version dir permissions nvm_check_file_permissions() { + local ZSH_HAS_NONOMATCH_UNSET + ZSH_HAS_NONOMATCH_UNSET=1 + if nvm_has "setopt"; then + ZSH_HAS_NONOMATCH_UNSET="$(set +e ; setopt | nvm_grep nonomatch > /dev/null ; nvm_echo $?)" + setopt nonomatch + fi for FILE in $1/* $1/.[!.]* $1/..?* ; do if [ -d "$FILE" ]; then if ! nvm_check_file_permissions "$FILE"; then + if [ "${ZSH_HAS_NONOMATCH_UNSET}" -eq 1 ] && nvm_has "setopt"; then + setopt nomatch + fi return 2 fi elif [ -e "$FILE" ] && [ ! -w "$FILE" ]; then nvm_err "file is not writable: $(nvm_sanitize_path "$FILE")" + if [ "${ZSH_HAS_NONOMATCH_UNSET}" -eq 1 ] && nvm_has "setopt"; then + setopt nomatch + fi return 1 fi done + if [ "${ZSH_HAS_NONOMATCH_UNSET}" -eq 1 ] && nvm_has "setopt"; then + setopt nomatch + fi return 0 } diff --git "a/test/slow/nvm uninstall/Running \"nvm uninstall 0.12.6\" uninstalls v0.12.6" "b/test/slow/nvm uninstall/Running \"nvm uninstall 0.12.6\" uninstalls v0.12.6" index 9af0171..67d054b 100755 --- "a/test/slow/nvm uninstall/Running \"nvm uninstall 0.12.6\" uninstalls v0.12.6" +++ "b/test/slow/nvm uninstall/Running \"nvm uninstall 0.12.6\" uninstalls v0.12.6" @@ -20,6 +20,11 @@ nvm ls | grep "$NVM_TEST_VERSION" || die "Failed to install node" # Switch to another version so we can uninstall nvm use 0.12.7 +# if zsh, set "nomatch" opt to reproduce failure from https://github.com/creationix/nvm/issues/1228 +if nvm_has "setopt"; then + setopt nomatch +fi + # Uninstall it nvm uninstall $NVM_TEST_VERSION