Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the HOMEBREW_INSTALL_CLEANUP env to trigger cleanup on reinstall/install/upgrade #5165

Merged
merged 4 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a clarification around the original feature, is the intent to keep both ENVs or to enhance what the old one did as well a rename it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Wojonatior Good question 👍 Let's remove the documentation for HOMEBREW_UPGRADE_CLEANUP in favour of HOMEBREW_INSTALL_CLEANUP but keep the HOMEBREW_UPGRADE_CLEANUP variable functional for people who are still using it.

#: previously installed version(s) of upgraded <formulae>.
#:
#: If `--fetch-HEAD` is passed, fetch the upstream repository to detect if
Expand Down Expand Up @@ -107,7 +107,7 @@ def upgrade_formulae(formulae_to_install)
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)
Expand Down
15 changes: 14 additions & 1 deletion Library/Homebrew/test/cmd/upgrade_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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

Expand All @@ -17,4 +17,17 @@
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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried both manually setting into ENV and mocking it out as shown in the 2 commented lines. I wasn't able to get either working even though I could confirm the functionality manually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Wojonatior Ideally we wouldn't add another integration test for this (they are really slow). Either add a unit test or omit one entirely.

(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
3 changes: 3 additions & 0 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down