purcell / envrc

Emacs support for direnv which operates buffer-locally
379 stars 35 forks source link

Consider resetting process-environment before merging #33

Closed dvzubarev closed 2 years ago

dvzubarev commented 2 years ago

There are two problems. The first one: create .envrc with export MYVAR=45 M-x envrc-allow M-x getenv MYVAR => 45 After that remove or rename MYVAR M-x envrc-allow M-x getenv MYVAR => 45 But I expected that MYVAR is gone from my environment. Another problem is excessive calls to direnv export. Call envrc-reload multiple times. Create a file temp in the same directory. change .envrc e.g. add export MYVAR_2=56 and reload M-x envrc-allow You can see in *Messages* multiple lines like this

Running direnv in /tmp/tempdir/...
Direnv succeeded in /tmp/tempdir/
Running direnv in /tmp/tempdir/...
Direnv succeeded in /tmp/tempdir/

Why is it called multiple times? You can print cache keys for each buffer and see multiple MYVAR and MYVAR_2 for .envrc buffer and only MYVAR_2 for new buffer. in envrc--update

(`missing (let ((calculated (envrc--export env-dir)))
                                     (with-temp-file (concat "/tmp/env/" (buffer-name))
                                       (insert cache-key))
                                       ...

                                     ))
cd /tmp/env/
sed -i 's/\x0/\n/g' {.envrc,temp}
grep '^MYVAR' temp | wc -l # 4
grep '^MYVAR' .envrc | wc -l # 6
purcell commented 2 years ago

I'm tackling this by doing something crazy — starting to write a test suite! :joy:

purcell commented 2 years ago

Should be fixed by #35 now.

dvzubarev commented 2 years ago

Thank you, It is indeed fixed.

purcell commented 2 years ago

Great, thank you for your help and patience.