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>
This commit is contained in:
copilot-swe-agent[bot] 2025-09-09 07:47:53 +00:00
parent cb7dbbae55
commit fb65fa9de9
3 changed files with 11 additions and 1 deletions

View File

@ -24,7 +24,7 @@ module Homebrew
else else
raise "'HOMEBREW_BUNDLE_FILE' cannot be specified with '--global'" if env_bundle_file.present? 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" "#{user_config_home}/Brewfile"
else else
Bundle.exchange_uid_if_needed! do Bundle.exchange_uid_if_needed! do

View File

@ -81,6 +81,7 @@ module Homebrew
sig { params(file: Pathname, content: String).void } sig { params(file: Pathname, content: String).void }
def self.write_file(file, content) def self.write_file(file, content)
Bundle.exchange_uid_if_needed! do Bundle.exchange_uid_if_needed! do
FileUtils.mkdir_p file.parent
file.open("w") { |io| io.write content } file.open("w") { |io| io.write content }
end end
end end

View File

@ -1,3 +1,4 @@
# typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "bundle" require "bundle"
@ -171,6 +172,14 @@ RSpec.describe Homebrew::Bundle::Brewfile do
expect(path).to eq(expected_pathname) expect(path).to eq(expected_pathname)
end end
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 end
context "when HOMEBREW_BUNDLE_FILE has a value" do context "when HOMEBREW_BUNDLE_FILE has a value" do