From b5d9e547f2538e073186ccd403dd075529c3ec31 Mon Sep 17 00:00:00 2001 From: Tobias Witt Date: Wed, 21 Jan 2015 23:02:20 +0100 Subject: [PATCH 1/2] Use `tee` to replace the alias files content instead of `>` As mentioned in #615 it is possible to configure `>` to not override existing files by default. `tee` is a standard tool that can be used shell independent. --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index fbbf663..ee13d9d 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1448,7 +1448,7 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')" if [ $? -ne 0 ]; then echo "! WARNING: Version '$3' does not exist." >&2 fi - echo "$3" > "$NVM_ALIAS_DIR/$2" + echo "$3" | tee "$NVM_ALIAS_DIR/$2" if [ ! "_$3" = "_$VERSION" ]; then echo "$2 -> $3 (-> $VERSION)" else From cba50946527152d3fff772de6ae462d15ef5dfe9 Mon Sep 17 00:00:00 2001 From: Tobias Witt Date: Thu, 22 Jan 2015 12:20:09 +0100 Subject: [PATCH 2/2] Provide test case for testing the `noclobber` option from zsh This tests the absence of the bug from #615 --- ...\" again should change the target" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 "test/fast/Aliases/Running \"nvm alias \" again should change the target" diff --git "a/test/fast/Aliases/Running \"nvm alias \" again should change the target" "b/test/fast/Aliases/Running \"nvm alias \" again should change the target" new file mode 100755 index 0000000..d4a8a2d --- /dev/null +++ "b/test/fast/Aliases/Running \"nvm alias \" again should change the target" @@ -0,0 +1,21 @@ +#!/bin/sh + +. ../../../nvm.sh + +die () { echo $@ ; exit 1; } + +if [ -n "$ZSH_VERSION" ]; then + # set clobber option in order to test that this does not produce any + # incompatibilities + setopt noclobber +fi + +nvm alias test-stable-1 0.0.2 + +nvm alias test-stable-1 | \grep -e "test-stable-1 -> 0.0.2 (-> v0.0.2)" \ + || die "nvm alias test-stable-1 0.0.2 did not set test-stable-1 to 0.0.2" + +nvm alias test-stable-1 0.0.1 + +nvm alias test-stable-1 | \grep -e "test-stable-1 -> 0.0.1 (-> v0.0.1)" \ + || die "nvm alias test-stable-1 0.0.1 did not set test-stable-1 to 0.0.1"