Preserve locale during brew startup - #23332
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts Homebrew’s early startup environment handling to better preserve a user’s locale (while still forcing a safe UTF-8 fallback when needed), and to avoid expensive locale enumeration on Linux by reusing values already captured during bin/brew’s environment filtering.
Changes:
- Update
setup-localeto validate the active locale vialocale charmapand avoidlocale -awhen the filtered locale values are already UTF-8. - Add bash-level specs covering
setup-localebehavior (macOS charmap validation and Linux variable restoration). - Preserve
LC_ALL/LC_CTYPEthroughbin/brewfiltering by copying them intoHOMEBREW_*variables.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Library/Homebrew/utils/os.sh | Restores locale from filtered copies and enforces UTF-8 by validating locale charmap. |
| Library/Homebrew/test/bash_spec.rb | Adds tests for setup-locale behavior on macOS and Linux paths. |
| bin/brew | Copies LC_ALL and LC_CTYPE into HOMEBREW_* before environment filtering. |
Comments suppressed due to low confidence (2)
Library/Homebrew/utils/os.sh:110
- On macOS,
setup-localenever restoresLANG/LC_*from theHOMEBREW_LANG/HOMEBREW_LC_*copies thatbin/brewnow exports, so after environment filtering the locale remains unset and the macOS branch will always forceLC_ALL=en_US.UTF-8. This prevents preserving a valid user UTF-8 locale during startup and makes the newLC_ALL/LC_CTYPEexports inbin/brewineffective on macOS.
if [[ -z "${HOMEBREW_MACOS}" ]]
then
[[ -z "${HOMEBREW_LANG:-}" ]] || export LANG="${HOMEBREW_LANG}"
[[ -z "${HOMEBREW_LC_CTYPE:-}" ]] || export LC_CTYPE="${HOMEBREW_LC_CTYPE}"
[[ -z "${HOMEBREW_LC_ALL:-}" ]] || export LC_ALL="${HOMEBREW_LC_ALL}"
Library/Homebrew/utils/os.sh:120
locale charmapcan print warnings to stderr when the locale variables are invalid (the broken-locale scenario this code is trying to handle). Becausesetup-localeruns duringbrewstartup, those warnings can leak into user output. Suppressing stderr for the charmap probe keeps startup quiet while still letting you detect non-UTF-8.
if [[ -z "${LC_ALL:-${LC_CTYPE:-${LANG:-}}}" ]] || [[ "$(locale charmap)" != "UTF-8" ]]
then
export LC_ALL="en_US.UTF-8"
fi
else
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Validate the locale charmap instead of trusting its name. - Reuse filtered Linux locale settings to avoid `locale -a`.
MikeMcQuaid
force-pushed
the
improve-locale-startup
branch
from
July 28, 2026 11:03
98dc8ab to
059785d
Compare
bevanjkay
approved these changes
Jul 28, 2026
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.
locale -a.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?OpenAI Codex GPT 5.6 Sol xhigh with local review and (macOS) testing