Skip to content

bin/brew: preserve XDG_CONFIG_HOME through environment filter#21648

Merged
MikeMcQuaid merged 1 commit intoHomebrew:mainfrom
cohei:fix/preserve-xdg-config-home
Mar 1, 2026
Merged

bin/brew: preserve XDG_CONFIG_HOME through environment filter#21648
MikeMcQuaid merged 1 commit intoHomebrew:mainfrom
cohei:fix/preserve-xdg-config-home

Conversation

@cohei
Copy link

@cohei cohei commented Mar 1, 2026

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
    • bin/brew is a Bash script with no existing test coverage for the environment filtering logic.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.

Claude Code (Claude Opus 4.6) was used to assist throughout the investigation and fix.

Manual verification:

  • Prerequisites: XDG_CONFIG_HOME is set, and $XDG_CONFIG_HOME/homebrew/Brewfile exists
  • Confirmed that brew bundle --global install no longer fails with "No Brewfile found" when auto-update triggers a re-exec

Summary

  • Add XDG_CONFIG_HOME to USED_BY_HOMEBREW_VARS so it is copied to HOMEBREW_XDG_CONFIG_HOME and survives the env -i filter, matching the existing pattern for XDG_CACHE_HOME, XDG_DATA_DIRS and XDG_RUNTIME_DIR
  • Fall back to HOMEBREW_XDG_CONFIG_HOME when computing HOMEBREW_USER_CONFIG_HOME, so that the value is correct when bin/brew is re-executed after auto-update

Problem

brew bundle --global fails with "No Brewfile found" for users whose Brewfile is at $XDG_CONFIG_HOME/homebrew/Brewfile whenever auto-update triggers a re-exec via exec "${HOMEBREW_BREW_FILE}" "$@" in brew.sh.

The env -i environment filter in bin/brew strips XDG_CONFIG_HOME. On the initial run this is not a problem because HOMEBREW_USER_CONFIG_HOME is computed before the filter. However, after auto-update the re-exec goes through bin/brew again, where HOMEBREW_USER_CONFIG_HOME (a BIN_BREW_EXPORTED_VARS member) is recomputed — this time without XDG_CONFIG_HOME, causing it to fall back to ~/.homebrew.

This is the same class of issue that was fixed for XDG_CACHE_HOME in e1dda87.

Add `XDG_CONFIG_HOME` to `USED_BY_HOMEBREW_VARS` so it is copied to
`HOMEBREW_XDG_CONFIG_HOME` and survives the `env -i` filter, matching
the existing pattern for `XDG_CACHE_HOME`, `XDG_DATA_DIRS` and
`XDG_RUNTIME_DIR`.

Also fall back to `HOMEBREW_XDG_CONFIG_HOME` when computing
`HOMEBREW_USER_CONFIG_HOME`, so that the value is correct when
`bin/brew` is re-executed after auto-update (via `exec` in `brew.sh`)
and the original `XDG_CONFIG_HOME` has been filtered out.

Without this fix, `brew bundle --global` fails with "No Brewfile found"
for users whose Brewfile is at `$XDG_CONFIG_HOME/homebrew/Brewfile`
whenever auto-update triggers a re-exec.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nunezmati185-arch

This comment was marked as spam.

@cohei cohei marked this pull request as ready for review March 1, 2026 17:19
Copilot AI review requested due to automatic review settings March 1, 2026 17:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nunezmati185-arch

This comment was marked as spam.

@nunezmati185-arch

This comment was marked as spam.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Mar 1, 2026
Merged via the queue into Homebrew:main with commit 65ded76 Mar 1, 2026
36 checks passed
@cohei cohei deleted the fix/preserve-xdg-config-home branch March 2, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants