From 0a85df8e19d39175b0c92f31a42c1c081764ac6c Mon Sep 17 00:00:00 2001 From: Justin Klaassen Date: Sat, 24 Feb 2024 09:35:32 -0800 Subject: [PATCH] Add HOMEBREW_UPGRADE_GREEDY="auto-updates" and "latest" Fixes: #16735 --- Library/Homebrew/cask/upgrade.rb | 2 - Library/Homebrew/cmd/outdated.rb | 9 ++- Library/Homebrew/cmd/upgrade.rb | 3 + Library/Homebrew/env_config.rb | 22 ++++++- Library/Homebrew/env_config.rbi | 4 +- Library/Homebrew/test/env_config_spec.rb | 81 ++++++++++++++++++++++++ docs/Manpage.md | 2 +- manpages/brew.1 | 2 +- 8 files changed, 114 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/cask/upgrade.rb b/Library/Homebrew/cask/upgrade.rb index 54e76880c6cac..4da2ec4a58096 100644 --- a/Library/Homebrew/cask/upgrade.rb +++ b/Library/Homebrew/cask/upgrade.rb @@ -40,8 +40,6 @@ def self.upgrade_casks( quarantine = true if quarantine.nil? - greedy = true if Homebrew::EnvConfig.upgrade_greedy? - outdated_casks = if casks.empty? Caskroom.casks(config: Config.from_args(args)).select do |cask| cask.outdated?(greedy: greedy, greedy_latest: greedy_latest, diff --git a/Library/Homebrew/cmd/outdated.rb b/Library/Homebrew/cmd/outdated.rb index 6df2c6e2d2553..95dd306c1ce7d 100644 --- a/Library/Homebrew/cmd/outdated.rb +++ b/Library/Homebrew/cmd/outdated.rb @@ -32,13 +32,16 @@ def self.outdated_args "formula is outdated. Otherwise, the repository's HEAD will only be checked for " \ "updates when a new stable or development version has been released." switch "-g", "--greedy", - description: "Also include outdated casks with `auto_updates true` or `version :latest`." + description: "Also include outdated casks with `auto_updates true` or `version :latest`.", + env: :cask_upgrade_greedy switch "--greedy-latest", - description: "Also include outdated casks including those with `version :latest`." + description: "Also include outdated casks including those with `version :latest`.", + env: :cask_upgrade_greedy_latest switch "--greedy-auto-updates", - description: "Also include outdated casks including those with `auto_updates true`." + description: "Also include outdated casks including those with `auto_updates true`.", + env: :cask_upgrade_greedy_auto_updates conflicts "--quiet", "--verbose", "--json" conflicts "--formula", "--cask" diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index ed712f3070f24..01956566eb314 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -91,12 +91,15 @@ def upgrade_args }], [:switch, "-g", "--greedy", { description: "Also include casks with `auto_updates true` or `version :latest`.", + env: :cask_upgrade_greedy, }], [:switch, "--greedy-latest", { description: "Also include casks with `version :latest`.", + env: :cask_upgrade_greedy_latest, }], [:switch, "--greedy-auto-updates", { description: "Also include casks with `auto_updates true`.", + env: :cask_upgrade_greedy_auto_updates, }], [:switch, "--[no-]binaries", { description: "Disable/enable linking of helper executables (default: enabled).", diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index c5d04c4082bad..ce5decaa09830 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -341,8 +341,9 @@ module EnvConfig boolean: true, }, HOMEBREW_UPGRADE_GREEDY: { - description: "If set, pass `--greedy` to all cask upgrade commands.", - boolean: true, + description: "When set to \"auto-updates\", \"latest\", or any other value (e.g. \"1\"), pass " \ + "`--greedy-auto-updates`, `--greedy-latest`, or `--greedy` respectively to all cask " \ + "upgrade commands.", }, HOMEBREW_SIMULATE_MACOS_ON_LINUX: { description: "If set, running Homebrew on Linux will simulate certain macOS code paths. This is useful " \ @@ -504,5 +505,22 @@ def cask_opts_require_sha? def automatically_set_no_install_from_api? ENV["HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API"].present? end + + sig { returns(T::Boolean) } + def cask_upgrade_greedy? + ENV["HOMEBREW_UPGRADE_GREEDY"].present? && + !cask_upgrade_greedy_latest? && + !cask_upgrade_greedy_auto_updates? + end + + sig { returns(T::Boolean) } + def cask_upgrade_greedy_latest? + ENV["HOMEBREW_UPGRADE_GREEDY"] == "latest" + end + + sig { returns(T::Boolean) } + def cask_upgrade_greedy_auto_updates? + ENV["HOMEBREW_UPGRADE_GREEDY"] == "auto-updates" + end end end diff --git a/Library/Homebrew/env_config.rbi b/Library/Homebrew/env_config.rbi index 1fa98249b3404..91bc33bb2fdcd 100644 --- a/Library/Homebrew/env_config.rbi +++ b/Library/Homebrew/env_config.rbi @@ -232,8 +232,8 @@ module Homebrew::EnvConfig sig { returns(T::Boolean) } def self.update_to_tag?; end - sig { returns(T::Boolean) } - def self.upgrade_greedy?; end + sig { returns(T.nilable(String)) } + def self.upgrade_greedy; end sig { returns(T::Boolean) } def self.verbose?; end diff --git a/Library/Homebrew/test/env_config_spec.rb b/Library/Homebrew/test/env_config_spec.rb index 02fdd05948c89..b780b401d96d0 100644 --- a/Library/Homebrew/test/env_config_spec.rb +++ b/Library/Homebrew/test/env_config_spec.rb @@ -63,4 +63,85 @@ expect(env_config.make_jobs).to eql("16") end end + + describe ".cask_upgrade_greedy" do + it "returns true if \"HOMEBREW_UPGRADE_GREEDY\" set to \"1\"" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "1" + expect(env_config.cask_upgrade_greedy?).to be(true) + end + + it "returns true if \"HOMEBREW_UPGRADE_GREEDY\" set to \"true\"" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "true" + expect(env_config.cask_upgrade_greedy?).to be(true) + end + + it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"latest\"" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "latest" + expect(env_config.cask_upgrade_greedy?).to be(false) + end + + it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"auto-updates\"" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "auto-updates" + expect(env_config.cask_upgrade_greedy?).to be(false) + end + + it "returns false by default" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "" + expect(env_config.cask_upgrade_greedy?).to be(false) + end + end + + describe ".cask_upgrade_greedy_latest" do + it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"1\"" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "1" + expect(env_config.cask_upgrade_greedy_latest?).to be(false) + end + + it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"true\"" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "true" + expect(env_config.cask_upgrade_greedy_latest?).to be(false) + end + + it "returns true if \"HOMEBREW_UPGRADE_GREEDY\" set to \"latest\"" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "latest" + expect(env_config.cask_upgrade_greedy_latest?).to be(true) + end + + it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"auto-updates\"" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "auto-updates" + expect(env_config.cask_upgrade_greedy_latest?).to be(false) + end + + it "returns false by default" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "" + expect(env_config.cask_upgrade_greedy_latest?).to be(false) + end + end + + describe ".cask_upgrade_greedy_auto_updates" do + it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"1\"" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "1" + expect(env_config.cask_upgrade_greedy_auto_updates?).to be(false) + end + + it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"true\"" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "true" + expect(env_config.cask_upgrade_greedy_auto_updates?).to be(false) + end + + it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"latest\"" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "latest" + expect(env_config.cask_upgrade_greedy_auto_updates?).to be(false) + end + + it "returns true if \"HOMEBREW_UPGRADE_GREEDY\" set to \"auto-updates\"" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "auto-updates" + expect(env_config.cask_upgrade_greedy_auto_updates?).to be(true) + end + + it "returns false by default" do + ENV["HOMEBREW_UPGRADE_GREEDY"] = "" + expect(env_config.cask_upgrade_greedy_auto_updates?).to be(false) + end + end end diff --git a/docs/Manpage.md b/docs/Manpage.md index 2abe611ece4b5..00801749302c0 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -2357,7 +2357,7 @@ command execution e.g. `$(cat file)`.
If set, use Pry for the `brew irb` command. - `HOMEBREW_UPGRADE_GREEDY` -
If set, pass `--greedy` to all cask upgrade commands. +
When set to "auto-updates", "latest", or any other value (e.g. "1"), pass `--greedy-auto-updates`, `--greedy-latest`, or `--greedy` respectively to all cask upgrade commands. - `HOMEBREW_SIMULATE_MACOS_ON_LINUX`
If set, running Homebrew on Linux will simulate certain macOS code paths. This is useful when auditing macOS formulae while on Linux. diff --git a/manpages/brew.1 b/manpages/brew.1 index 69941c531d2f6..81468437be9d2 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -3464,7 +3464,7 @@ If set, use Pry for the \fBbrew irb\fR command\. \fBHOMEBREW_UPGRADE_GREEDY\fR . .br -If set, pass \fB\-\-greedy\fR to all cask upgrade commands\. +When set to "auto\-updates", "latest", or any other value (e\.g\. "1"), pass \fB\-\-greedy\-auto\-updates\fR, \fB\-\-greedy\-latest\fR, or \fB\-\-greedy\fR respectively to all cask upgrade commands\. . .TP \fBHOMEBREW_SIMULATE_MACOS_ON_LINUX\fR