Strip GIT_DIR and friends from internal git subprocess calls#19042
Closed
BootstrapperSBL wants to merge 1 commit intoastral-sh:mainfrom
Closed
Strip GIT_DIR and friends from internal git subprocess calls#19042BootstrapperSBL wants to merge 1 commit intoastral-sh:mainfrom
BootstrapperSBL wants to merge 1 commit intoastral-sh:mainfrom
Conversation
…sh#19008) `git bisect run` sets `GIT_DIR` (and related env vars) in the process environment. When uv is invoked as the bisect command it inherits those variables, and they leak into every `git` subprocess uv spawns — causing those operations to hit the bisected repo's index instead of uv's cache. `fetch_with_cli` and `fetch_lfs` already stripped these variables individually, but the other eight `ProcessBuilder::new(GIT…)` call sites did not. Introduce a `git_cmd()` helper that creates a `ProcessBuilder` with `GIT_DIR`, `GIT_WORK_TREE`, `GIT_INDEX_FILE`, `GIT_OBJECT_DIRECTORY`, and `GIT_ALTERNATE_OBJECT_DIRECTORIES` always removed, and replace all call sites with it. The fetch helpers now use `git_cmd()` too, so the per-call `env_remove` chains there can be dropped. Fixes astral-sh#19008
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #19008.
git bisect run(andgit rebase --exec) injectsGIT_DIRinto theprocess environment before calling the user's command. When that command
is
uv, the variable leaks into everygitsubprocess uv spawns,directing them at the bisected repo instead of uv's own cache.
fetch_with_cliandfetch_lfsalready stripped these five env varsindividually. The other call sites —
open,init,rev_parse,to_short_id, both clone variants,reset, andsubmodule update—did not.
Changes
Introduce a
git_cmd()helper:All call sites now go through
git_cmd(). The per-callenv_removechains in
fetch_with_cliandfetch_lfsare removed since the helpercovers them.
Before / After
Before:
GIT_DIR=/bisected-repo/.git uv lock(with a git dependency) fails — uv's internalgit rev-parse,git clone, etc. hit the wrong repo.After: same command succeeds —
git_cmd()strips the variable before each subprocess is spawned.Test
Added
lock_sdist_git_with_git_dir_env(behind#[cfg(feature = "test-git")]) that runsuv lockwithGIT_DIR=/nonexistentin the environment and expects success.