Port Homebrew::Cmd::UpdateReport
This commit is contained in:
parent
48f4adad33
commit
d5add6565c
@ -1,6 +1,7 @@
|
|||||||
# typed: true
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "abstract_command"
|
||||||
require "migrator"
|
require "migrator"
|
||||||
require "formulary"
|
require "formulary"
|
||||||
require "cask/cask_loader"
|
require "cask/cask_loader"
|
||||||
@ -8,405 +9,406 @@ require "cask/migrator"
|
|||||||
require "descriptions"
|
require "descriptions"
|
||||||
require "cleanup"
|
require "cleanup"
|
||||||
require "description_cache_store"
|
require "description_cache_store"
|
||||||
require "cli/parser"
|
|
||||||
require "settings"
|
require "settings"
|
||||||
require "linuxbrew-core-migration"
|
require "linuxbrew-core-migration"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module Cmd
|
||||||
|
class UpdateReport < AbstractCommand
|
||||||
def auto_update_header(args:)
|
cmd_args do
|
||||||
@auto_update_header ||= begin
|
description <<~EOS
|
||||||
ohai "Auto-updated Homebrew!" if args.auto_update?
|
The Ruby implementation of `brew update`. Never called manually.
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { returns(CLI::Parser) }
|
|
||||||
def update_report_args
|
|
||||||
Homebrew::CLI::Parser.new do
|
|
||||||
description <<~EOS
|
|
||||||
The Ruby implementation of `brew update`. Never called manually.
|
|
||||||
EOS
|
|
||||||
switch "--auto-update", "--preinstall",
|
|
||||||
description: "Run in 'auto-update' mode (faster, less output)."
|
|
||||||
switch "-f", "--force",
|
|
||||||
description: "Treat installed and updated formulae as if they are from " \
|
|
||||||
"the same taps and migrate them anyway."
|
|
||||||
|
|
||||||
hide_from_man_page!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_report
|
|
||||||
return output_update_report if $stdout.tty?
|
|
||||||
|
|
||||||
redirect_stdout($stderr) do
|
|
||||||
output_update_report
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def output_update_report
|
|
||||||
args = update_report_args.parse
|
|
||||||
|
|
||||||
# Run `brew update` (again) if we've got a linuxbrew-core CoreTap
|
|
||||||
if CoreTap.instance.installed? && CoreTap.instance.linuxbrew_core? &&
|
|
||||||
ENV["HOMEBREW_LINUXBREW_CORE_MIGRATION"].blank?
|
|
||||||
ohai "Re-running `brew update` for linuxbrew-core migration"
|
|
||||||
|
|
||||||
if Homebrew::EnvConfig.core_git_remote != HOMEBREW_CORE_DEFAULT_GIT_REMOTE
|
|
||||||
opoo <<~EOS
|
|
||||||
HOMEBREW_CORE_GIT_REMOTE was set: #{Homebrew::EnvConfig.core_git_remote}.
|
|
||||||
It has been unset for the migration.
|
|
||||||
You may need to change this from a linuxbrew-core mirror to a homebrew-core one.
|
|
||||||
|
|
||||||
EOS
|
EOS
|
||||||
|
switch "--auto-update", "--preinstall",
|
||||||
|
description: "Run in 'auto-update' mode (faster, less output)."
|
||||||
|
switch "-f", "--force",
|
||||||
|
description: "Treat installed and updated formulae as if they are from " \
|
||||||
|
"the same taps and migrate them anyway."
|
||||||
|
|
||||||
|
hide_from_man_page!
|
||||||
end
|
end
|
||||||
ENV.delete("HOMEBREW_CORE_GIT_REMOTE")
|
|
||||||
|
|
||||||
if Homebrew::EnvConfig.bottle_domain != HOMEBREW_BOTTLE_DEFAULT_DOMAIN
|
sig { override.void }
|
||||||
opoo <<~EOS
|
def run
|
||||||
HOMEBREW_BOTTLE_DOMAIN was set: #{Homebrew::EnvConfig.bottle_domain}.
|
return output_update_report if $stdout.tty?
|
||||||
It has been unset for the migration.
|
|
||||||
You may need to change this from a Linuxbrew package mirror to a Homebrew one.
|
|
||||||
|
|
||||||
EOS
|
redirect_stdout($stderr) do
|
||||||
|
output_update_report
|
||||||
|
end
|
||||||
end
|
end
|
||||||
ENV.delete("HOMEBREW_BOTTLE_DOMAIN")
|
|
||||||
|
|
||||||
ENV["HOMEBREW_LINUXBREW_CORE_MIGRATION"] = "1"
|
private
|
||||||
FileUtils.rm_f HOMEBREW_LOCKS/"update"
|
|
||||||
|
|
||||||
update_args = []
|
def auto_update_header
|
||||||
update_args << "--auto-update" if args.auto_update?
|
@auto_update_header ||= begin
|
||||||
update_args << "--force" if args.force?
|
ohai "Auto-updated Homebrew!" if args.auto_update?
|
||||||
exec HOMEBREW_BREW_FILE, "update", *update_args
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
if ENV["HOMEBREW_ADDITIONAL_GOOGLE_ANALYTICS_ID"].present?
|
|
||||||
opoo "HOMEBREW_ADDITIONAL_GOOGLE_ANALYTICS_ID is now a no-op so can be unset."
|
|
||||||
puts "All Homebrew Google Analytics code and data was destroyed."
|
|
||||||
end
|
|
||||||
|
|
||||||
if ENV["HOMEBREW_NO_GOOGLE_ANALYTICS"].present?
|
|
||||||
opoo "HOMEBREW_NO_GOOGLE_ANALYTICS is now a no-op so can be unset."
|
|
||||||
puts "All Homebrew Google Analytics code and data was destroyed."
|
|
||||||
end
|
|
||||||
|
|
||||||
unless args.quiet?
|
|
||||||
analytics_message
|
|
||||||
donation_message
|
|
||||||
install_from_api_message
|
|
||||||
end
|
|
||||||
|
|
||||||
tap_or_untap_core_taps_if_necessary
|
|
||||||
|
|
||||||
updated = false
|
|
||||||
new_tag = nil
|
|
||||||
|
|
||||||
initial_revision = ENV["HOMEBREW_UPDATE_BEFORE"].to_s
|
|
||||||
current_revision = ENV["HOMEBREW_UPDATE_AFTER"].to_s
|
|
||||||
odie "update-report should not be called directly!" if initial_revision.empty? || current_revision.empty?
|
|
||||||
|
|
||||||
if initial_revision != current_revision
|
|
||||||
auto_update_header(args:)
|
|
||||||
|
|
||||||
updated = true
|
|
||||||
|
|
||||||
old_tag = Settings.read "latesttag"
|
|
||||||
|
|
||||||
new_tag = Utils.popen_read(
|
|
||||||
"git", "-C", HOMEBREW_REPOSITORY, "tag", "--list", "--sort=-version:refname", "*.*"
|
|
||||||
).lines.first.chomp
|
|
||||||
|
|
||||||
Settings.write "latesttag", new_tag if new_tag != old_tag
|
|
||||||
|
|
||||||
if new_tag == old_tag
|
|
||||||
ohai "Updated Homebrew from #{shorten_revision(initial_revision)} to #{shorten_revision(current_revision)}."
|
|
||||||
elsif old_tag.blank?
|
|
||||||
ohai "Updated Homebrew from #{shorten_revision(initial_revision)} " \
|
|
||||||
"to #{new_tag} (#{shorten_revision(current_revision)})."
|
|
||||||
else
|
|
||||||
ohai "Updated Homebrew from #{old_tag} (#{shorten_revision(initial_revision)}) " \
|
|
||||||
"to #{new_tag} (#{shorten_revision(current_revision)})."
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Check if we can parse the JSON and do any Ruby-side follow-up.
|
def output_update_report
|
||||||
unless Homebrew::EnvConfig.no_install_from_api?
|
# Run `brew update` (again) if we've got a linuxbrew-core CoreTap
|
||||||
Homebrew::API::Formula.write_names_and_aliases
|
if CoreTap.instance.installed? && CoreTap.instance.linuxbrew_core? &&
|
||||||
Homebrew::API::Cask.write_names
|
ENV["HOMEBREW_LINUXBREW_CORE_MIGRATION"].blank?
|
||||||
end
|
ohai "Re-running `brew update` for linuxbrew-core migration"
|
||||||
|
|
||||||
Homebrew.failed = true if ENV["HOMEBREW_UPDATE_FAILED"]
|
if Homebrew::EnvConfig.core_git_remote != HOMEBREW_CORE_DEFAULT_GIT_REMOTE
|
||||||
return if Homebrew::EnvConfig.disable_load_formula?
|
opoo <<~EOS
|
||||||
|
HOMEBREW_CORE_GIT_REMOTE was set: #{Homebrew::EnvConfig.core_git_remote}.
|
||||||
|
It has been unset for the migration.
|
||||||
|
You may need to change this from a linuxbrew-core mirror to a homebrew-core one.
|
||||||
|
|
||||||
migrate_gcc_dependents_if_needed
|
EOS
|
||||||
|
|
||||||
hub = ReporterHub.new
|
|
||||||
|
|
||||||
updated_taps = []
|
|
||||||
Tap.installed.each do |tap|
|
|
||||||
next if !tap.git? || tap.git_repo.origin_url.nil?
|
|
||||||
next if (tap.core_tap? || tap.core_cask_tap?) && !Homebrew::EnvConfig.no_install_from_api?
|
|
||||||
|
|
||||||
if ENV["HOMEBREW_MIGRATE_LINUXBREW_FORMULAE"].present? && tap.core_tap? &&
|
|
||||||
Settings.read("linuxbrewmigrated") != "true"
|
|
||||||
ohai "Migrating formulae from linuxbrew-core to homebrew-core"
|
|
||||||
|
|
||||||
LINUXBREW_CORE_MIGRATION_LIST.each do |name|
|
|
||||||
begin
|
|
||||||
formula = Formula[name]
|
|
||||||
rescue FormulaUnavailableError
|
|
||||||
next
|
|
||||||
end
|
end
|
||||||
next unless formula.any_version_installed?
|
ENV.delete("HOMEBREW_CORE_GIT_REMOTE")
|
||||||
|
|
||||||
keg = formula.installed_kegs.last
|
if Homebrew::EnvConfig.bottle_domain != HOMEBREW_BOTTLE_DEFAULT_DOMAIN
|
||||||
tab = Tab.for_keg(keg)
|
opoo <<~EOS
|
||||||
# force a `brew upgrade` from the linuxbrew-core version to the homebrew-core version (even if lower)
|
HOMEBREW_BOTTLE_DOMAIN was set: #{Homebrew::EnvConfig.bottle_domain}.
|
||||||
tab.source["versions"]["version_scheme"] = -1
|
It has been unset for the migration.
|
||||||
tab.write
|
You may need to change this from a Linuxbrew package mirror to a Homebrew one.
|
||||||
|
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
ENV.delete("HOMEBREW_BOTTLE_DOMAIN")
|
||||||
|
|
||||||
|
ENV["HOMEBREW_LINUXBREW_CORE_MIGRATION"] = "1"
|
||||||
|
FileUtils.rm_f HOMEBREW_LOCKS/"update"
|
||||||
|
|
||||||
|
update_args = []
|
||||||
|
update_args << "--auto-update" if args.auto_update?
|
||||||
|
update_args << "--force" if args.force?
|
||||||
|
exec HOMEBREW_BREW_FILE, "update", *update_args
|
||||||
end
|
end
|
||||||
|
|
||||||
Settings.write "linuxbrewmigrated", true
|
if ENV["HOMEBREW_ADDITIONAL_GOOGLE_ANALYTICS_ID"].present?
|
||||||
end
|
opoo "HOMEBREW_ADDITIONAL_GOOGLE_ANALYTICS_ID is now a no-op so can be unset."
|
||||||
|
puts "All Homebrew Google Analytics code and data was destroyed."
|
||||||
|
end
|
||||||
|
|
||||||
begin
|
if ENV["HOMEBREW_NO_GOOGLE_ANALYTICS"].present?
|
||||||
reporter = Reporter.new(tap)
|
opoo "HOMEBREW_NO_GOOGLE_ANALYTICS is now a no-op so can be unset."
|
||||||
rescue Reporter::ReporterRevisionUnsetError => e
|
puts "All Homebrew Google Analytics code and data was destroyed."
|
||||||
onoe "#{e.message}\n#{Utils::Backtrace.clean(e)&.join("\n")}" if Homebrew::EnvConfig.developer?
|
end
|
||||||
next
|
|
||||||
end
|
|
||||||
if reporter.updated?
|
|
||||||
updated_taps << tap.name
|
|
||||||
hub.add(reporter, auto_update: args.auto_update?)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# If we're installing from the API: we cannot use Git to check for #
|
unless args.quiet?
|
||||||
# differences in packages so instead use {formula,cask}_names.txt to do so.
|
analytics_message
|
||||||
# The first time this runs: we won't yet have a base state
|
donation_message
|
||||||
# ({formula,cask}_names.before.txt) to compare against so we don't output a
|
install_from_api_message
|
||||||
# anything and just copy the files for next time.
|
end
|
||||||
unless Homebrew::EnvConfig.no_install_from_api?
|
|
||||||
api_cache = Homebrew::API::HOMEBREW_CACHE_API
|
|
||||||
core_tap = CoreTap.instance
|
|
||||||
cask_tap = CoreCaskTap.instance
|
|
||||||
[
|
|
||||||
[:formula, core_tap, core_tap.formula_dir],
|
|
||||||
[:cask, cask_tap, cask_tap.cask_dir],
|
|
||||||
].each do |type, tap, dir|
|
|
||||||
names_txt = api_cache/"#{type}_names.txt"
|
|
||||||
next unless names_txt.exist?
|
|
||||||
|
|
||||||
names_before_txt = api_cache/"#{type}_names.before.txt"
|
tap_or_untap_core_taps_if_necessary
|
||||||
if names_before_txt.exist?
|
|
||||||
reporter = Reporter.new(
|
updated = false
|
||||||
tap,
|
new_tag = nil
|
||||||
api_names_txt: names_txt,
|
|
||||||
api_names_before_txt: names_before_txt,
|
initial_revision = ENV["HOMEBREW_UPDATE_BEFORE"].to_s
|
||||||
api_dir_prefix: dir,
|
current_revision = ENV["HOMEBREW_UPDATE_AFTER"].to_s
|
||||||
)
|
odie "update-report should not be called directly!" if initial_revision.empty? || current_revision.empty?
|
||||||
|
|
||||||
|
if initial_revision != current_revision
|
||||||
|
auto_update_header
|
||||||
|
|
||||||
|
updated = true
|
||||||
|
|
||||||
|
old_tag = Settings.read "latesttag"
|
||||||
|
|
||||||
|
new_tag = Utils.popen_read(
|
||||||
|
"git", "-C", HOMEBREW_REPOSITORY, "tag", "--list", "--sort=-version:refname", "*.*"
|
||||||
|
).lines.first.chomp
|
||||||
|
|
||||||
|
Settings.write "latesttag", new_tag if new_tag != old_tag
|
||||||
|
|
||||||
|
if new_tag == old_tag
|
||||||
|
ohai "Updated Homebrew from #{shorten_revision(initial_revision)} " \
|
||||||
|
"to #{shorten_revision(current_revision)}."
|
||||||
|
elsif old_tag.blank?
|
||||||
|
ohai "Updated Homebrew from #{shorten_revision(initial_revision)} " \
|
||||||
|
"to #{new_tag} (#{shorten_revision(current_revision)})."
|
||||||
|
else
|
||||||
|
ohai "Updated Homebrew from #{old_tag} (#{shorten_revision(initial_revision)}) " \
|
||||||
|
"to #{new_tag} (#{shorten_revision(current_revision)})."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Check if we can parse the JSON and do any Ruby-side follow-up.
|
||||||
|
unless Homebrew::EnvConfig.no_install_from_api?
|
||||||
|
Homebrew::API::Formula.write_names_and_aliases
|
||||||
|
Homebrew::API::Cask.write_names
|
||||||
|
end
|
||||||
|
|
||||||
|
Homebrew.failed = true if ENV["HOMEBREW_UPDATE_FAILED"]
|
||||||
|
return if Homebrew::EnvConfig.disable_load_formula?
|
||||||
|
|
||||||
|
migrate_gcc_dependents_if_needed
|
||||||
|
|
||||||
|
hub = ReporterHub.new
|
||||||
|
|
||||||
|
updated_taps = []
|
||||||
|
Tap.installed.each do |tap|
|
||||||
|
next if !tap.git? || tap.git_repo.origin_url.nil?
|
||||||
|
next if (tap.core_tap? || tap.core_cask_tap?) && !Homebrew::EnvConfig.no_install_from_api?
|
||||||
|
|
||||||
|
if ENV["HOMEBREW_MIGRATE_LINUXBREW_FORMULAE"].present? && tap.core_tap? &&
|
||||||
|
Settings.read("linuxbrewmigrated") != "true"
|
||||||
|
ohai "Migrating formulae from linuxbrew-core to homebrew-core"
|
||||||
|
|
||||||
|
LINUXBREW_CORE_MIGRATION_LIST.each do |name|
|
||||||
|
begin
|
||||||
|
formula = Formula[name]
|
||||||
|
rescue FormulaUnavailableError
|
||||||
|
next
|
||||||
|
end
|
||||||
|
next unless formula.any_version_installed?
|
||||||
|
|
||||||
|
keg = formula.installed_kegs.last
|
||||||
|
tab = Tab.for_keg(keg)
|
||||||
|
# force a `brew upgrade` from the linuxbrew-core version to the homebrew-core version (even if lower)
|
||||||
|
tab.source["versions"]["version_scheme"] = -1
|
||||||
|
tab.write
|
||||||
|
end
|
||||||
|
|
||||||
|
Settings.write "linuxbrewmigrated", true
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
reporter = Reporter.new(tap)
|
||||||
|
rescue Reporter::ReporterRevisionUnsetError => e
|
||||||
|
onoe "#{e.message}\n#{Utils::Backtrace.clean(e)&.join("\n")}" if Homebrew::EnvConfig.developer?
|
||||||
|
next
|
||||||
|
end
|
||||||
if reporter.updated?
|
if reporter.updated?
|
||||||
updated_taps << tap.name
|
updated_taps << tap.name
|
||||||
hub.add(reporter, auto_update: args.auto_update?)
|
hub.add(reporter, auto_update: args.auto_update?)
|
||||||
end
|
end
|
||||||
else
|
|
||||||
FileUtils.cp names_txt, names_before_txt
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
unless updated_taps.empty?
|
|
||||||
auto_update_header(args:)
|
|
||||||
puts "Updated #{Utils.pluralize("tap", updated_taps.count, include_count: true)} (#{updated_taps.to_sentence})."
|
|
||||||
updated = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if updated
|
|
||||||
if hub.empty?
|
|
||||||
puts no_changes_message unless args.quiet?
|
|
||||||
else
|
|
||||||
if ENV.fetch("HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED", false)
|
|
||||||
opoo "HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED is now the default behaviour, " \
|
|
||||||
"so you can unset it from your environment."
|
|
||||||
end
|
end
|
||||||
|
|
||||||
hub.dump(auto_update: args.auto_update?) unless args.quiet?
|
# If we're installing from the API: we cannot use Git to check for #
|
||||||
hub.reporters.each(&:migrate_tap_migration)
|
# differences in packages so instead use {formula,cask}_names.txt to do so.
|
||||||
hub.reporters.each(&:migrate_cask_rename)
|
# The first time this runs: we won't yet have a base state
|
||||||
hub.reporters.each { |r| r.migrate_formula_rename(force: args.force?, verbose: args.verbose?) }
|
# ({formula,cask}_names.before.txt) to compare against so we don't output a
|
||||||
|
# anything and just copy the files for next time.
|
||||||
|
unless Homebrew::EnvConfig.no_install_from_api?
|
||||||
|
api_cache = Homebrew::API::HOMEBREW_CACHE_API
|
||||||
|
core_tap = CoreTap.instance
|
||||||
|
cask_tap = CoreCaskTap.instance
|
||||||
|
[
|
||||||
|
[:formula, core_tap, core_tap.formula_dir],
|
||||||
|
[:cask, cask_tap, cask_tap.cask_dir],
|
||||||
|
].each do |type, tap, dir|
|
||||||
|
names_txt = api_cache/"#{type}_names.txt"
|
||||||
|
next unless names_txt.exist?
|
||||||
|
|
||||||
CacheStoreDatabase.use(:descriptions) do |db|
|
names_before_txt = api_cache/"#{type}_names.before.txt"
|
||||||
DescriptionCacheStore.new(db)
|
if names_before_txt.exist?
|
||||||
.update_from_report!(hub)
|
reporter = Reporter.new(
|
||||||
end
|
tap,
|
||||||
CacheStoreDatabase.use(:cask_descriptions) do |db|
|
api_names_txt: names_txt,
|
||||||
CaskDescriptionCacheStore.new(db)
|
api_names_before_txt: names_before_txt,
|
||||||
.update_from_report!(hub)
|
api_dir_prefix: dir,
|
||||||
end
|
)
|
||||||
end
|
if reporter.updated?
|
||||||
puts if args.auto_update?
|
updated_taps << tap.name
|
||||||
elsif !args.auto_update? && !ENV["HOMEBREW_UPDATE_FAILED"] && !ENV["HOMEBREW_MIGRATE_LINUXBREW_FORMULAE"]
|
hub.add(reporter, auto_update: args.auto_update?)
|
||||||
puts "Already up-to-date." unless args.quiet?
|
end
|
||||||
end
|
else
|
||||||
|
FileUtils.cp names_txt, names_before_txt
|
||||||
Commands.rebuild_commands_completion_list
|
end
|
||||||
link_completions_manpages_and_docs
|
end
|
||||||
Tap.installed.each(&:link_completions_and_manpages)
|
end
|
||||||
|
|
||||||
failed_fetch_dirs = ENV["HOMEBREW_MISSING_REMOTE_REF_DIRS"]&.split("\n")
|
unless updated_taps.empty?
|
||||||
if failed_fetch_dirs.present?
|
auto_update_header
|
||||||
failed_fetch_taps = failed_fetch_dirs.map { |dir| Tap.from_path(dir) }
|
puts "Updated #{Utils.pluralize("tap", updated_taps.count,
|
||||||
|
include_count: true)} (#{updated_taps.to_sentence})."
|
||||||
ofail <<~EOS
|
updated = true
|
||||||
Some taps failed to update!
|
end
|
||||||
The following taps can not read their remote branches:
|
|
||||||
#{failed_fetch_taps.join("\n ")}
|
if updated
|
||||||
This is happening because the remote branch was renamed or deleted.
|
if hub.empty?
|
||||||
Reset taps to point to the correct remote branches by running `brew tap --repair`
|
puts no_changes_message unless args.quiet?
|
||||||
EOS
|
else
|
||||||
end
|
if ENV.fetch("HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED", false)
|
||||||
|
opoo "HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED is now the default behaviour, " \
|
||||||
return if new_tag.blank? || new_tag == old_tag || args.quiet?
|
"so you can unset it from your environment."
|
||||||
|
end
|
||||||
puts
|
|
||||||
|
hub.dump(auto_update: args.auto_update?) unless args.quiet?
|
||||||
new_major_version, new_minor_version, new_patch_version = new_tag.split(".").map(&:to_i)
|
hub.reporters.each(&:migrate_tap_migration)
|
||||||
old_major_version, old_minor_version = (old_tag.split(".")[0, 2]).map(&:to_i) if old_tag.present?
|
hub.reporters.each(&:migrate_cask_rename)
|
||||||
if old_tag.blank? || new_major_version > old_major_version || new_minor_version > old_minor_version
|
hub.reporters.each { |r| r.migrate_formula_rename(force: args.force?, verbose: args.verbose?) }
|
||||||
puts <<~EOS
|
|
||||||
The #{new_major_version}.#{new_minor_version}.0 release notes are available on the Homebrew Blog:
|
CacheStoreDatabase.use(:descriptions) do |db|
|
||||||
#{Formatter.url("https://brew.sh/blog/#{new_major_version}.#{new_minor_version}.0")}
|
DescriptionCacheStore.new(db)
|
||||||
EOS
|
.update_from_report!(hub)
|
||||||
end
|
end
|
||||||
|
CacheStoreDatabase.use(:cask_descriptions) do |db|
|
||||||
return if new_patch_version.zero?
|
CaskDescriptionCacheStore.new(db)
|
||||||
|
.update_from_report!(hub)
|
||||||
puts <<~EOS
|
end
|
||||||
The #{new_tag} changelog can be found at:
|
end
|
||||||
#{Formatter.url("https://github.com/Homebrew/brew/releases/tag/#{new_tag}")}
|
puts if args.auto_update?
|
||||||
EOS
|
elsif !args.auto_update? && !ENV["HOMEBREW_UPDATE_FAILED"] && !ENV["HOMEBREW_MIGRATE_LINUXBREW_FORMULAE"]
|
||||||
end
|
puts "Already up-to-date." unless args.quiet?
|
||||||
|
end
|
||||||
def no_changes_message
|
|
||||||
"No changes to formulae or casks."
|
Commands.rebuild_commands_completion_list
|
||||||
end
|
link_completions_manpages_and_docs
|
||||||
|
Tap.installed.each(&:link_completions_and_manpages)
|
||||||
def shorten_revision(revision)
|
|
||||||
Utils.popen_read("git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--short", revision).chomp
|
failed_fetch_dirs = ENV["HOMEBREW_MISSING_REMOTE_REF_DIRS"]&.split("\n")
|
||||||
end
|
if failed_fetch_dirs.present?
|
||||||
|
failed_fetch_taps = failed_fetch_dirs.map { |dir| Tap.from_path(dir) }
|
||||||
def tap_or_untap_core_taps_if_necessary
|
|
||||||
return if ENV["HOMEBREW_UPDATE_TEST"]
|
ofail <<~EOS
|
||||||
|
Some taps failed to update!
|
||||||
if Homebrew::EnvConfig.no_install_from_api?
|
The following taps can not read their remote branches:
|
||||||
return if Homebrew::EnvConfig.automatically_set_no_install_from_api?
|
#{failed_fetch_taps.join("\n ")}
|
||||||
|
This is happening because the remote branch was renamed or deleted.
|
||||||
core_tap = CoreTap.instance
|
Reset taps to point to the correct remote branches by running `brew tap --repair`
|
||||||
return if core_tap.installed?
|
EOS
|
||||||
|
end
|
||||||
core_tap.ensure_installed!
|
|
||||||
revision = CoreTap.instance.git_head
|
return if new_tag.blank? || new_tag == old_tag || args.quiet?
|
||||||
ENV["HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_CORE"] = revision
|
|
||||||
ENV["HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_CORE"] = revision
|
puts
|
||||||
else
|
|
||||||
return if Homebrew::EnvConfig.developer? || ENV["HOMEBREW_DEV_CMD_RUN"]
|
new_major_version, new_minor_version, new_patch_version = new_tag.split(".").map(&:to_i)
|
||||||
return if ENV["HOMEBREW_GITHUB_HOSTED_RUNNER"] || ENV["GITHUB_ACTIONS_HOMEBREW_SELF_HOSTED"]
|
old_major_version, old_minor_version = (old_tag.split(".")[0, 2]).map(&:to_i) if old_tag.present?
|
||||||
return if (HOMEBREW_PREFIX/".homebrewdocker").exist?
|
if old_tag.blank? || new_major_version > old_major_version || new_minor_version > old_minor_version
|
||||||
|
puts <<~EOS
|
||||||
tap_output_header_printed = T.let(false, T::Boolean)
|
The #{new_major_version}.#{new_minor_version}.0 release notes are available on the Homebrew Blog:
|
||||||
[CoreTap.instance, CoreCaskTap.instance].each do |tap|
|
#{Formatter.url("https://brew.sh/blog/#{new_major_version}.#{new_minor_version}.0")}
|
||||||
next unless tap.installed?
|
EOS
|
||||||
|
end
|
||||||
if tap.git_branch == "master" &&
|
|
||||||
(Date.parse(T.must(tap.git_repo.last_commit_date)) <= Date.today.prev_month)
|
return if new_patch_version.zero?
|
||||||
ohai "#{tap.name} is old and unneeded, untapping to save space..."
|
|
||||||
tap.uninstall
|
puts <<~EOS
|
||||||
else
|
The #{new_tag} changelog can be found at:
|
||||||
unless tap_output_header_printed
|
#{Formatter.url("https://github.com/Homebrew/brew/releases/tag/#{new_tag}")}
|
||||||
puts "Installing from the API is now the default behaviour!"
|
EOS
|
||||||
puts "You can save space and time by running:"
|
end
|
||||||
tap_output_header_printed = true
|
|
||||||
|
def no_changes_message
|
||||||
|
"No changes to formulae or casks."
|
||||||
|
end
|
||||||
|
|
||||||
|
def shorten_revision(revision)
|
||||||
|
Utils.popen_read("git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--short", revision).chomp
|
||||||
|
end
|
||||||
|
|
||||||
|
def tap_or_untap_core_taps_if_necessary
|
||||||
|
return if ENV["HOMEBREW_UPDATE_TEST"]
|
||||||
|
|
||||||
|
if Homebrew::EnvConfig.no_install_from_api?
|
||||||
|
return if Homebrew::EnvConfig.automatically_set_no_install_from_api?
|
||||||
|
|
||||||
|
core_tap = CoreTap.instance
|
||||||
|
return if core_tap.installed?
|
||||||
|
|
||||||
|
core_tap.ensure_installed!
|
||||||
|
revision = CoreTap.instance.git_head
|
||||||
|
ENV["HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_CORE"] = revision
|
||||||
|
ENV["HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_CORE"] = revision
|
||||||
|
else
|
||||||
|
return if Homebrew::EnvConfig.developer? || ENV["HOMEBREW_DEV_CMD_RUN"]
|
||||||
|
return if ENV["HOMEBREW_GITHUB_HOSTED_RUNNER"] || ENV["GITHUB_ACTIONS_HOMEBREW_SELF_HOSTED"]
|
||||||
|
return if (HOMEBREW_PREFIX/".homebrewdocker").exist?
|
||||||
|
|
||||||
|
tap_output_header_printed = T.let(false, T::Boolean)
|
||||||
|
[CoreTap.instance, CoreCaskTap.instance].each do |tap|
|
||||||
|
next unless tap.installed?
|
||||||
|
|
||||||
|
if tap.git_branch == "master" &&
|
||||||
|
(Date.parse(T.must(tap.git_repo.last_commit_date)) <= Date.today.prev_month)
|
||||||
|
ohai "#{tap.name} is old and unneeded, untapping to save space..."
|
||||||
|
tap.uninstall
|
||||||
|
else
|
||||||
|
unless tap_output_header_printed
|
||||||
|
puts "Installing from the API is now the default behaviour!"
|
||||||
|
puts "You can save space and time by running:"
|
||||||
|
tap_output_header_printed = true
|
||||||
|
end
|
||||||
|
puts " brew untap #{tap.name}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
puts " brew untap #{tap.name}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def link_completions_manpages_and_docs(repository = HOMEBREW_REPOSITORY)
|
||||||
|
command = "brew update"
|
||||||
|
Utils::Link.link_completions(repository, command)
|
||||||
|
Utils::Link.link_manpages(repository, command)
|
||||||
|
Utils::Link.link_docs(repository, command)
|
||||||
|
rescue => e
|
||||||
|
ofail <<~EOS
|
||||||
|
Failed to link all completions, docs and manpages:
|
||||||
|
#{e}
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
def migrate_gcc_dependents_if_needed
|
||||||
|
# do nothing
|
||||||
|
end
|
||||||
|
|
||||||
|
def analytics_message
|
||||||
|
return if Utils::Analytics.messages_displayed?
|
||||||
|
return if Utils::Analytics.no_message_output?
|
||||||
|
|
||||||
|
if Utils::Analytics.disabled? && !Utils::Analytics.influx_message_displayed?
|
||||||
|
ohai "Homebrew's analytics have entirely moved to our InfluxDB instance in the EU."
|
||||||
|
puts "We gather less data than before and have destroyed all Google Analytics data:"
|
||||||
|
puts " #{Formatter.url("https://docs.brew.sh/Analytics")}#{Tty.reset}"
|
||||||
|
puts "Please reconsider re-enabling analytics to help our volunteer maintainers with:"
|
||||||
|
puts " brew analytics on"
|
||||||
|
elsif !Utils::Analytics.disabled?
|
||||||
|
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"
|
||||||
|
# Use the shell's audible bell.
|
||||||
|
print "\a"
|
||||||
|
|
||||||
|
# Use an extra newline and bold to avoid this being missed.
|
||||||
|
ohai "Homebrew collects anonymous analytics."
|
||||||
|
puts <<~EOS
|
||||||
|
#{Tty.bold}Read the analytics documentation (and how to opt-out) here:
|
||||||
|
#{Formatter.url("https://docs.brew.sh/Analytics")}#{Tty.reset}
|
||||||
|
No analytics have been recorded yet (nor will be during this `brew` run).
|
||||||
|
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
# Consider the messages possibly missed if not a TTY.
|
||||||
|
Utils::Analytics.messages_displayed! if $stdout.tty?
|
||||||
|
end
|
||||||
|
|
||||||
|
def donation_message
|
||||||
|
return if Settings.read("donationmessage") == "true"
|
||||||
|
|
||||||
|
ohai "Homebrew is run entirely by unpaid volunteers. Please consider donating:"
|
||||||
|
puts " #{Formatter.url("https://github.com/Homebrew/brew#donations")}\n\n"
|
||||||
|
|
||||||
|
# Consider the message possibly missed if not a TTY.
|
||||||
|
Settings.write "donationmessage", true if $stdout.tty?
|
||||||
|
end
|
||||||
|
|
||||||
|
def install_from_api_message
|
||||||
|
return if Settings.read("installfromapimessage") == "true"
|
||||||
|
|
||||||
|
no_install_from_api_set = Homebrew::EnvConfig.no_install_from_api? &&
|
||||||
|
!Homebrew::EnvConfig.automatically_set_no_install_from_api?
|
||||||
|
return unless no_install_from_api_set
|
||||||
|
|
||||||
|
ohai "You have HOMEBREW_NO_INSTALL_FROM_API set"
|
||||||
|
puts "Homebrew >=4.1.0 is dramatically faster and less error-prone when installing"
|
||||||
|
puts "from the JSON API. Please consider unsetting HOMEBREW_NO_INSTALL_FROM_API."
|
||||||
|
puts "This message will only be printed once."
|
||||||
|
puts "\n\n"
|
||||||
|
|
||||||
|
# Consider the message possibly missed if not a TTY.
|
||||||
|
Settings.write "installfromapimessage", true if $stdout.tty?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_completions_manpages_and_docs(repository = HOMEBREW_REPOSITORY)
|
|
||||||
command = "brew update"
|
|
||||||
Utils::Link.link_completions(repository, command)
|
|
||||||
Utils::Link.link_manpages(repository, command)
|
|
||||||
Utils::Link.link_docs(repository, command)
|
|
||||||
rescue => e
|
|
||||||
ofail <<~EOS
|
|
||||||
Failed to link all completions, docs and manpages:
|
|
||||||
#{e}
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
|
|
||||||
def migrate_gcc_dependents_if_needed
|
|
||||||
# do nothing
|
|
||||||
end
|
|
||||||
|
|
||||||
def analytics_message
|
|
||||||
return if Utils::Analytics.messages_displayed?
|
|
||||||
return if Utils::Analytics.no_message_output?
|
|
||||||
|
|
||||||
if Utils::Analytics.disabled? && !Utils::Analytics.influx_message_displayed?
|
|
||||||
ohai "Homebrew's analytics have entirely moved to our InfluxDB instance in the EU."
|
|
||||||
puts "We gather less data than before and have destroyed all Google Analytics data:"
|
|
||||||
puts " #{Formatter.url("https://docs.brew.sh/Analytics")}#{Tty.reset}"
|
|
||||||
puts "Please reconsider re-enabling analytics to help our volunteer maintainers with:"
|
|
||||||
puts " brew analytics on"
|
|
||||||
elsif !Utils::Analytics.disabled?
|
|
||||||
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"
|
|
||||||
# Use the shell's audible bell.
|
|
||||||
print "\a"
|
|
||||||
|
|
||||||
# Use an extra newline and bold to avoid this being missed.
|
|
||||||
ohai "Homebrew collects anonymous analytics."
|
|
||||||
puts <<~EOS
|
|
||||||
#{Tty.bold}Read the analytics documentation (and how to opt-out) here:
|
|
||||||
#{Formatter.url("https://docs.brew.sh/Analytics")}#{Tty.reset}
|
|
||||||
No analytics have been recorded yet (nor will be during this `brew` run).
|
|
||||||
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
|
|
||||||
# Consider the messages possibly missed if not a TTY.
|
|
||||||
Utils::Analytics.messages_displayed! if $stdout.tty?
|
|
||||||
end
|
|
||||||
|
|
||||||
def donation_message
|
|
||||||
return if Settings.read("donationmessage") == "true"
|
|
||||||
|
|
||||||
ohai "Homebrew is run entirely by unpaid volunteers. Please consider donating:"
|
|
||||||
puts " #{Formatter.url("https://github.com/Homebrew/brew#donations")}\n\n"
|
|
||||||
|
|
||||||
# Consider the message possibly missed if not a TTY.
|
|
||||||
Settings.write "donationmessage", true if $stdout.tty?
|
|
||||||
end
|
|
||||||
|
|
||||||
def install_from_api_message
|
|
||||||
return if Settings.read("installfromapimessage") == "true"
|
|
||||||
|
|
||||||
no_install_from_api_set = Homebrew::EnvConfig.no_install_from_api? &&
|
|
||||||
!Homebrew::EnvConfig.automatically_set_no_install_from_api?
|
|
||||||
return unless no_install_from_api_set
|
|
||||||
|
|
||||||
ohai "You have HOMEBREW_NO_INSTALL_FROM_API set"
|
|
||||||
puts "Homebrew >=4.1.0 is dramatically faster and less error-prone when installing"
|
|
||||||
puts "from the JSON API. Please consider unsetting HOMEBREW_NO_INSTALL_FROM_API."
|
|
||||||
puts "This message will only be printed once."
|
|
||||||
puts "\n\n"
|
|
||||||
|
|
||||||
# Consider the message possibly missed if not a TTY.
|
|
||||||
Settings.write "installfromapimessage", true if $stdout.tty?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require "extend/os/cmd/update-report"
|
require "extend/os/cmd/update-report"
|
||||||
|
|||||||
@ -5,7 +5,7 @@ require "formula_versions"
|
|||||||
require "yaml"
|
require "yaml"
|
||||||
require "cmd/shared_examples/args_parse"
|
require "cmd/shared_examples/args_parse"
|
||||||
|
|
||||||
RSpec.describe "brew update-report" do
|
RSpec.describe Homebrew::Cmd::UpdateReport do
|
||||||
it_behaves_like "parseable arguments"
|
it_behaves_like "parseable arguments"
|
||||||
|
|
||||||
describe Reporter do
|
describe Reporter do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user