From 36f3e09669d9cd3687d9ad1f7b02a4ccd999c93e Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Sat, 15 Aug 2020 10:43:29 +0200 Subject: [PATCH] bump-revision: allow multiple formulae to be specified --- Library/Homebrew/dev-cmd/bump-revision.rb | 105 +++++++++++----------- docs/Manpage.md | 2 +- manpages/brew.1 | 2 +- 3 files changed, 55 insertions(+), 54 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-revision.rb b/Library/Homebrew/dev-cmd/bump-revision.rb index 2b71a91d7f..094f362cb0 100644 --- a/Library/Homebrew/dev-cmd/bump-revision.rb +++ b/Library/Homebrew/dev-cmd/bump-revision.rb @@ -9,7 +9,7 @@ module Homebrew def bump_revision_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `bump-revision` [] + `bump-revision` [] [ ...] Create a commit to increment the revision of . If no revision is present, "revision 1" will be added. @@ -19,7 +19,7 @@ module Homebrew flag "--message=", description: "Append to the default commit message." - named :formula + min_named :formula end end @@ -30,63 +30,64 @@ module Homebrew # user path, too. ENV["PATH"] = ENV["HOMEBREW_PATH"] - formula = args.formulae.first - current_revision = formula.revision + args.formulae.each do |formula| + 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 - - old = if formula.license - license_string = if formula.license.length > 1 - formula.license - else - "\"#{formula.license.first}\"" + if current_revision.zero? + formula_spec = formula.stable + hash_type, old_hash = if (checksum = formula_spec.checksum) + [checksum.hash_type, checksum.hexdigest] end - # insert replacement revision after license - <<~EOS - license #{license_string} - EOS - elsif formula.path.read.include?("stable do\n") - # insert replacement revision after homepage - <<~EOS - homepage "#{formula.homepage}" - EOS - elsif hash_type - # insert replacement revision after hash - <<~EOS - #{hash_type} "#{old_hash}" - EOS + + old = if formula.license + license_string = if formula.license.length > 1 + formula.license + else + "\"#{formula.license.first}\"" + end + # insert replacement revision after license + <<~EOS + license #{license_string} + EOS + elsif formula.path.read.include?("stable do\n") + # insert replacement revision after homepage + <<~EOS + homepage "#{formula.homepage}" + EOS + elsif hash_type + # insert replacement revision after hash + <<~EOS + #{hash_type} "#{old_hash}" + EOS + else + # insert replacement revision after :revision + <<~EOS + revision: "#{formula_spec.specs[:revision]}" + EOS + end + replacement = old + " revision 1\n" + else - # insert replacement revision after :revision - <<~EOS - revision: "#{formula_spec.specs[:revision]}" - EOS + old = "revision #{current_revision}" + replacement = "revision #{current_revision+1}" 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 args.quiet? - else - Utils::Inreplace.inreplace(formula.path) do |s| - s.gsub!(old, replacement) + if args.dry_run? + ohai "replace #{old.inspect} with #{replacement.inspect}" unless args.quiet? + else + Utils::Inreplace.inreplace(formula.path) do |s| + s.gsub!(old, replacement) + end 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 + 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 diff --git a/docs/Manpage.md b/docs/Manpage.md index a3a741ae70..d35cd591ff 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -865,7 +865,7 @@ nor vice versa. It must use whichever style specification the formula already us * `-f`, `--force`: Ignore duplicate open PRs. Remove all mirrors if --mirror= was not specified. -### `bump-revision` [*`options`*] *`formula`* +### `bump-revision` [*`options`*] *`formula`* [*`formula`* ...] Create a commit to increment the revision of *`formula`*. If no revision is present, "revision 1" will be added. diff --git a/manpages/brew.1 b/manpages/brew.1 index f1915f3b37..120e68cf37 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1210,7 +1210,7 @@ Specify the new git commit \fIrevision\fR corresponding to the specified \fItag\ \fB\-f\fR, \fB\-\-force\fR Ignore duplicate open PRs\. Remove all mirrors if \-\-mirror= was not specified\. . -.SS "\fBbump\-revision\fR [\fIoptions\fR] \fIformula\fR" +.SS "\fBbump\-revision\fR [\fIoptions\fR] \fIformula\fR [\fIformula\fR \.\.\.]" Create a commit to increment the revision of \fIformula\fR\. If no revision is present, "revision 1" will be added\. . .TP