Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

look for Brewfile in HOMEBREW_USER_CONFIG_HOME #1549

Merged
merged 4 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
MikeMcQuaid marked this conversation as resolved.
Show resolved Hide resolved
switch "-v", "--verbose",
description: "`install` prints output from commands as they are run. " \
"`check` lists all missing dependencies."
Expand Down
9 changes: 7 additions & 2 deletions lib/bundle/brewfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ 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?
env_bundle_file_global
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?
Expand Down
16 changes: 16 additions & 0 deletions spec/bundle/brewfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@
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)
allow(ENV).to receive(:fetch).with("HOMEBREW_BUNDLE_FILE_GLOBAL", any_args)
.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
Expand Down Expand Up @@ -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
Expand Down
Loading