Merge pull request #13730 from apainintheneck/handle-no-cleanup-formulae-in-autoremove

Ignore HOMEBREW_NO_CLEANUP_FORMULAE deps in `brew autoremove`
This commit is contained in:
Mike McQuaid 2022-08-23 09:48:30 +01:00 committed by GitHub
commit 3be7a65486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -189,8 +189,8 @@ module Homebrew
def self.skip_clean_formula?(f)
return false if Homebrew::EnvConfig.no_cleanup_formulae.blank?
skip_clean_formulae = Homebrew::EnvConfig.no_cleanup_formulae.split(",")
skip_clean_formulae.include?(f.name) || (skip_clean_formulae & f.aliases).present?
@skip_clean_formulae ||= Homebrew::EnvConfig.no_cleanup_formulae.split(",")
@skip_clean_formulae.include?(f.name) || (@skip_clean_formulae & f.aliases).present?
end
def self.periodic_clean_due?
@ -535,8 +535,12 @@ module Homebrew
# the cache of installed formulae may no longer be valid.
Formula.clear_cache unless dry_run
# Remove formulae listed in HOMEBREW_NO_CLEANUP_FORMULAE.
formulae = Formula.installed.reject(&method(:skip_clean_formula?))
formulae = Formula.installed
# Remove formulae listed in HOMEBREW_NO_CLEANUP_FORMULAE and their dependencies.
if Homebrew::EnvConfig.no_cleanup_formulae.present?
formulae -= formulae.select(&method(:skip_clean_formula?))
.flat_map { |f| [f, *f.runtime_formula_dependencies] }
end
casks = Cask::Caskroom.casks
removable_formulae = Formula.unused_formulae_with_no_dependents(formulae, casks)