Skip to content

Commit

Permalink
Merge pull request #1379 from Homebrew/fix_stdin_install_cleanup
Browse files Browse the repository at this point in the history
Fix `brew bundle --cleanup` from `stdin`
  • Loading branch information
MikeMcQuaid committed Jun 7, 2024
2 parents 80c15f1 + 9242457 commit 0450821
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def run
file: args.file,
force: true,
zap: args.zap?,
dsl: Bundle::Commands::Install.dsl,
)
end
when "dump"
Expand Down
4 changes: 3 additions & 1 deletion lib/bundle/commands/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def reset!
Bundle::BrewServices.reset!
end

def run(global: false, file: nil, force: false, zap: false)
def run(global: false, file: nil, force: false, zap: false, dsl: nil)
@dsl ||= dsl

casks = casks_to_uninstall(global:, file:)
formulae = formulae_to_uninstall(global:, file:)
taps = taps_to_untap(global:, file:)
Expand Down
4 changes: 2 additions & 2 deletions lib/bundle/commands/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def run(*args, global: false, file: nil)
command_path = command_path.dirname.to_s
end

brewfile = Brewfile.read(global:, file:)
@dsl = Brewfile.read(global:, file:)

require "formula"
require "formulary"

ENV.deps = brewfile.entries.map do |entry|
ENV.deps = @dsl.entries.map do |entry|
next if entry.type != :brew

f = Formulary.factory(entry.name)
Expand Down
8 changes: 6 additions & 2 deletions lib/bundle/commands/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ module Install
module_function

def run(global: false, file: nil, no_lock: false, no_upgrade: false, verbose: false, force: false, quiet: false)
parsed_entries = Brewfile.read(global:, file:).entries
@dsl = Brewfile.read(global:, file:)
Bundle::Installer.install(
parsed_entries,
@dsl.entries,
global:, file:, no_lock:, no_upgrade:, verbose:, force:, quiet:,
) || exit(1)
end

def dsl
@dsl
end
end
end
end
12 changes: 12 additions & 0 deletions spec/bundle/commands/install_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
expect { described_class.run }.not_to raise_error
end

it "#dsl returns a valid DSL" do
allow(Bundle::TapInstaller).to receive(:preinstall).and_return(false)
allow(Bundle::WhalebrewInstaller).to receive(:preinstall).and_return(false)
allow(Bundle::VscodeExtensionInstaller).to receive(:preinstall).and_return(false)
allow(Bundle::BrewInstaller).to receive_messages(preinstall: true, install: true)
allow(Bundle::CaskInstaller).to receive_messages(preinstall: true, install: true)
allow(Bundle::MacAppStoreInstaller).to receive_messages(preinstall: true, install: true)
allow_any_instance_of(Pathname).to receive(:read).and_return(brewfile_contents)
described_class.run
expect(described_class.dsl.entries.first.name).to eql("phinze/cask")
end

it "does not raise an error when skippable" do
expect(Bundle::BrewInstaller).not_to receive(:install)

Expand Down

0 comments on commit 0450821

Please sign in to comment.