From 42d4f3d8b920cb70fff7c1f9e12b1d9544a9064a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 15 Aug 2025 19:18:52 +0100 Subject: [PATCH] Upgrade unlinked/unpinned kegs Co-authored-by: MikeMcQuaid <125011+MikeMcQuaid@users.noreply.github.com> --- Library/Homebrew/formula.rb | 5 ++++- Library/Homebrew/test/cmd/upgrade_spec.rb | 12 ++++++++++++ Library/Homebrew/test/formula_spec.rb | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 2efc9e5e89..072d2b0c62 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1681,7 +1681,10 @@ class Formula # don't consider this keg current if there's a newer formula available next if follow_installed_alias? && new_formula_available? - # this keg is the current version of the formula, so it's not outdated + # this keg is the current version of the formula, but only consider it current + # if it's actually linked - an unlinked current version means we're outdated + next if !keg.optlinked? && !keg.linked? && !pinned? + current_version = true break end diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index 152a07b9ec..c39a27901a 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -18,6 +18,18 @@ RSpec.describe Homebrew::Cmd::UpgradeCmd do expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist end + it "links newer version when upgrade was interrupted", :integration_test do + setup_test_formula "testball" + + (HOMEBREW_CELLAR/"testball/0.1/foo").mkpath + + expect { brew "upgrade" }.to be_a_success + + expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory + expect(HOMEBREW_PREFIX/"opt/testball").to be_a_symlink + expect(HOMEBREW_PREFIX/"var/homebrew/linked/testball").to be_a_symlink + end + it "upgrades with asking for user prompts", :integration_test do setup_test_formula "testball" (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index ada1618966..9925d05ce6 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -1364,6 +1364,10 @@ RSpec.describe Formula do def setup_tab_for_prefix(prefix, options = {}) prefix.mkpath + + keg = Keg.new(prefix) + keg.optlink + tab = Tab.empty tab.tabfile = prefix/AbstractTab::FILENAME tab.source["path"] = options[:path].to_s if options[:path] @@ -1396,6 +1400,12 @@ RSpec.describe Formula do expect(f.outdated_kegs).not_to be_empty end + example "outdated unlinked tap installed" do + setup_tab_for_prefix(same_prefix) + Keg.new(same_prefix).remove_opt_record + expect(f.outdated_kegs).not_to be_empty + end + example "outdated follow alias and alias unchanged" do f.follow_installed_alias = true f.build = setup_tab_for_prefix(same_prefix, path: alias_path)