From 93ebe42a72e33e40c2c4c355f0cbc3e996599730 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Mon, 15 Aug 2022 21:48:57 +0900 Subject: [PATCH 01/11] add dry-run option to cask#install --- Library/Homebrew/cask/cmd/install.rb | 4 +++- Library/Homebrew/cask/installer.rb | 9 +++++++-- Library/Homebrew/cmd/install.rb | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/cmd/install.rb b/Library/Homebrew/cask/cmd/install.rb index 69bd9d80fa..2d477f10e8 100644 --- a/Library/Homebrew/cask/cmd/install.rb +++ b/Library/Homebrew/cask/cmd/install.rb @@ -56,7 +56,8 @@ module Cask require_sha: nil, quarantine: nil, quiet: nil, - zap: nil + zap: nil, + dry_run: nil ) odie "Installing casks is supported only on macOS" unless OS.mac? @@ -69,6 +70,7 @@ module Cask quarantine: quarantine, quiet: quiet, zap: zap, + dry_run: dry_run, }.compact options[:quarantine] = true if options[:quarantine].nil? diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index c0417e311d..e13eb423e3 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -24,7 +24,7 @@ module Cask skip_cask_deps: false, binaries: true, verbose: false, zap: false, require_sha: false, upgrade: false, installed_as_dependency: false, quarantine: true, - verify_download_integrity: true, quiet: false) + verify_download_integrity: true, quiet: false, dry_run: false) @cask = cask @command = command @force = force @@ -39,11 +39,12 @@ module Cask @quarantine = quarantine @verify_download_integrity = verify_download_integrity @quiet = quiet + @dry_run = dry_run end attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?, :reinstall?, :upgrade?, :verbose?, :zap?, :installed_as_dependency?, - :quarantine?, :quiet? + :quarantine?, :quiet?, :dry_run? def self.caveats(cask) odebug "Printing caveats" @@ -96,6 +97,10 @@ module Cask check_conflicts print caveats + if dry_run? + puts "#{Formatter.identifier(@cask)} would be installed" + exit + end fetch uninstall_existing_cask if reinstall? diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index a312190440..2acb56baba 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -45,6 +45,8 @@ module Homebrew "(binaries and symlinks are excluded, unless originally from the same cask)." switch "-v", "--verbose", description: "Print the verification and postinstall steps." + switch "-n", "--dry-run", + description: "Show what would be installed, but do not actually install anything." [ [:switch, "--formula", "--formulae", { description: "Treat all named arguments as formulae.", @@ -193,6 +195,7 @@ module Homebrew skip_cask_deps: args.skip_cask_deps?, quarantine: args.quarantine?, quiet: args.quiet?, + dry_run: args.dry_run?, ) end From 634fcad1b230fabe3a6b6d094541b0151178867f Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Tue, 16 Aug 2022 20:59:01 +0900 Subject: [PATCH 02/11] add dry-run option to formula#install --- Library/Homebrew/cmd/install.rb | 4 +++- Library/Homebrew/formula_installer.rb | 11 +++++++++-- Library/Homebrew/install.rb | 4 +++- Library/Homebrew/upgrade.rb | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 2acb56baba..60f2733cd1 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -245,6 +245,7 @@ module Homebrew debug: args.debug?, quiet: args.quiet?, verbose: args.verbose?, + dry_run: args.dry_run?, ) Upgrade.check_installed_dependents( @@ -260,9 +261,10 @@ module Homebrew debug: args.debug?, quiet: args.quiet?, verbose: args.verbose?, + dry_run: args.dry_run?, ) - Cleanup.periodic_clean! + Cleanup.periodic_clean!(dry_run: args.dry_run?) Homebrew.messages.display_messages(display_times: args.display_times?) rescue FormulaUnreadableError, FormulaClassUnavailableError, diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index e895c09215..759fb247c7 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -40,7 +40,7 @@ class FormulaInstaller attr_predicate :show_summary_heading?, :show_header? attr_predicate :force_bottle?, :ignore_deps?, :only_deps?, :interactive?, :git?, :force?, :overwrite?, :keep_tmp? attr_predicate :debug_symbols? - attr_predicate :verbose?, :debug?, :quiet? + attr_predicate :verbose?, :debug?, :quiet?, :dry_run? def initialize( formula, @@ -66,7 +66,8 @@ class FormulaInstaller overwrite: false, debug: false, quiet: false, - verbose: false + verbose: false, + dry_run: false ) @formula = formula @env = env @@ -90,6 +91,7 @@ class FormulaInstaller @verbose = verbose @quiet = quiet @debug = debug + @dry_run = dry_run @installed_as_dependency = installed_as_dependency @installed_on_request = installed_on_request @options = options @@ -696,6 +698,7 @@ class FormulaInstaller debug: debug?, quiet: quiet?, verbose: verbose?, + dry_run: dry_run?, ) fi.prelude fi.fetch @@ -1182,6 +1185,10 @@ class FormulaInstaller return if self.class.fetched.include?(formula) fetch_dependencies + if dry_run? + puts "#{Formatter.identifier(formula.full_name)} would be installed" + return + end return if only_deps? diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 3d838dac3e..8154dd1325 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -274,7 +274,8 @@ module Homebrew overwrite: false, debug: false, quiet: false, - verbose: false + verbose: false, + dry_run: false ) formula_installers = formulae_to_install.map do |f| Migrator.migrate_if_needed(f, force: force) @@ -300,6 +301,7 @@ module Homebrew debug: debug, quiet: quiet, verbose: verbose, + dry_run: dry_run, ) begin diff --git a/Library/Homebrew/upgrade.rb b/Library/Homebrew/upgrade.rb index 54e3223c18..82b6b7a691 100644 --- a/Library/Homebrew/upgrade.rb +++ b/Library/Homebrew/upgrade.rb @@ -208,6 +208,7 @@ module Homebrew # possible for the existing build to interfere with the build we are about to # do! Seriously, it happens! kegs.each(&:unlink) if kegs.present? + return if formula_installer.dry_run? formula_installer.install formula_installer.finish From 8a7f445d1f1095cf2587f6d4e3e9fde630459f7e Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Wed, 17 Aug 2022 22:14:05 +0900 Subject: [PATCH 03/11] repair how to show casks to be installed --- Library/Homebrew/cask/cmd/install.rb | 21 ++++++++++++++++++++- Library/Homebrew/cask/installer.rb | 11 +++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cask/cmd/install.rb b/Library/Homebrew/cask/cmd/install.rb index 2d477f10e8..6c4d71572a 100644 --- a/Library/Homebrew/cask/cmd/install.rb +++ b/Library/Homebrew/cask/cmd/install.rb @@ -70,14 +70,33 @@ module Cask quarantine: quarantine, quiet: quiet, zap: zap, - dry_run: dry_run, }.compact options[:quarantine] = true if options[:quarantine].nil? + if dry_run + casks_to_install = casks.reject(&:installed?) + if casks_to_install.present? + ohai "Would install #{casks_to_install.count} #{"package".pluralize(casks_to_install.count)}:" + puts casks_to_install.map(&:full_name).join(" ") + end + end + require "cask/installer" casks.each do |cask| + if dry_run + dep_names = CaskDependent.new(cask) + .runtime_dependencies + .reject(&:installed?) + .map(&:to_formula) + .map(&:name) + if dep_names.present? + ohai "Would install #{dep_names.count} #{"dependency".pluralize(dep_names.count)} for #{cask.full_name}:" + puts dep_names.join(" ") + end + next + end Installer.new(cask, **options).install rescue CaskAlreadyInstalledError => e opoo e.message diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index e13eb423e3..18337bd043 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -24,7 +24,7 @@ module Cask skip_cask_deps: false, binaries: true, verbose: false, zap: false, require_sha: false, upgrade: false, installed_as_dependency: false, quarantine: true, - verify_download_integrity: true, quiet: false, dry_run: false) + verify_download_integrity: true, quiet: false) @cask = cask @command = command @force = force @@ -39,12 +39,11 @@ module Cask @quarantine = quarantine @verify_download_integrity = verify_download_integrity @quiet = quiet - @dry_run = dry_run end attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?, :reinstall?, :upgrade?, :verbose?, :zap?, :installed_as_dependency?, - :quarantine?, :quiet?, :dry_run? + :quarantine?, :quiet? def self.caveats(cask) odebug "Printing caveats" @@ -97,13 +96,9 @@ module Cask check_conflicts print caveats - if dry_run? - puts "#{Formatter.identifier(@cask)} would be installed" - exit - end + fetch uninstall_existing_cask if reinstall? - backup if force? && @cask.staged_path.exist? && @cask.metadata_versioned_path.exist? oh1 "Installing Cask #{Formatter.identifier(@cask)}" From 66817c0c320c8fcf27de47923d0657c87fbf08f6 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Wed, 17 Aug 2022 22:14:20 +0900 Subject: [PATCH 04/11] repair how to show formula to be installed --- Library/Homebrew/formula_installer.rb | 4 ---- Library/Homebrew/install.rb | 32 ++++++++++++++++++++++++--- Library/Homebrew/upgrade.rb | 1 - 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 759fb247c7..aa25be9bbd 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -1185,10 +1185,6 @@ class FormulaInstaller return if self.class.fetched.include?(formula) fetch_dependencies - if dry_run? - puts "#{Formatter.identifier(formula.full_name)} would be installed" - return - end return if only_deps? diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 8154dd1325..382ecb8076 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -278,7 +278,7 @@ module Homebrew dry_run: false ) formula_installers = formulae_to_install.map do |f| - Migrator.migrate_if_needed(f, force: force) + Migrator.migrate_if_needed(f, force: force, dry_run: dry_run) build_options = f.build fi = FormulaInstaller.new( @@ -305,8 +305,10 @@ module Homebrew ) begin - fi.prelude - fi.fetch + unless dry_run + fi.prelude + fi.fetch + end fi rescue CannotInstallFormulaError => e ofail e.message @@ -317,6 +319,14 @@ module Homebrew end end.compact + if dry_run + formulae_name_to_install = formulae_to_install.map(&:name) + if formulae_name_to_install.present? + ohai "Would install #{formulae_name_to_install.count} #{"package".pluralize(formulae_name_to_install.count)}:" + puts formulae_name_to_install.join(" ") + end + end + formula_installers.each do |fi| install_formula(fi) Cleanup.install_formula_clean!(fi.formula) @@ -326,11 +336,27 @@ module Homebrew def install_formula(formula_installer) f = formula_installer.formula + if formula_installer.dry_run? + print_dry_run_dependencies(f, formula_installer.compute_dependencies) + return + end + upgrade = f.linked? && f.outdated? && !f.head? && !Homebrew::EnvConfig.no_install_upgrade? Upgrade.install_formula(formula_installer, upgrade: upgrade) end private_class_method :install_formula + + def print_dry_run_dependencies(formula, dependencies) + return unless dependencies.present? + + plural = "dependency".pluralize(dependencies.count) + ohai "Would install #{dependencies.count} #{plural} for #{formula.name}:" + formula_names = dependencies.map(&:first).map(&:to_formula).map(&:name) + puts formula_names.join(" ") + end + + private_class_method :print_dry_run_dependencies end end diff --git a/Library/Homebrew/upgrade.rb b/Library/Homebrew/upgrade.rb index 82b6b7a691..54e3223c18 100644 --- a/Library/Homebrew/upgrade.rb +++ b/Library/Homebrew/upgrade.rb @@ -208,7 +208,6 @@ module Homebrew # possible for the existing build to interfere with the build we are about to # do! Seriously, it happens! kegs.each(&:unlink) if kegs.present? - return if formula_installer.dry_run? formula_installer.install formula_installer.finish From 1bfcf314ac855275d342021fdd1e783d00e3106d Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Thu, 18 Aug 2022 00:16:11 +0900 Subject: [PATCH 05/11] repair style --- Library/Homebrew/cask/cmd/install.rb | 6 ++++-- Library/Homebrew/install.rb | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cask/cmd/install.rb b/Library/Homebrew/cask/cmd/install.rb index 6c4d71572a..82333efb68 100644 --- a/Library/Homebrew/cask/cmd/install.rb +++ b/Library/Homebrew/cask/cmd/install.rb @@ -77,7 +77,8 @@ module Cask if dry_run casks_to_install = casks.reject(&:installed?) if casks_to_install.present? - ohai "Would install #{casks_to_install.count} #{"package".pluralize(casks_to_install.count)}:" + plural = "package".pluralize(casks_to_install.count) + ohai "Would install #{casks_to_install.count} #{plural}:" puts casks_to_install.map(&:full_name).join(" ") end end @@ -92,7 +93,8 @@ module Cask .map(&:to_formula) .map(&:name) if dep_names.present? - ohai "Would install #{dep_names.count} #{"dependency".pluralize(dep_names.count)} for #{cask.full_name}:" + plural = "dependency".pluralize(dep_names.count) + ohai "Would install #{dep_names.count} #{plural} for #{cask.full_name}:" puts dep_names.join(" ") end next diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 382ecb8076..5cb3d09380 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -322,7 +322,8 @@ module Homebrew if dry_run formulae_name_to_install = formulae_to_install.map(&:name) if formulae_name_to_install.present? - ohai "Would install #{formulae_name_to_install.count} #{"package".pluralize(formulae_name_to_install.count)}:" + plural = "package".pluralize(casks_to_install.count) + ohai "Would install #{formulae_name_to_install.count} #{plural}:" puts formulae_name_to_install.join(" ") end end @@ -348,11 +349,11 @@ module Homebrew private_class_method :install_formula def print_dry_run_dependencies(formula, dependencies) - return unless dependencies.present? + return if dependencies.empry? plural = "dependency".pluralize(dependencies.count) ohai "Would install #{dependencies.count} #{plural} for #{formula.name}:" - formula_names = dependencies.map(&:first).map(&:to_formula).map(&:name) + formula_names = dependencies.map(&:first).map(&:to_formula).map(&:name) puts formula_names.join(" ") end From 4bbcab235b69e44affc31a47179a80a818b50c3e Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Fri, 19 Aug 2022 20:08:38 +0900 Subject: [PATCH 06/11] change local variable --- Library/Homebrew/install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 5cb3d09380..953b7545b0 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -322,7 +322,7 @@ module Homebrew if dry_run formulae_name_to_install = formulae_to_install.map(&:name) if formulae_name_to_install.present? - plural = "package".pluralize(casks_to_install.count) + plural = "package".pluralize(formulae_name_to_install.count) ohai "Would install #{formulae_name_to_install.count} #{plural}:" puts formulae_name_to_install.join(" ") end From 0f544be8ffdc42a227b288566a4ab43e38cf95d3 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Fri, 19 Aug 2022 21:43:41 +0900 Subject: [PATCH 07/11] remove dry-run option from FormulaInstaller --- Library/Homebrew/formula_installer.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index aa25be9bbd..e895c09215 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -40,7 +40,7 @@ class FormulaInstaller attr_predicate :show_summary_heading?, :show_header? attr_predicate :force_bottle?, :ignore_deps?, :only_deps?, :interactive?, :git?, :force?, :overwrite?, :keep_tmp? attr_predicate :debug_symbols? - attr_predicate :verbose?, :debug?, :quiet?, :dry_run? + attr_predicate :verbose?, :debug?, :quiet? def initialize( formula, @@ -66,8 +66,7 @@ class FormulaInstaller overwrite: false, debug: false, quiet: false, - verbose: false, - dry_run: false + verbose: false ) @formula = formula @env = env @@ -91,7 +90,6 @@ class FormulaInstaller @verbose = verbose @quiet = quiet @debug = debug - @dry_run = dry_run @installed_as_dependency = installed_as_dependency @installed_on_request = installed_on_request @options = options @@ -698,7 +696,6 @@ class FormulaInstaller debug: debug?, quiet: quiet?, verbose: verbose?, - dry_run: dry_run?, ) fi.prelude fi.fetch From b61ae5942166e9ffcd49b0595fddcb726cd36f75 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Fri, 19 Aug 2022 21:43:57 +0900 Subject: [PATCH 08/11] repair syntax --- Library/Homebrew/cask/cmd/install.rb | 24 ++++++++++++------------ Library/Homebrew/cask/installer.rb | 2 +- Library/Homebrew/install.rb | 14 +++++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Library/Homebrew/cask/cmd/install.rb b/Library/Homebrew/cask/cmd/install.rb index 82333efb68..fb410b83d5 100644 --- a/Library/Homebrew/cask/cmd/install.rb +++ b/Library/Homebrew/cask/cmd/install.rb @@ -81,24 +81,24 @@ module Cask ohai "Would install #{casks_to_install.count} #{plural}:" puts casks_to_install.map(&:full_name).join(" ") end - end - - require "cask/installer" - - casks.each do |cask| - if dry_run + casks.each do |cask| dep_names = CaskDependent.new(cask) .runtime_dependencies .reject(&:installed?) .map(&:to_formula) .map(&:name) - if dep_names.present? - plural = "dependency".pluralize(dep_names.count) - ohai "Would install #{dep_names.count} #{plural} for #{cask.full_name}:" - puts dep_names.join(" ") - end - next + next if dep_names.blank? + + plural = "dependency".pluralize(dep_names.count) + ohai "Would install #{dep_names.count} #{plural} for #{cask.full_name}:" + puts dep_names.join(" ") end + return + end + + require "cask/installer" + + casks.each do |cask| Installer.new(cask, **options).install rescue CaskAlreadyInstalledError => e opoo e.message diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 18337bd043..9ef2b3bea2 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -96,8 +96,8 @@ module Cask check_conflicts print caveats - fetch + uninstall_existing_cask if reinstall? backup if force? && @cask.staged_path.exist? && @cask.metadata_versioned_path.exist? diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 953b7545b0..9a4cddc3b9 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -301,7 +301,6 @@ module Homebrew debug: debug, quiet: quiet, verbose: verbose, - dry_run: dry_run, ) begin @@ -325,7 +324,13 @@ module Homebrew plural = "package".pluralize(formulae_name_to_install.count) ohai "Would install #{formulae_name_to_install.count} #{plural}:" puts formulae_name_to_install.join(" ") + + formula_installers.each do |fi| + f = fi.formula + print_dry_run_dependencies(f, fi.compute_dependencies) + end end + return end formula_installers.each do |fi| @@ -337,11 +342,6 @@ module Homebrew def install_formula(formula_installer) f = formula_installer.formula - if formula_installer.dry_run? - print_dry_run_dependencies(f, formula_installer.compute_dependencies) - return - end - upgrade = f.linked? && f.outdated? && !f.head? && !Homebrew::EnvConfig.no_install_upgrade? Upgrade.install_formula(formula_installer, upgrade: upgrade) @@ -349,7 +349,7 @@ module Homebrew private_class_method :install_formula def print_dry_run_dependencies(formula, dependencies) - return if dependencies.empry? + return if dependencies.empty? plural = "dependency".pluralize(dependencies.count) ohai "Would install #{dependencies.count} #{plural} for #{formula.name}:" From 374dd3dea24ff4648fccb61bcbb177f03d543498 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Sat, 27 Aug 2022 22:29:07 +0900 Subject: [PATCH 09/11] repair if syntax and remove useless line --- Library/Homebrew/cask/cmd/install.rb | 5 ++--- Library/Homebrew/cask/installer.rb | 1 - Library/Homebrew/install.rb | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cask/cmd/install.rb b/Library/Homebrew/cask/cmd/install.rb index fb410b83d5..8b088de6b3 100644 --- a/Library/Homebrew/cask/cmd/install.rb +++ b/Library/Homebrew/cask/cmd/install.rb @@ -75,9 +75,8 @@ module Cask options[:quarantine] = true if options[:quarantine].nil? if dry_run - casks_to_install = casks.reject(&:installed?) - if casks_to_install.present? - plural = "package".pluralize(casks_to_install.count) + if (casks_to_install = casks.reject(&:installed?).presence) + plural = "cask".pluralize(casks_to_install.count) ohai "Would install #{casks_to_install.count} #{plural}:" puts casks_to_install.map(&:full_name).join(" ") end diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 9ef2b3bea2..06b015517a 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -97,7 +97,6 @@ module Cask print caveats fetch - uninstall_existing_cask if reinstall? backup if force? && @cask.staged_path.exist? && @cask.metadata_versioned_path.exist? diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 9a4cddc3b9..9b21b1029b 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -319,9 +319,8 @@ module Homebrew end.compact if dry_run - formulae_name_to_install = formulae_to_install.map(&:name) - if formulae_name_to_install.present? - plural = "package".pluralize(formulae_name_to_install.count) + if (formulae_name_to_install = formulae_to_install.map(&:name)) + plural = "formula".pluralize(formulae_name_to_install.count) ohai "Would install #{formulae_name_to_install.count} #{plural}:" puts formulae_name_to_install.join(" ") From 5491f7b1bd1af1f394826225d2385c042f947bb6 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Sat, 3 Sep 2022 16:01:55 +0900 Subject: [PATCH 10/11] share Install.print_dry_run_dependencies --- Library/Homebrew/install.rb | 8 +++----- Library/Homebrew/upgrade.rb | 25 ++++++++----------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 9b21b1029b..51cd1bf42a 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -326,7 +326,7 @@ module Homebrew formula_installers.each do |fi| f = fi.formula - print_dry_run_dependencies(f, fi.compute_dependencies) + print_dry_run_dependencies(f, fi.compute_dependencies, &:name) end end return @@ -347,16 +347,14 @@ module Homebrew end private_class_method :install_formula - def print_dry_run_dependencies(formula, dependencies) + def print_dry_run_dependencies(formula, dependencies, &block) return if dependencies.empty? plural = "dependency".pluralize(dependencies.count) ohai "Would install #{dependencies.count} #{plural} for #{formula.name}:" - formula_names = dependencies.map(&:first).map(&:to_formula).map(&:name) + formula_names = dependencies.map(&:first).map(&:to_formula).map(&block) puts formula_names.join(" ") end - - private_class_method :print_dry_run_dependencies end end diff --git a/Library/Homebrew/upgrade.rb b/Library/Homebrew/upgrade.rb index 54e3223c18..48a1a363c9 100644 --- a/Library/Homebrew/upgrade.rb +++ b/Library/Homebrew/upgrade.rb @@ -94,22 +94,6 @@ 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}" @@ -178,7 +162,14 @@ module Homebrew formula = formula_installer.formula if dry_run - print_dry_run_dependencies(formula, formula_installer.compute_dependencies) + Install.print_dry_run_dependencies(formula, formula_installer.compute_dependencies) 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 return end From d0e83d39a028babe1a1509ea4d198c9b9d5be6ba Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Tue, 6 Sep 2022 22:07:44 +0900 Subject: [PATCH 11/11] add empty line --- Library/Homebrew/cask/installer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 06b015517a..c0417e311d 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -98,6 +98,7 @@ module Cask print caveats fetch uninstall_existing_cask if reinstall? + backup if force? && @cask.staged_path.exist? && @cask.metadata_versioned_path.exist? oh1 "Installing Cask #{Formatter.identifier(@cask)}"