From a67c0f2e88b1c0dbd82a2b2ec3a0b953ceb821d8 Mon Sep 17 00:00:00 2001 From: wojteksbt <13969461+wojteksbt@users.noreply.github.com> Date: Wed, 13 May 2026 21:51:33 +0200 Subject: [PATCH] bundle: try `mas install` before falling back to `mas get` Fixes purchase-history regression introduced by #21590 (closes #21559). `mas get` fails on macOS 26.5 / mas 7.0.0 for apps in the Apple ID's purchase history but not on disk, while `mas install` succeeds. Try `install` first (fast path for owned apps); fall back to `get` for fresh-account scenario (the original #21559 motivation). Fixes #22270 --- Library/Homebrew/bundle/extensions/mac_app_store.rb | 4 +++- Library/Homebrew/test/bundle/mac_app_store_spec.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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)