Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[1548] FIX: Unload environment on delete#1562

Open
jgfranco17 wants to merge 5 commits into
direnv:masterdirenv/direnv:masterfrom
jgfranco17:fix/1548/reload-on-deletejgfranco17/direnv:fix/1548/reload-on-deleteCopy head branch name to clipboard
Open

[1548] FIX: Unload environment on delete#1562
jgfranco17 wants to merge 5 commits into
direnv:masterdirenv/direnv:masterfrom
jgfranco17:fix/1548/reload-on-deletejgfranco17/direnv:fix/1548/reload-on-deleteCopy head branch name to clipboard

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.