fix(env): Enhance support for Git worktrees and shared virtual environments#108406
fix(env): Enhance support for Git worktrees and shared virtual environments#108406
Conversation
…nments Updated .envrc to allow for a shared virtual environment across multiple Git worktrees by setting VIRTUAL_ENV dynamically. Node checks are now conditional based on the presence of a .node-version file, improving compatibility with different directory structures. Added documentation in AGENTS.md to clarify development practices with Git worktrees.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| # not needed for getsentry | ||
| if [ "${PWD##*/}" = "sentry" ]; then | ||
| # only run Node checks when .node-version exists (sentry has it, getsentry does not); works for worktrees | ||
| if [ -f "${SENTRY_ROOT}/.node-version" ]; then |
There was a problem hiding this comment.
Inconsistent path references for .node-version file
Low Severity
The guard on the new line checks ${SENTRY_ROOT}/.node-version for existence, but the read inside the block still uses bare .node-version (relative to PWD). Since SENTRY_ROOT resolves symlinks via pwd -P and PWD may not, these can refer to different filesystem paths. Before this change, both the guard and the read were implicitly PWD-relative, so they were consistent. The read (and the node_modules directory check) need to use "${SENTRY_ROOT}/.node-version" to match the guard, especially given the PR's goal of robust worktree and directory-structure support.
Additional Locations (1)
| if [ -f .venv/bin/devenv ]; then | ||
| DEVENV=.venv/bin/devenv | ||
| # VIRTUAL_ENV can be set in .env (e.g. to a primary worktree's .venv for Cursor Parallel Agents) | ||
| export VIRTUAL_ENV="${VIRTUAL_ENV:-$PWD/.venv}" |
There was a problem hiding this comment.
Inherited VIRTUAL_ENV from parent shell silently misroutes environment
Low Severity
The ${VIRTUAL_ENV:-$PWD/.venv} pattern preserves any pre-existing VIRTUAL_ENV from the parent shell, not just values deliberately set in .env. If a developer has another virtualenv active (e.g. via source activate), the sentry .envrc will silently use that foreign virtualenv for the devenv lookup, PATH_add, and the exported VIRTUAL_ENV. The old code unconditionally set VIRTUAL_ENV to $PWD/.venv, so it was immune to this. A narrower mechanism that only respects the .env override would avoid this side effect.


Updated .envrc to allow for a shared virtual environment across multiple Git worktrees by setting VIRTUAL_ENV dynamically. Node checks are now conditional based on the presence of a .node-version file, improving compatibility with different directory structures. Added documentation in AGENTS.md to clarify development practices with Git worktrees.