Merge pull request #5961 from Moisan/bump-revision
Add bump-revision command
This commit is contained in:
commit
a17b87368a
83
Library/Homebrew/dev-cmd/bump-revision.rb
Normal file
83
Library/Homebrew/dev-cmd/bump-revision.rb
Normal file
@ -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
|
||||||
|
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
|
||||||
|
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
|
||||||
7
Library/Homebrew/test/dev-cmd/bump-revision_spec.rb
Normal file
7
Library/Homebrew/test/dev-cmd/bump-revision_spec.rb
Normal file
@ -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
|
||||||
@ -739,6 +739,16 @@ formula already uses.
|
|||||||
* `--revision`:
|
* `--revision`:
|
||||||
Specify the new git commit *`revision`* corresponding to a specified *`tag`*.
|
Specify the new git commit *`revision`* corresponding to a specified *`tag`*.
|
||||||
|
|
||||||
|
### `bump-revision` [*`options`*] [*`formula`*]
|
||||||
|
|
||||||
|
Create a commit to increment the revision of the formula. If no revision is
|
||||||
|
present, "revision 1" will be added.
|
||||||
|
|
||||||
|
* `-n`, `--dry-run`:
|
||||||
|
Print what would be done rather than doing it.
|
||||||
|
* `--message`:
|
||||||
|
Append the provided *`message`* to the default commit message.
|
||||||
|
|
||||||
### `create` [*`options`*] *`URL`*
|
### `create` [*`options`*] *`URL`*
|
||||||
|
|
||||||
Generate a formula for the downloadable file at *`URL`* and open it in the editor.
|
Generate a formula for the downloadable file at *`URL`* and open it in the editor.
|
||||||
|
|||||||
@ -936,6 +936,17 @@ Specify the new git commit \fItag\fR for the formula\.
|
|||||||
\fB\-\-revision\fR
|
\fB\-\-revision\fR
|
||||||
Specify the new git commit \fIrevision\fR corresponding to a specified \fItag\fR\.
|
Specify the new git commit \fIrevision\fR corresponding to a specified \fItag\fR\.
|
||||||
.
|
.
|
||||||
|
.SS "\fBbump\-revision\fR [\fIoptions\fR] [\fIformula\fR]"
|
||||||
|
Create a commit to increment the revision of the formula\. If no revision is present, "revision 1" will be added\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-n\fR, \fB\-\-dry\-run\fR
|
||||||
|
Print what would be done rather than doing it\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-\-message\fR
|
||||||
|
Append the provided \fImessage\fR to the default commit message\.
|
||||||
|
.
|
||||||
.SS "\fBcreate\fR [\fIoptions\fR] \fIURL\fR"
|
.SS "\fBcreate\fR [\fIoptions\fR] \fIURL\fR"
|
||||||
Generate a formula for the downloadable file at \fIURL\fR and open it in the editor\. Homebrew will attempt to automatically derive the formula name and version, but if it fails, you\'ll have to make your own template\. The \fBwget\fR formula serves as a simple example\. For the complete API, see: \fIhttp://www\.rubydoc\.info/github/Homebrew/brew/master/Formula\fR
|
Generate a formula for the downloadable file at \fIURL\fR and open it in the editor\. Homebrew will attempt to automatically derive the formula name and version, but if it fails, you\'ll have to make your own template\. The \fBwget\fR formula serves as a simple example\. For the complete API, see: \fIhttp://www\.rubydoc\.info/github/Homebrew/brew/master/Formula\fR
|
||||||
.
|
.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user