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
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 = []

View File

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

View File

@ -19,6 +19,8 @@ module Homebrew
switch "-f", "--force",
description: "Treat installed <formula> and provided <formula> as if they are from "\
"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
end
@ -35,8 +37,7 @@ module Homebrew
odie "#{rack} is a symlink" if rack.symlink?
end
migrator = Migrator.new(f, force: args.force?)
migrator.migrate
Migrator.migrate_if_needed(f, force: args.force?, dry_run: args.dry_run?)
end
end
end

View File

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

View File

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

View File

@ -17,6 +17,7 @@ module Homebrew
def upgrade_formulae(
formulae_to_install,
flags:,
dry_run: false,
installed_on_request: false,
force_bottle: false,
build_from_source_formulae: [],
@ -42,7 +43,7 @@ module Homebrew
end
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
fi = create_and_fetch_formula_installer(
formula,
@ -57,7 +58,7 @@ module Homebrew
quiet: quiet,
verbose: verbose,
)
fi.fetch
fi.fetch unless dry_run
fi
rescue UnsatisfiedRequirements, DownloadError => e
ofail "#{formula}: #{e}"
@ -66,8 +67,8 @@ module Homebrew
end.compact
formula_installers.each do |fi|
upgrade_formula(fi, verbose: verbose)
Cleanup.install_formula_clean!(fi.formula)
upgrade_formula(fi, dry_run: dry_run, verbose: verbose)
Cleanup.install_formula_clean!(fi.formula, dry_run: dry_run)
end
end
@ -77,6 +78,22 @@ module Homebrew
.map { |k| Keg.new(k.resolved_path) }
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)
version_upgrade = if formula.optlinked?
"#{Keg.new(formula.opt_prefix).version} -> #{formula.pkg_version}"
@ -139,13 +156,18 @@ module Homebrew
end
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
kegs = outdated_kegs(formula)
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

View File

@ -1419,6 +1419,7 @@ _brew_migrate() {
-*)
__brewcomp "
--debug
--dry-run
--force
--help
--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_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 help -d 'Show this message'
__fish_brew_complete_arg 'migrate' -l quiet -d 'Make some output more quiet'

View File

@ -1221,6 +1221,7 @@ _brew_man() {
_brew_migrate() {
_arguments \
'--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]' \
'--help[Show this message]' \
'--quiet[Make some output more quiet]' \

View File

@ -417,13 +417,15 @@ if no formula is provided.
* `-n`, `--max-count`:
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
packages.
* `-f`, `--force`:
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`* ...]

View File

@ -578,13 +578,17 @@ Print only one commit\.
\fB\-n\fR, \fB\-\-max\-count\fR
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\.
.
.TP
\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\.
.
.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 \.\.\.]"
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\.
.