From 98e6e6e31fee6ba077f3bdf74dd969a254530edc Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sun, 21 Aug 2022 12:37:38 -0700 Subject: [PATCH] Ignore HOMEBREW_NO_CLEANUP_FORMULAE deps in `brew autoremove` --- Library/Homebrew/cleanup.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index 72b325cb9e..716a23dfbb 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -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)