Null Git global config for local repository inspections#22797
Merged
Conversation
`last_commit` and `current_revision` run `git rev-parse` against the
cached clone while staging inside the build sandbox, before the stage
environment nulls the global Git config. There, reading the user's
global Git config is denied and makes Git exit, so `last_commit` returns
an empty string. For HEAD builds this makes `update_commit("")` produce a
bare `HEAD-` version, the build installs to `Cellar/<name>/HEAD-`, and
the install then fails with `Error: Empty installation` once the real
short commit is computed outside the sandbox.
These are local, read-only inspections of an already-cloned repository
that never need credential helpers, so null the global config for them
via a shared `local_git_env` helper, matching the existing
`source_modified_time` fix. The download-time commands keep reading the
user config for private-repository credentials.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes sandboxed staging failures for --HEAD installs by ensuring read-only Git inspections against an already-cached clone do not read the user’s global Git config (which can be denied in the sandbox), preventing empty last_commit/current_revision results and downstream versioning/install path issues.
Changes:
- Introduces a shared
local_git_envhelper that mergesGIT_TERMINAL_PROMPT=0withUtils::Git.no_global_config_env. - Routes local inspection commands (
git ... show/git ... rev-parse) insource_modified_time,last_commit, andcurrent_revisionthroughlocal_git_env. - Updates the Git download strategy spec to assert
#last_commituses the null-global-config env.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Library/Homebrew/download_strategy/git_download_strategy.rb | Adds local_git_env and applies it to local Git inspection calls to avoid sandbox global-config reads. |
| Library/Homebrew/test/download_strategies/git_spec.rb | Refactors/extends #last_commit tests to assert the correct env is passed to system_command. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
MikeMcQuaid
approved these changes
Jun 18, 2026
MikeMcQuaid
left a comment
Member
There was a problem hiding this comment.
Thanks for fix here @carlocab and apologies for the regressions 🙈
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.
brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?I used Claude to diagnose the bug and write the fix. I reviewed the resulting code and manually ran
brew lgtmand also manually checked that the bug has been fixed.last_commitandcurrent_revisionrungit rev-parseagainst thecached clone while staging inside the build sandbox, before the stage
environment nulls the global Git config. There, reading the user's
global Git config is denied and makes Git exit, so
last_commitreturnsan empty string. For HEAD builds this makes
update_commit("")produce abare
HEAD-version, the build installs toCellar/<name>/HEAD-, andthe install then fails with
Error: Empty installationonce the realshort commit is computed outside the sandbox.
These are local, read-only inspections of an already-cloned repository
that never need credential helpers, so null the global config for them
via a shared
local_git_envhelper, matching the existingsource_modified_timefix. The download-time commands keep reading theuser config for private-repository credentials.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
To reproduce, run: