1e615b71d636c3697d7e4aee8fbcd1dc01fd7da3

Author
Zachary Cutlip <uid000@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

fix(virtualenvwrapper): only deactivate if virtual env is still present (#10671)

Diff

 1diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 2index c30216f51b326b6c2c8a22ded568d02fb8db53c5..d359e0c219a17eceb4dce58da81e99d9b77b7b39 100644
 3--- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 4+++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 5@@ -56,7 +56,13 @@ if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
 6       if [[ -n $CD_VIRTUAL_ENV && "$ENV_NAME" != "$CD_VIRTUAL_ENV" ]]; then
 7         # We've just left the repo, deactivate the environment
 8         # Note: this only happens if the virtualenv was activated automatically
 9-        deactivate && unset CD_VIRTUAL_ENV
10+        if [[ -n "$VIRTUAL_ENV" ]]; then
11+          # Only deactivate if VIRTUAL_ENV was set
12+          # User may have deactivated manually or via another mechanism
13+          deactivate
14+        fi
15+        # clean up regardless
16+        unset CD_VIRTUAL_ENV
17       fi
18       if [[ "$ENV_NAME" != "" ]]; then
19         # Activate the environment only if it is not already active