← Back to Pull requests

Unset GIT_INDEX_FILE for git+ VCS subprocesses #14291

Open
unknown opened this pull request with 247 lines diff across 3 files
View on GitHub
unknown unknown commented on Aug 30, 2026 11:54 UTC
Author

Fixes #14290

What

Git.unset_environ in pip/_internal/vcs/git.py already strips GIT_DIR and GIT_WORK_TREE from git subprocesses spawned for git+ VCS installs (#1130), but not GIT_INDEX_FILE. This PR adds it.

Why

git sets GIT_INDEX_FILE when invoking hooks (e.g. pre-commit), pointing at the index of the repo/worktree currently being committed. If such a hook runs a git+-pinned pip install (directly, or via a tool like pip-audit), the inherited GIT_INDEX_FILE causes pip's own git checkout — run inside its throwaway temp clone of the dependency — to write its checked-out tree into the hook-invoking repo's index instead of its own. Those entries reference blobs that only ever existed in the temp clone (deleted right after pip finishes), so git fsck/git diff --staged in the caller's repo comes back with missing blob / invalid sha1 pointer in cache-tree errors. This is fully deterministic — one git commit is enough, no concurrency needed. Repro steps and more detail are in #14290.

Testing

Added test_git_index_file_ignored, mirroring the existing test_git_dir_ignored / test_git_work_tree_ignored pattern: stages a file in a "work" repo with GIT_INDEX_FILE pointed at a separate "victim" repo's index, and asserts the victim index is untouched.

  • Confirmed this test fails without the fix (the victim index gets mutated) and passes with it.

  • ruff check and ruff format --check clean on both changed files.
  • PR Checklist:


  • I agree to follow the PSF Code of Conduct.

  • I have read and have followed the CONTRIBUTING.md file.

  • I have added a news file fragment (or this PR does not need one).

  • I have read and followed the AI_POLICY.md file, and if any AI tools were used, I have disclosed it below.
  • Assisted-by: Claude

    Diff: 247 lines (+185 / -62) across 3 files Reviewer: 2ykwang Review duration: 67662m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.46) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 247 lines diff across 3 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.330
    Real PR Conversation Timeline
    1 comments
    "Review active on #14291"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.9% (MEDIUM) · Higher = larger blast radius
    45.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.4% · Safe to merge
    25.4%
    Repository