Merge pull request #11947 from EricFromCanada/upgrade-dry-run

upgrade: list upgradeable dependencies on dry run
This commit is contained in:
Mike McQuaid 2021-09-01 11:24:22 +01:00 committed by GitHub
commit ffb4e5f519
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 70 additions and 31 deletions

View File

@ -133,7 +133,7 @@ module Cask
end end
verb = dry_run ? "Would upgrade" : "Upgrading" verb = dry_run ? "Would upgrade" : "Upgrading"
oh1 "#{verb} #{outdated_casks.count} #{"outdated package".pluralize(outdated_casks.count)}:" oh1 "#{verb} #{outdated_casks.count} outdated #{"package".pluralize(outdated_casks.count)}:"
caught_exceptions = [] caught_exceptions = []

View File

@ -154,10 +154,10 @@ module Homebrew
@cleaned_up_paths = Set.new @cleaned_up_paths = Set.new
end end
def self.install_formula_clean!(f) def self.install_formula_clean!(f, dry_run: false)
return if Homebrew::EnvConfig.no_install_cleanup? return if Homebrew::EnvConfig.no_install_cleanup?
cleanup = Cleanup.new cleanup = Cleanup.new(dry_run: dry_run)
if cleanup.periodic_clean_due? if cleanup.periodic_clean_due?
cleanup.periodic_clean! cleanup.periodic_clean!
elsif f.latest_version_installed? && !cleanup.skip_clean_formula?(f) elsif f.latest_version_installed? && !cleanup.skip_clean_formula?(f)
@ -187,8 +187,12 @@ module Homebrew
def periodic_clean! def periodic_clean!
return false unless periodic_clean_due? return false unless periodic_clean_due?
ohai "`brew cleanup` has not been run in #{CLEANUP_DEFAULT_DAYS} days, running now..." if dry_run?
clean!(quiet: true, periodic: true) ohai "Would run `brew cleanup` which has not been run in the last #{CLEANUP_DEFAULT_DAYS} days"
else
ohai "`brew cleanup` has not been run in the last #{CLEANUP_DEFAULT_DAYS} days, running now..."
clean!(quiet: true, periodic: true)
end
end end
def clean!(quiet: false, periodic: false) def clean!(quiet: false, periodic: false)

View File

@ -19,6 +19,8 @@ module Homebrew
switch "-f", "--force", switch "-f", "--force",
description: "Treat installed <formula> and provided <formula> as if they are from "\ description: "Treat installed <formula> and provided <formula> as if they are from "\
"the same taps and migrate them anyway." "the same taps and migrate them anyway."
switch "-n", "--dry-run",
description: "Show what would be migrated, but do not actually migrate anything."
named_args :installed_formula, min: 1 named_args :installed_formula, min: 1
end end
@ -35,8 +37,7 @@ module Homebrew
odie "#{rack} is a symlink" if rack.symlink? odie "#{rack} is a symlink" if rack.symlink?
end end
migrator = Migrator.new(f, force: args.force?) Migrator.migrate_if_needed(f, force: args.force?, dry_run: args.dry_run?)
migrator.migrate
end end
end end
end end

View File

