diff --git a/Library/Homebrew/bundle/extensions/mac_app_store.rb b/Library/Homebrew/bundle/extensions/mac_app_store.rb index 0ca3af1d4f10d..9cf39a817f2a4 100644 --- a/Library/Homebrew/bundle/extensions/mac_app_store.rb +++ b/Library/Homebrew/bundle/extensions/mac_app_store.rb @@ -200,7 +200,9 @@ def install!(name, id = nil, with: nil, preinstall: true, no_upgrade: false, ver end puts "Installing #{name} app. It is not currently installed." if verbose - return false unless Bundle.system(mas, "get", id.to_s, verbose:) + installed = Bundle.system(mas, "install", id.to_s, verbose:) || + Bundle.system(mas, "get", id.to_s, verbose:) + return false unless installed apps << [id.to_s, name] unless apps.any? { |app_id, _app_name| app_id.to_i == id } packages << App.new(id: id.to_s, name:) unless packages.any? { |app| app.id.to_i == id } diff --git a/Library/Homebrew/test/bundle/mac_app_store_spec.rb b/Library/Homebrew/test/bundle/mac_app_store_spec.rb index f92462208dd05..bfdcf32650af7 100644 --- a/Library/Homebrew/test/bundle/mac_app_store_spec.rb +++ b/Library/Homebrew/test/bundle/mac_app_store_spec.rb @@ -258,6 +258,15 @@ end it "installs app" do + expect(Homebrew::Bundle).to receive(:system).with(Pathname("mas"), "install", "123", verbose: false) + .and_return(true) + expect(described_class.preinstall!("foo", 123)).to be(true) + expect(described_class.install!("foo", 123)).to be(true) + end + + it "falls back to `mas get` when `mas install` fails" do + expect(Homebrew::Bundle).to receive(:system).with(Pathname("mas"), "install", "123", verbose: false) + .and_return(false) expect(Homebrew::Bundle).to receive(:system).with(Pathname("mas"), "get", "123", verbose: false) .and_return(true) expect(described_class.preinstall!("foo", 123)).to be(true)