Skip to content

[1548] FIX: Unload environment on delete#1562

Open
jgfranco17 wants to merge 5 commits into
direnv:masterfrom
jgfranco17:fix/1548/reload-on-delete
Open

[1548] FIX: Unload environment on delete#1562
jgfranco17 wants to merge 5 commits into
direnv:masterfrom
jgfranco17:fix/1548/reload-on-delete

Conversation

@jgfranco17

Copy link
Copy Markdown

Fix: unload environment when .envrc is deleted

Addresses #1548.

When a loaded .envrc is deleted, direnv fails to unload the environment on the next prompt eval (or on cd out of the directory).

Root cause: In cmd_export.go, the early-return guard was:

if loadedRC == nil && toLoad == "" {
    return
}

Meanwhile DIRENV_DIFF is still set in the shell from the previous load, so the exported variables remain in the environment indefinitely.

Changes

  • Extend the early-return guard to also requireDIRENV_DIFF to be unset

Testing

  • Added test scenario for deleted .envrc

@jgfranco17 jgfranco17 marked this pull request as ready for review March 19, 2026 13:34
@winterqt

Copy link
Copy Markdown

Hi! I wrote a fix for this before seeing the issue + this PR.

Yours looks a bit simpler in terms of the actual implementation, but you might want to take my code for the tests, as yours has a chance of leaving the working tree dirty if it fails.

@jgfranco17

Copy link
Copy Markdown
Author

but you might want to take my code for the tests, as yours has a chance of leaving the working tree dirty if it fails.

Hi @winterqt, thanks for the assist! I've updated the test scripts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants