1a0500b00dd417ea2d9d3ea12bbad5318f8d7e55

Author
Jay Tavares <jaytavares@gmail.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Change order of automatic virtualenv activation/deactivation (#6687)

When navigating from a virtualenv project directory, first deactivate the virtualenv.
Then, check to see if destination directory is also a virtualenv project directory.
If it is activate that virtualenv. See #5817.

Diff

 1diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 2index 2a4b43189518cc55593cf4e787f5d0f9feeb92e4..b07b2a30661c4ccc3a5dee0d89c699cc08f04064 100644
 3--- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 4+++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
 5@@ -77,6 +77,12 @@ if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
 6       else
 7         ENV_NAME=""
 8       fi
 9+      
10+      if [[ -n $CD_VIRTUAL_ENV && "$ENV_NAME" != "$CD_VIRTUAL_ENV" ]]; then
11+        # We've just left the repo, deactivate the environment
12+        # Note: this only happens if the virtualenv was activated automatically
13+        deactivate && unset CD_VIRTUAL_ENV
14+      fi
15       if [[ "$ENV_NAME" != "" ]]; then
16         # Activate the environment only if it is not already active
17         if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
18@@ -86,10 +92,6 @@ if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
19             source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME"
20           fi
21         fi
22-      elif [[ -n $CD_VIRTUAL_ENV && -n $VIRTUAL_ENV ]]; then
23-        # We've just left the repo, deactivate the environment
24-        # Note: this only happens if the virtualenv was activated automatically
25-        deactivate && unset CD_VIRTUAL_ENV
26       fi
27     fi
28   }