Move install-specific code to install.rb

This commit is contained in:
Connor Mann 2021-06-15 15:59:00 -04:00
parent bf9876c10f
commit 79f9a9aac6
No known key found for this signature in database
GPG Key ID: 5886083015754F6F
2 changed files with 23 additions and 28 deletions

View File

@ -344,30 +344,6 @@ class FormulaInstaller
Homebrew::Install.perform_build_from_source_checks
end
# not in initialize so upgrade can unlink the active keg before calling this
# function but after instantiating this class so that it can avoid having to
# relink the active keg if possible (because it is slow).
if formula.linked_keg.directory?
message = <<~EOS
#{formula.name} #{formula.linked_version} is already installed
EOS
if Homebrew::EnvConfig.no_install_upgrade? && formula.outdated? && !formula.head?
message += <<~EOS
To upgrade to #{formula.pkg_version}, run:
brew upgrade #{formula.full_name}
EOS
elsif only_deps?
message = nil
else
# some other version is already installed *and* linked
message += <<~EOS
To install #{formula.pkg_version}, first run:
brew unlink #{formula.name}
EOS
end
raise CannotInstallFormulaError, message if message
end
# Warn if a more recent version of this formula is available in the tap.
begin
if formula.pkg_version < (v = Formulary.factory(formula.full_name, force_bottle: force_bottle?).pkg_version)

View File

@ -270,11 +270,30 @@ module Homebrew
verbose: verbose,
)
if !Homebrew::EnvConfig.no_install_upgrade? && f.outdated? && !f.head?
if f.linked_keg.directory?
if Homebrew::EnvConfig.no_install_upgrade?
message = <<~EOS
#{f.name} #{f.linked_version} is already installed
EOS
message += if f.outdated? && !f.head?
<<~EOS
To upgrade to #{f.pkg_version}, run:
brew upgrade #{f.full_name}
EOS
else
<<~EOS
To install #{f.pkg_version}, first run:
brew unlink #{f.name}
EOS
end
raise CannotInstallFormulaError, message unless only_deps
elsif f.outdated? && !f.head?
puts "#{f.name} #{f.linked_version} is installed but outdated"
kegs = Upgrade.outdated_kegs(f)
linked_kegs = kegs.select(&:linked?)
Upgrade.print_upgrade_message(f, fi.options)
end
end
fi.prelude
fi.fetch