From ca97c0d008f23d537f10fb0bbbcb1f397863abc7 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 9 May 2024 11:20:43 +0100 Subject: [PATCH] Enable HOMEBREW_AUTOREMOVE by autoremove_default Enabled `HOMEBREW_AUTOREMOVE` by default, and added `HOMEBREW_NO_AUTOREMOVE` to disable it. --- Library/Homebrew/cleanup.rb | 2 +- Library/Homebrew/cmd/uninstall.rb | 2 +- Library/Homebrew/env_config.rb | 5 +++++ Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index fd0c2d30de8497..0fbfee8aaa8026 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -288,7 +288,7 @@ def clean!(quiet: false, periodic: false) cleanup_formula(formula, quiet:, ds_store: false, cache_db: false) end - Cleanup.autoremove(dry_run: dry_run?) if Homebrew::EnvConfig.autoremove? + Cleanup.autoremove(dry_run: dry_run?) unless Homebrew::EnvConfig.no_autoremove? cleanup_cache cleanup_empty_api_source_directories diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index 4bc98b2305f823..5bd384181c3ca2 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -77,7 +77,7 @@ def run ) end - Cleanup.autoremove if Homebrew::EnvConfig.autoremove? + Cleanup.autoremove unless Homebrew::EnvConfig.no_autoremove? end end end diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 0424212119ed12..559492b633b33a 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -313,6 +313,11 @@ module EnvConfig "configuration. Please ensure you always run `brew update` before reporting any issues.", boolean: true, }, + HOMEBREW_NO_AUTOREMOVE: { + description: "If set, calls to `brew cleanup` and `brew uninstall` not automatically " \ + "remove unused formula dependents.", + boolean: true, + }, HOMEBREW_NO_BOOTSNAP: { description: "If set, do not use Bootsnap to speed up repeated `brew` calls.", boolean: true, diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi index 14bc5e01b0b9b1..9271a6a6ad8e04 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi @@ -190,6 +190,9 @@ module Homebrew::EnvConfig sig { returns(T::Boolean) } def no_auto_update?; end + sig { returns(T::Boolean) } + def no_autoremove?; end + sig { returns(T::Boolean) } def no_bootsnap?; end