Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoenv_init: Only activate envs between PWD and previous dir #237

Closed
wants to merge 1 commit into from

Conversation

tomtseng
Copy link
Contributor

Fixes #228.

Issue

Suppose we cd from /a/b/c to /a/y/z.

Expected behavior: Presumably we've already invoked /.env, /a/.env, and /a/b/.env when we cded into /a/b/c, so I expect now cding into a/y/z/ to only invoke /a/y/.env and /a/y/z/.env.

Actual behavior: Invokes envs in all ancestors of /a/y/z: /.env, /a/.env, /a/y/.env, and /a/y/z/.env.

Changes

  • In autoenv_init(), when traversing up from /a/y/z, stop traversing once the previous directory /a/b/c is a child of the currently travsed directory.

Suppose we `cd` from `/a/b/c` to `/a/y/z`.

Expected behavior: Run `/a/y/.env` and `/a/y/z/.env`.

Actual behavior prior to this commit: Run `/.env`, `/a/.env`, `/a/y/.env`, and `/a/y/z/.env`.
@tomtseng tomtseng changed the title activate.sh: Only activate envs between PWD and previous dir autoenv_init: Only activate envs between PWD and previous dir Jun 22, 2024
@hyperupcall
Copy link
Owner

Thanks for the PR! Although this is a clean fix, I worry that addressing this issue will cause breakage. The readme states:

When executing, autoenv, will walk up the directories until the mount point and execute all .env files beginning at the top.

I don't want to make any changes that run contrary to that, since it's the intended behavior, even if it's possibly counter-intuitive.

I thought of one tangible case that could break downstream consumers:

  • An .env file at /home/user/.env with contents export GITHUB_TOKEN=... (assume token has "general permissions")
  • An .env file at /home/user/Projects/project1/.env with contents export GITHUB_TOKEN=... (assume token has "specific permissions")
  • When cding from /home/user/Projects/project1 from /home/user/Projects/project2, these new changes will no longer source /home/user/.env, meaning the token with the "general permissions" will not be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autoenv running on all directories in parent
2 participants