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
Add bump-revision command #5961
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# frozen_string_literal: true | ||
|
||
require "formula" | ||
require "cli/parser" | ||
|
||
module Homebrew | ||
module_function | ||
|
||
def bump_revision_args | ||
Homebrew::CLI::Parser.new do | ||
usage_banner <<~EOS | ||
`bump-revision` [<options>] [<formula>] | ||
|
||
Create a commit to increment the revision of the formula. If no revision is | ||
present, "revision 1" will be added. | ||
EOS | ||
switch "-n", "--dry-run", | ||
description: "Print what would be done rather than doing it." | ||
flag "--message=", | ||
description: "Append the provided <message> to the default commit message." | ||
|
||
switch :force | ||
switch :quiet | ||
switch :verbose | ||
switch :debug | ||
end | ||
end | ||
|
||
def bump_revision | ||
bump_revision_args.parse | ||
|
||
# As this command is simplifying user run commands then let's just use a | ||
# user path, too. | ||
ENV["PATH"] = ENV["HOMEBREW_PATH"] | ||
|
||
raise "Multiple formulae given, only one is allowed." if ARGV.formulae.length > 1 | ||
|
||
formula = ARGV.formulae.first | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May want to error if there's more than one. |
||
current_revision = formula.revision | ||
|
||
if current_revision.zero? | ||
formula_spec = formula.stable | ||
hash_type, old_hash = if (checksum = formula_spec.checksum) | ||
[checksum.hash_type, checksum.hexdigest] | ||
end | ||
|
||
if hash_type | ||
# insert replacement revision after hash | ||
old = <<~EOS | ||
#{hash_type} "#{old_hash}" | ||
EOS | ||
else | ||
# insert replacement revision after :revision | ||
old = <<~EOS | ||
:revision => "#{formula_spec.specs[:revision]}" | ||
EOS | ||
end | ||
replacement = old + " revision 1\n" | ||
|
||
else | ||
old = "revision #{current_revision}" | ||
replacement = "revision #{current_revision+1}" | ||
end | ||
|
||
if args.dry_run? | ||
ohai "replace #{old.inspect} with #{replacement.inspect}" unless Homebrew.args.quiet? | ||
else | ||
Utils::Inreplace.inreplace(formula.path) do |s| | ||
s.gsub!(old, replacement) | ||
end | ||
MikeMcQuaid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
message = "#{formula.name}: revision bump #{args.message}" | ||
if args.dry_run? | ||
ohai "git commit --no-edit --verbose --message=#{message} -- #{formula.path}" | ||
else | ||
formula.path.parent.cd do | ||
safe_system "git", "commit", "--no-edit", "--verbose", | ||
"--message=#{message}", "--", formula.path | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
require "cmd/shared_examples/args_parse" | ||
|
||
describe "Homebrew.bump_revision_args" do | ||
it_behaves_like "parseable arguments" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a useful flag to have? I'm wondering if we need it for a v1 and it makes the code more complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, it's useful at least for debugging. Combined with the changes from @scpeters it is only two additional
if
block.