Respect previously nvm-loaded node version when sourcing
diff --git a/nvm.sh b/nvm.sh
index 5d488fe..d854605 100644
--- a/nvm.sh
+++ b/nvm.sh
@@ -3606,6 +3606,8 @@
 }
 
 nvm_auto() {
+  local NVM_CURRENT
+  NVM_CURRENT="$(nvm_ls_current)"
   local NVM_MODE
   NVM_MODE="${1-}"
   local VERSION
@@ -3617,11 +3619,15 @@
       nvm install >/dev/null
     fi
   elif [ "_$NVM_MODE" = '_use' ]; then
-    VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)"
-    if [ -n "$VERSION" ]; then
-      nvm use --silent "$VERSION" >/dev/null
-    elif nvm_rc_version >/dev/null 2>&1; then
-      nvm use --silent >/dev/null
+    if [ "_${NVM_CURRENT}" = '_none' ] || [ "_${NVM_CURRENT}" = '_system' ]; then
+      VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)"
+      if [ -n "${VERSION}" ]; then
+        nvm use --silent "${VERSION}" >/dev/null
+      elif nvm_rc_version >/dev/null 2>&1; then
+        nvm use --silent >/dev/null
+      fi
+    else
+      nvm use --silent "${NVM_CURRENT}" >/dev/null
     fi
   elif [ "_$NVM_MODE" != '_none' ]; then
     nvm_err 'Invalid auto mode supplied.'
diff --git a/test/sourcing/Sourcing nvm.sh should keep version if one is active b/test/sourcing/Sourcing nvm.sh should keep version if one is active
new file mode 100755
index 0000000..4254159
--- /dev/null
+++ b/test/sourcing/Sourcing nvm.sh should keep version if one is active
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+die () { echo "$@" ; exit 1; }
+
+echo '0.10.1' > ../../alias/default || die "couldn't create default alias"
+
+\. ../../nvm.sh || die 'sourcing returned nonzero exit code'
+
+NVM_TARGET=0.10.3
+NVM_DEFAULT="$(nvm_resolve_local_alias default)"
+
+[ "_$NVM_DEFAULT" != "_$NVM_TARGET" ] || die "default $NVM_DEFAULT is the same as target $NVM_TARGET"
+
+nvm use $NVM_TARGET || die "nvm use $NVM_TARGET failed"
+
+\. ../../nvm.sh || die 'sourcing returned nonzero exit code'
+
+NVM_CURRENT="$(nvm current)"
+
+[ "_${NVM_CURRENT#v}" = "_$NVM_TARGET" ] || die "node version not retained after sourcing"
diff --git a/test/sourcing/Sourcing nvm.sh should use the default if available b/test/sourcing/Sourcing nvm.sh should use the default if available
deleted file mode 100755
index 67e3048..0000000
--- a/test/sourcing/Sourcing nvm.sh should use the default if available
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-
-die () { echo "$@" ; exit 1; }
-
-echo '0.10.1' > ../../alias/default || die 'creation of default alias failed'
-
-\. ../../nvm.sh || die 'sourcing returned nonzero exit code'
-\. ../common.sh
-
-NVM_LS_CURRENT="$(nvm ls current | strip_colors | \grep -o v0.10.1)"
-[ "_$NVM_LS_CURRENT" = '_v0.10.1' ] || die "'nvm ls current' did not return '-> v0.10.1', got '$NVM_LS_CURRENT'"
-
-# NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)"
-
-NVM_ALIAS_DEFAULT="$(nvm alias default | strip_colors)"
-[ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.1 (-> v0.10.1)" ] \
-  || die "'nvm alias default did not return 'default -> 0.10.1 (-> v0.10.1)', got '$NVM_ALIAS_DEFAULT'"
diff --git a/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded b/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded
new file mode 100755
index 0000000..fe837f2
--- /dev/null
+++ b/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+die () { echo "$@" ; exit 1; }
+
+\. ../common.sh
+
+# We need to unload nvm again first, as by the time this test is run,
+# despite being unloaded in setup, the inherited PATH still contains
+# an nvm-installed node version. We have to reset NVM_DIR after the unload.
+\. ../../nvm.sh || die 'sourcing returned nonzero exit code'
+NVM_DIR_CACHED="$NVM_DIR"
+nvm unload || die 'unloading returned nonzero exit code'
+NVM_DIR="$NVM_DIR_CACHED"
+
+echo '0.10.1' > ../../alias/default || die 'creation of default alias failed'
+
+# Now to begin the real test
+\. ../../nvm.sh || die 'sourcing returned nonzero exit code'
+
+NVM_LS_CURRENT_NOT_GREPPED="$(nvm ls current | strip_colors)"
+NVM_LS_CURRENT="$(nvm ls current | strip_colors | \grep -o v0.10.1)"
+[ "_$NVM_LS_CURRENT" = '_v0.10.1' ] || die "'nvm ls current' did not return '-> v0.10.1', got '$NVM_LS_CURRENT_NOT_GREPPED'"
+
+# NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)"
+
+NVM_ALIAS_DEFAULT="$(nvm alias default | strip_colors)"
+[ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.1 (-> v0.10.1)" ] \
+  || die "'nvm alias default did not return 'default -> 0.10.1 (-> v0.10.1)', got '$NVM_ALIAS_DEFAULT'"
diff --git a/test/sourcing/setup b/test/sourcing/setup
index 44b688e..a7f6be8 100755
--- a/test/sourcing/setup
+++ b/test/sourcing/setup
@@ -9,5 +9,6 @@
 
 \. ../../nvm.sh
 nvm install 0.10.1 || echo >&2 'nvm install 0.10.1 failed'
+nvm install 0.10.3 || echo >&2 'nvm install 0.10.3 failed'
 nvm unalias default || 'removing default alias failed'
 nvm unload || echo >&2 'nvm unload failed'
diff --git a/test/sourcing/teardown b/test/sourcing/teardown
index 00a8749..9bb52b0 100755
--- a/test/sourcing/teardown
+++ b/test/sourcing/teardown
@@ -3,4 +3,5 @@
 rm -rf ../../alias
 rm -rf ../../v0.10.1
 rm -rf ../../v0.10.2
+rm -rf ../../v0.10.3
 rm -f ../../.nvmrc