cmd/upgrade: add --dry-run option.

This commit is contained in:
Doug Hogan 2019-07-26 22:55:16 -07:00
parent 6db1c7383f
commit 9e0e012a56
4 changed files with 28 additions and 3 deletions

View File

@ -46,6 +46,8 @@ module Homebrew
description: "Print the verification and postinstall steps." description: "Print the verification and postinstall steps."
switch "--display-times", switch "--display-times",
description: "Print install times for each formula at the end of the run." description: "Print install times for each formula at the end of the run."
switch "--dry-run",
description: "Show what would be upgraded, but do not actually upgrade anything."
conflicts "--build-from-source", "--force-bottle" conflicts "--build-from-source", "--force-bottle"
formula_options formula_options
end end
@ -104,11 +106,15 @@ module Homebrew
puts formulae_upgrades.join(", ") puts formulae_upgrades.join(", ")
end end
upgrade_formulae(formulae_to_install) if args.dry_run?
puts "Dry run: did not upgrade anything."
else
upgrade_formulae(formulae_to_install)
check_dependents(formulae_to_install) check_dependents(formulae_to_install)
Homebrew.messages.display_messages Homebrew.messages.display_messages
end
end end
def upgrade_formulae(formulae_to_install) def upgrade_formulae(formulae_to_install)

View File

@ -16,4 +16,17 @@ describe "brew upgrade", :integration_test do
expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory
expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist
end end
it "can do a dry run upgrade" do
setup_test_formula "testball"
(HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
expect { brew "upgrade", "--dry-run" }
.to output(/Dry run: did not upgrade anything/).to_stdout
.and not_to_output.to_stderr
.and be_a_success
expect(HOMEBREW_CELLAR/"testball/0.1").not_to exist
expect(HOMEBREW_CELLAR/"testball/0.0.1").to be_a_directory
end
end end

View File

@ -557,6 +557,8 @@ upgraded formulae or, every 30 days, for all formulae.
Don't delete the temporary files created during installation. Don't delete the temporary files created during installation.
* `--display-times`: * `--display-times`:
Print install times for each formula at the end of the run. Print install times for each formula at the end of the run.
* `--dry-run`:
Show what would be upgraded, but do not actually upgrade anything.
### `uses` [*`options`*] *`formula`* ### `uses` [*`options`*] *`formula`*

View File

@ -690,6 +690,10 @@ Don\'t delete the temporary files created during installation\.
\fB\-\-display\-times\fR \fB\-\-display\-times\fR
Print install times for each formula at the end of the run\. Print install times for each formula at the end of the run\.
. .
.TP
\fB\-\-dry\-run\fR
Show what would be upgraded, but do not actually upgrade anything\.
.
.SS "\fBuses\fR [\fIoptions\fR] \fIformula\fR" .SS "\fBuses\fR [\fIoptions\fR] \fIformula\fR"
Show the formulae that specify \fIformula\fR as a dependency\. When given multiple formula arguments, show the intersection of formulae that use \fIformula\fR\. Show the formulae that specify \fIformula\fR as a dependency\. When given multiple formula arguments, show the intersection of formulae that use \fIformula\fR\.
. .