@ -187,21 +187,20 @@ module Homebrew
puts formulae_upgrades.join("\n") puts formulae_upgrades.join("\n")
end end
unless args.dry_run? Upgrade.upgrade_formulae(
Upgrade.upgrade_formulae( formulae_to_install,
formulae_to_install, flags: args.flags_only,
flags: args.flags_only, dry_run: args.dry_run?,
installed_on_request: args.named.present?, installed_on_request: args.named.present?,
force_bottle: args.force_bottle?, force_bottle: args.force_bottle?,
build_from_source_formulae: args.build_from_source_formulae, build_from_source_formulae: args.build_from_source_formulae,
interactive: args.interactive?, interactive: args.interactive?,
keep_tmp: args.keep_tmp?, keep_tmp: args.keep_tmp?,
force: args.force?, force: args.force?,
debug: args.debug?, debug: args.debug?,
quiet: args.quiet?, quiet: args.quiet?,
verbose: args.verbose?, verbose: args.verbose?,
) )
end
Upgrade.check_installed_dependents( Upgrade.check_installed_dependents(
formulae_to_install, formulae_to_install,

View File

@ -110,10 +110,14 @@ class Migrator
true true
end end
def self.migrate_if_needed(formula, force:) def self.migrate_if_needed(formula, force:, dry_run: false)
return unless Migrator.needs_migration?(formula) return unless Migrator.needs_migration?(formula)
begin begin
if dry_run
ohai "Would migrate #{formula.oldname} to #{formula.name}"
return
end
migrator = Migrator.new(formula, force: force) migrator = Migrator.new(formula, force: force)
migrator.migrate migrator.migrate
rescue => e rescue => e

View File

@ -17,6 +17,7 @@ module Homebrew
def upgrade_formulae( def upgrade_formulae(
formulae_to_install, formulae_to_install,
flags:, flags:,
dry_run: false,
installed_on_request: false, installed_on_request: false,
force_bottle: false, force_bottle: false,
build_from_source_formulae: [], build_from_source_formulae: [],
@ -42,7 +43,7 @@ module Homebrew
end end
formula_installers = formulae_to_install.map do |formula| formula_installers = formulae_to_install.map do |formula|
Migrator.migrate_if_needed(formula, force: force) Migrator.migrate_if_needed(formula, force: force, dry_run: dry_run)
begin begin
fi = create_and_fetch_formula_installer( fi = create_and_fetch_formula_installer(
formula, formula,
@ -57,7 +58,7 @@ module Homebrew
quiet: quiet, quiet: quiet,
verbose: verbose, verbose: verbose,
) )
fi.fetch fi.fetch unless dry_run
fi fi
rescue UnsatisfiedRequirements, DownloadError => e rescue UnsatisfiedRequirements, DownloadError => e
ofail "#{formula}: #{e}" ofail "#{formula}: #{e}"
@ -66,8 +67,8 @@ module Homebrew
end.compact end.compact
formula_installers.each do |fi| formula_installers.each do |fi|
upgrade_formula(fi, verbose: verbose) upgrade_formula(fi, dry_run: dry_run, verbose: verbose)
Cleanup.install_formula_clean!(fi.formula) Cleanup.install_formula_clean!(fi.formula, dry_run: dry_run)
end end
end end
@ -77,6 +78,22 @@ module Homebrew
.map { |k| Keg.new(k.resolved_path) } .map { |k| Keg.new(k.resolved_path) }
end end
def print_dry_run_dependencies(formula, fi_deps)
return if fi_deps.empty?
plural = "dependency".pluralize(fi_deps.count)
ohai "Would upgrade #{fi_deps.count} #{plural} for #{formula.full_specified_name}:"
formulae_upgrades = fi_deps.map(&:first).map(&:to_formula).map do |f|
name = f.full_specified_name
if f.optlinked?
"#{name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}"
else
"#{name} #{f.pkg_version}"
end
end
puts formulae_upgrades.join(", ")
end
def print_upgrade_message(formula, fi_options) def print_upgrade_message(formula, fi_options)
version_upgrade = if formula.optlinked? version_upgrade = if formula.optlinked?
"#{Keg.new(formula.opt_prefix).version} -> #{formula.pkg_version}" "#{Keg.new(formula.opt_prefix).version} -> #{formula.pkg_version}"
@ -139,13 +156,18 @@ module Homebrew
end end
private_class_method :create_and_fetch_formula_installer private_class_method :create_and_fetch_formula_installer
def upgrade_formula(formula_installer, verbose: false) def upgrade_formula(formula_installer, dry_run: false, verbose: false)
formula = formula_installer.formula formula = formula_installer.formula
kegs = outdated_kegs(formula) kegs = outdated_kegs(formula)
linked_kegs = kegs.select(&:linked?) linked_kegs = kegs.select(&:linked?)
print_upgrade_message(formula, formula_installer.options) if dry_run
print_dry_run_dependencies(formula, formula_installer.compute_dependencies)
return
else
print_upgrade_message(formula, formula_installer.options)
end
formula_installer.prelude formula_installer.prelude

View File

@ -1419,6 +1419,7 @@ _brew_migrate() {
-*) -*)
__brewcomp " __brewcomp "
--debug --debug
--dry-run
--force --force
--help --help
--quiet --quiet

View File

@ -997,6 +997,7 @@ __fish_brew_complete_arg 'man' -l verbose -d 'Make some output more verbose'
__fish_brew_complete_cmd 'migrate' 'Migrate renamed packages to new names, where formula are old names of packages' __fish_brew_complete_cmd 'migrate' 'Migrate renamed packages to new names, where formula are old names of packages'
__fish_brew_complete_arg 'migrate' -l debug -d 'Display any debugging information' __fish_brew_complete_arg 'migrate' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'migrate' -l dry-run -d 'Show what would be migrated, but do not actually migrate anything'
__fish_brew_complete_arg 'migrate' -l force -d 'Treat installed formula and provided formula as if they are from the same taps and migrate them anyway' __fish_brew_complete_arg 'migrate' -l force -d 'Treat installed formula and provided formula as if they are from the same taps and migrate them anyway'
__fish_brew_complete_arg 'migrate' -l help -d 'Show this message' __fish_brew_complete_arg 'migrate' -l help -d 'Show this message'
__fish_brew_complete_arg 'migrate' -l quiet -d 'Make some output more quiet' __fish_brew_complete_arg 'migrate' -l quiet -d 'Make some output more quiet'

View File

@ -1221,6 +1221,7 @@ _brew_man() {
_brew_migrate() { _brew_migrate() {
_arguments \ _arguments \
'--debug[Display any debugging information]' \ '--debug[Display any debugging information]' \
'--dry-run[Show what would be migrated, but do not actually migrate anything]' \
'--force[Treat installed formula and provided formula as if they are from the same taps and migrate them anyway]' \ '--force[Treat installed formula and provided formula as if they are from the same taps and migrate them anyway]' \
'--help[Show this message]' \ '--help[Show this message]' \
'--quiet[Make some output more quiet]' \ '--quiet[Make some output more quiet]' \

View File

@ -417,13 +417,15 @@ if no formula is provided.
* `-n`, `--max-count`: * `-n`, `--max-count`:
Print only a specified number of commits. Print only a specified number of commits.
### `migrate` [*`--force`*] *`installed_formula`* [...] ### `migrate` [*`--force`*] [*`--dry-run`*] *`installed_formula`* [...]
Migrate renamed packages to new names, where *`formula`* are old names of Migrate renamed packages to new names, where *`formula`* are old names of
packages. packages.
* `-f`, `--force`: * `-f`, `--force`:
Treat installed *`formula`* and provided *`formula`* as if they are from the same taps and migrate them anyway. Treat installed *`formula`* and provided *`formula`* as if they are from the same taps and migrate them anyway.
* `-n`, `--dry-run`:
Show what would be migrated, but do not actually migrate anything.
### `missing` [*`--hide`*`=`] [*`formula`* ...] ### `missing` [*`--hide`*`=`] [*`formula`* ...]

View File

@ -578,13 +578,17 @@ Print only one commit\.
\fB\-n\fR, \fB\-\-max\-count\fR \fB\-n\fR, \fB\-\-max\-count\fR
Print only a specified number of commits\. Print only a specified number of commits\.
. .
.SS "\fBmigrate\fR [\fI\-\-force\fR] \fIinstalled_formula\fR [\.\.\.]" .SS "\fBmigrate\fR [\fI\-\-force\fR] [\fI\-\-dry\-run\fR] \fIinstalled_formula\fR [\.\.\.]"
Migrate renamed packages to new names, where \fIformula\fR are old names of packages\. Migrate renamed packages to new names, where \fIformula\fR are old names of packages\.
. .
.TP .TP
\fB\-f\fR, \fB\-\-force\fR \fB\-f\fR, \fB\-\-force\fR
Treat installed \fIformula\fR and provided \fIformula\fR as if they are from the same taps and migrate them anyway\. Treat installed \fIformula\fR and provided \fIformula\fR as if they are from the same taps and migrate them anyway\.
. .
.TP
\fB\-n\fR, \fB\-\-dry\-run\fR
Show what would be migrated, but do not actually migrate anything\.
.
.SS "\fBmissing\fR [\fI\-\-hide\fR\fB=\fR] [\fIformula\fR \.\.\.]" .SS "\fBmissing\fR [\fI\-\-hide\fR\fB=\fR] [\fIformula\fR \.\.\.]"
Check the given \fIformula\fR kegs for missing dependencies\. If no \fIformula\fR are provided, check all kegs\. Will exit with a non\-zero status if any kegs are found to be missing dependencies\. Check the given \fIformula\fR kegs for missing dependencies\. If no \fIformula\fR are provided, check all kegs\. Will exit with a non\-zero status if any kegs are found to be missing dependencies\.
. .