From 18f8adbd5c70d38b9eae10da2455ccb09b79427b Mon Sep 17 00:00:00 2001 From: Jarek Wojciechowski Date: Sat, 20 Oct 2018 19:34:26 -0400 Subject: [PATCH] test and add HOMEBREW_INSTALL_CLEANUP to upgrade --- Library/Homebrew/cmd/upgrade.rb | 4 ++-- Library/Homebrew/test/cmd/upgrade_spec.rb | 15 ++++++++++++++- docs/Manpage.md | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 7b4b8c5c96..71d702f642 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -3,7 +3,7 @@ #: #: Options for the `install` command are also valid here. #: -#: If `--cleanup` is specified or `HOMEBREW_UPGRADE_CLEANUP` is set then remove +#: If `--cleanup` is specified, `HOMEBREW_INSTALL_CLEANUP` or `HOMEBREW_UPGRADE_CLEANUP` is set then remove #: previously installed version(s) of upgraded . #: #: If `--fetch-HEAD` is passed, fetch the upstream repository to detect if @@ -107,7 +107,7 @@ module Homebrew Migrator.migrate_if_needed(f) begin upgrade_formula(f) - next if !ARGV.include?("--cleanup") && !ENV["HOMEBREW_UPGRADE_CLEANUP"] + next if !ARGV.include?("--cleanup") && !ENV["HOMEBREW_UPGRADE_CLEANUP"] && !ENV["HOMEBREW_INSTALL_CLEANUP"] next unless f.installed? Cleanup.new.cleanup_formula(f) diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index cb6934d4c3..60ef9b25ca 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -8,7 +8,7 @@ describe "brew upgrade", :integration_test do expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory end - it "upgrades a Formula and cleans up old versions" do + it "upgrades a Formula and cleans up old versions when `--cleanup` is passed" do setup_test_formula "testball" (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath @@ -17,4 +17,17 @@ describe "brew upgrade", :integration_test do expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist end + + it "upgrades a Formula and cleans up old versions when `HOMEBREW_INSTALL_CLEANUP` is set" do + setup_test_formula "testball" + # allow(ENV).to receive(:[]).and_call_original + # allow(ENV).to receive(:[]).with("HOMEBREW_INSTALL_CLEANUP").and_return("1") + ENV["HOMEBREW_INSTALL_CLEANUP"] = "1" + (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath + + expect { brew "upgrade" }.to be_a_success + + expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory + expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist + end end diff --git a/docs/Manpage.md b/docs/Manpage.md index 5d8387d9c1..1d6ba4da8a 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -1246,6 +1246,9 @@ Note that environment variables must have a value set to be detected. For exampl * `HOMEBREW_UPGRADE_CLEANUP`: If set, `brew upgrade` always assumes `--cleanup` has been passed. + * `HOMEBREW_INSTALL_CLEANUP`: + If set, `brew upgrade` always assumes `--cleanup` has been passed. + * `HOMEBREW_VERBOSE`: If set, Homebrew always assumes `--verbose` when running commands.