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:
parent
cb7dbbae55
commit
fb65fa9de9
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user