From 313480a50d2103ee619a5a9c613def099d9bb2d7 Mon Sep 17 00:00:00 2001 From: Ryan Rotter Date: Thu, 2 Jan 2025 14:05:58 -0500 Subject: [PATCH 1/4] look for Brewfile in HOMEBREW_USER_CONFIG_HOME When --global is set, use `$HOMEBREW_USER_CONFIG_HOME/Brewfile` if it exists before falling back to `~/.Brewfile`. --- lib/bundle/brewfile.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/bundle/brewfile.rb b/lib/bundle/brewfile.rb index 913a92771..b57ebf6de 100644 --- a/lib/bundle/brewfile.rb +++ b/lib/bundle/brewfile.rb @@ -7,6 +7,7 @@ module Brewfile def path(dash_writes_to_stdout: false, global: false, file: nil) env_bundle_file_global = ENV.fetch("HOMEBREW_BUNDLE_FILE_GLOBAL", nil) env_bundle_file = ENV.fetch("HOMEBREW_BUNDLE_FILE", nil) + user_config_home = ENV.fetch("HOMEBREW_USER_CONFIG_HOME", nil) filename = if global if env_bundle_file_global.present? @@ -14,8 +15,12 @@ def path(dash_writes_to_stdout: false, global: false, file: nil) else raise "'HOMEBREW_BUNDLE_FILE' cannot be specified with '--global'" if env_bundle_file.present? - Bundle.exchange_uid_if_needed! do - "#{Dir.home}/.Brewfile" + if user_config_home && File.exist?("#{user_config_home}/Brewfile") + "#{user_config_home}/Brewfile" + else + Bundle.exchange_uid_if_needed! do + "#{Dir.home}/.Brewfile" + end end end elsif file.present? From 37dc2d4c52acfde7b4157693d8138238082ce430 Mon Sep 17 00:00:00 2001 From: Ryan Rotter Date: Fri, 24 Jan 2025 23:18:15 -0500 Subject: [PATCH 2/4] document alternate locations of global Brewfile --- cmd/bundle.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/bundle.rb b/cmd/bundle.rb index ab3d5b1ee..5a5fb292a 100755 --- a/cmd/bundle.rb +++ b/cmd/bundle.rb @@ -56,8 +56,8 @@ class BundleCmd < AbstractCommand flag "--file=", description: "Read the `Brewfile` from this location. Use `--file=-` to pipe to stdin/stdout." switch "--global", - description: "Read the `Brewfile` from `~/.Brewfile` or " \ - "the `HOMEBREW_BUNDLE_FILE_GLOBAL` environment variable, if set." + description: "Read the global `Brewfile`, from the homebrew config directory or `~/.Brewfile`. " \ + "Override this path with the `HOMEBREW_BUNDLE_FILE_GLOBAL` environment variable." switch "-v", "--verbose", description: "`install` prints output from commands as they are run. " \ "`check` lists all missing dependencies." From 28bf5f9072615cb776dc45caf94a1cf778d1fd7f Mon Sep 17 00:00:00 2001 From: Ryan Rotter Date: Sat, 25 Jan 2025 00:06:58 -0500 Subject: [PATCH 3/4] add spec for alternate global Brewfile path --- spec/bundle/brewfile_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/bundle/brewfile_spec.rb b/spec/bundle/brewfile_spec.rb index 824b2efc9..bb90f9804 100644 --- a/spec/bundle/brewfile_spec.rb +++ b/spec/bundle/brewfile_spec.rb @@ -11,8 +11,10 @@ let(:dash_writes_to_stdout) { false } let(:env_bundle_file_global_value) { nil } let(:env_bundle_file_value) { nil } + let(:env_user_config_home_value) { "/Users/username/.homebrew" } let(:file_value) { nil } let(:has_global) { false } + let(:config_dir_brewfile_exist) { false } before do allow(ENV).to receive(:fetch).and_return(nil) @@ -20,6 +22,11 @@ .and_return(env_bundle_file_global_value) allow(ENV).to receive(:fetch).with("HOMEBREW_BUNDLE_FILE", any_args) .and_return(env_bundle_file_value) + + allow(ENV).to receive(:fetch).with("HOMEBREW_USER_CONFIG_HOME", any_args) + .and_return(env_user_config_home_value) + allow(File).to receive(:exist?).with("/Users/username/.homebrew/Brewfile") + .and_return(config_dir_brewfile_exist) end context "when `file` is specified with a relative path" do @@ -154,6 +161,15 @@ expect(path).to eq(expected_pathname) end end + + context "when HOMEBREW_USER_CONFIG_HOME/Brewfile exists" do + let(:config_dir_brewfile_exist) { true } + let(:expected_pathname) { Pathname.new("#{env_user_config_home_value}/Brewfile") } + + it "returns the expected path" do + expect(path).to eq(expected_pathname) + end + end end context "when HOMEBREW_BUNDLE_FILE has a value" do From 369ddcf56c09252d43ea1ceebd4d1aaeb4c98181 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 27 Jan 2025 08:55:30 +0000 Subject: [PATCH 4/4] cmd/bundle: tweak --global documentation. --- cmd/bundle.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/bundle.rb b/cmd/bundle.rb index 5a5fb292a..9aa0cabd5 100755 --- a/cmd/bundle.rb +++ b/cmd/bundle.rb @@ -56,8 +56,9 @@ class BundleCmd < AbstractCommand flag "--file=", description: "Read the `Brewfile` from this location. Use `--file=-` to pipe to stdin/stdout." switch "--global", - description: "Read the global `Brewfile`, from the homebrew config directory or `~/.Brewfile`. " \ - "Override this path with the `HOMEBREW_BUNDLE_FILE_GLOBAL` environment variable." + description: "Read the `Brewfile` from `~/.Brewfile`, " \ + "in the `HOMEBREW_USER_CONFIG_HOME` directory, " \ + "or the `HOMEBREW_BUNDLE_FILE_GLOBAL` environment variable, if set." switch "-v", "--verbose", description: "`install` prints output from commands as they are run. " \ "`check` lists all missing dependencies."