From fb65fa9de928f705c5a5825f0d824ac543a279be Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Sep 2025 07:47:53 +0000 Subject: [PATCH] Fix brew bundle dump --global to respect XDG_CONFIG_HOME - Remove File.exist? check in brewfile.rb to use XDG path even when Brewfile doesn't exist yet - Add directory creation in dumper.rb to ensure parent directories exist before writing - Add test case for XDG behavior when Brewfile doesn't exist initially Co-authored-by: MikeMcQuaid <125011+MikeMcQuaid@users.noreply.github.com> --- Library/Homebrew/bundle/brewfile.rb | 2 +- Library/Homebrew/bundle/dumper.rb | 1 + Library/Homebrew/test/bundle/brewfile_spec.rb | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/bundle/brewfile.rb b/Library/Homebrew/bundle/brewfile.rb index 60e1a1fba4..4c526504d0 100644 --- a/Library/Homebrew/bundle/brewfile.rb +++ b/Library/Homebrew/bundle/brewfile.rb @@ -24,7 +24,7 @@ module Homebrew else raise "'HOMEBREW_BUNDLE_FILE' cannot be specified with '--global'" if env_bundle_file.present? - if user_config_home && File.exist?("#{user_config_home}/Brewfile") + if user_config_home "#{user_config_home}/Brewfile" else Bundle.exchange_uid_if_needed! do diff --git a/Library/Homebrew/bundle/dumper.rb b/Library/Homebrew/bundle/dumper.rb index 218b297890..c5ef1ddb17 100644 --- a/Library/Homebrew/bundle/dumper.rb +++ b/Library/Homebrew/bundle/dumper.rb @@ -81,6 +81,7 @@ module Homebrew sig { params(file: Pathname, content: String).void } def self.write_file(file, content) Bundle.exchange_uid_if_needed! do + FileUtils.mkdir_p file.parent file.open("w") { |io| io.write content } end end diff --git a/Library/Homebrew/test/bundle/brewfile_spec.rb b/Library/Homebrew/test/bundle/brewfile_spec.rb index 9be511c2a5..febdcb0afe 100644 --- a/Library/Homebrew/test/bundle/brewfile_spec.rb +++ b/Library/Homebrew/test/bundle/brewfile_spec.rb @@ -1,3 +1,4 @@ +# typed: strict # frozen_string_literal: true require "bundle" @@ -171,6 +172,14 @@ RSpec.describe Homebrew::Bundle::Brewfile do expect(path).to eq(expected_pathname) end end + + context "when HOMEBREW_USER_CONFIG_HOME is set but Brewfile does not exist" do + let(:config_dir_brewfile_exist) { false } + + it "returns the XDG-compliant path when HOMEBREW_USER_CONFIG_HOME is set" do + expect(path).to eq(Pathname.new("#{env_user_config_home_value}/Brewfile")) + end + end end context "when HOMEBREW_BUNDLE_FILE has a value" do