Repository navigation
Description
Problem
git_command_in() creates git -c protocol.ext.allow=never -C <checkout> ... but inherits the process environment unchanged. The clone path in ensure_repository() creates another Git command independently.
Repository-selection variables inherited from a parent process can override the intended checkout. In particular, setting GIT_DIR to a different repository causes git -C <checkout> rev-parse HEAD to inspect that other repository despite -C. This can affect origin checks, commit lookup, status inspection, and checkout operations.
This is relevant when Vex is launched from a Git hook or another tool that exports repository-local Git environment variables. Git's hook documentation explicitly describes clearing that context before operating on a different repository.
Code reference: src/resolver.rs — git_command_in, ensure_repository, verify_origin, git_has_commit, require_checkout_at, and checkout_commit.
Reproduction scenario
Create two temporary repositories with distinct HEAD commits. With GIT_DIR unset, reading HEAD using git -C <managed-checkout> selects the managed repository. With GIT_DIR set to the other repository's absolute .git path, the same command reads the other HEAD:
GIT_DIR=/absolute/path/to/other/.git \
git -c protocol.ext.allow=never -C /absolute/path/to/managed rev-parse HEADUse those isolated repositories to test Vex's dependency commands as well. The expected result is that Git operations always address the dependency selected by Vex, not a repository named by inherited environment state.
Expected behavior
Centralize dependency Git command construction and explicitly remove inherited repository-selection context from the child environment. Apply the same policy to clone and commands executed inside existing checkouts.
Do not clear the entire environment or indiscriminately remove every GIT_* variable. Ordinary authentication, SSH, proxy, HOME/config discovery, and user URL-rewrite settings must remain usable.
Acceptance criteria
- Introduce one documented child-environment policy for all dependency Git subprocesses, including the separate clone path.
- Handle at least
GIT_DIR,GIT_WORK_TREE, andGIT_INDEX_FILE; review related common-directory, object-directory, alternate-object, and namespace variables and document the chosen removal set. - Keep
protocol.ext.allow=neverand existing platform-specific path handling intact. - Add isolated integration tests injecting repository-selection variables individually and in relevant combinations. Use distinct repositories so accidentally inspecting the wrong HEAD or origin cannot pass.
- Cover fetch/update, locked offline reuse, and dry-run checkout verification.
- Assert the unrelated repository's HEAD, index, and working-tree files remain unchanged.
- Preserve normal user transport/configuration behavior, including the
insteadOfscenario tracked in Preserve declared Git source identity when insteadOf rewrites transport URLs #108. - Set environment overrides on test child processes rather than mutating the test runner's global environment, and run
cargo test --locked.
Related: #19 checks whether a selected checkout is dirty. This issue ensures the Git command selects the intended repository in the first place. Child-process cancellation and timeout policy remain separate work.
Activity