Merge pull request #20446 from Homebrew/copilot/fix-20427
Fix `brew upgrade` not linking newer versions when upgrade interrupted
This commit is contained in:
		
						commit
						0d4f3419ac
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user