]> Sergey Matveev's repositories - zsh-autoenv.git/commitdiff
Set varstash_dir for "leave" event (#72)
authorDaniel Hahler <github@thequod.de>
Tue, 17 Oct 2017 22:31:43 +0000 (00:31 +0200)
committerGitHub <noreply@github.com>
Tue, 17 Oct 2017 22:31:43 +0000 (00:31 +0200)
Fixes https://github.com/Tarrasch/zsh-autoenv/issues/45.

autoenv.zsh
tests/varstash-unstash-on-leave.t [new file with mode: 0644]

index b64b6c7cc06985e324bc5fb146f08ede8b28c851..166213a4caa91377d7828e3004f04cb4de254ae9 100644 (file)
@@ -406,7 +406,7 @@ _autoenv_chpwd_handler() {
       if ! [[ ${PWD}/ == ${prev_dir}/* ]]; then
         local env_file_leave=$prev_dir/$AUTOENV_FILE_LEAVE
         if _autoenv_check_authorized_env_file $env_file_leave; then
-          _autoenv_source $env_file_leave leave $prev_dir
+          varstash_dir=$prev_dir _autoenv_source $env_file_leave leave $prev_dir
         fi
 
         # Unstash any autostashed stuff.
diff --git a/tests/varstash-unstash-on-leave.t b/tests/varstash-unstash-on-leave.t
new file mode 100644 (file)
index 0000000..bfea2bf
--- /dev/null
@@ -0,0 +1,25 @@
+Test unstash behavior on leaving.
+
+  $ source $TESTDIR/setup.zsh || return 1
+
+Setup test environment.
+
+  $ mkdir sub
+  $ echo 'echo ENTER; stash FOO=changed' >| sub/$AUTOENV_FILE_ENTER
+  $ echo 'echo LEAVE; unstash FOO' >| sub/$AUTOENV_FILE_LEAVE
+  $ test_autoenv_auth_env_files sub
+  $ FOO=orig
+
+Activating the env stashes it and applies a new value.
+
+  $ cd sub
+  ENTER
+  $ echo $FOO
+  changed
+
+Leaving the directory unstashes it (varstash_dir is set to prev dir).
+
+  $ cd ..
+  LEAVE
+  $ echo $FOO
+  orig