brew/Library/Homebrew/dev-cmd/bump-revision.rb

77 lines
2.1 KiB
Ruby
Raw Normal View History

2020-11-25 17:03:23 +01:00
# typed: true
# frozen_string_literal: true
require "formula"
require "cli/parser"
module Homebrew
2020-10-20 12:03:48 +02:00
extend T::Sig
module_function
2020-10-20 12:03:48 +02:00
sig { returns(CLI::Parser) }
def bump_revision_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`bump-revision` [<options>] <formula> [<formula> ...]
2019-08-06 14:20:27 -04:00
Create a commit to increment the revision of <formula>. If no revision is
2019-08-06 13:23:19 -04:00
present, "revision 1" will be added.
EOS
switch "-n", "--dry-run",
description: "Print what would be done rather than doing it."
2019-08-06 13:23:19 -04:00
flag "--message=",
description: "Append <message> to the default commit message."
2020-07-30 18:40:10 +02:00
min_named :formula
end
end
def bump_revision
args = 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"]
args.named.to_formulae.each do |formula|
current_revision = formula.revision
new_revision = current_revision + 1
2020-12-18 17:24:40 -08:00
if args.dry_run?
unless args.quiet?
old_text = "revision #{current_revision}"
new_text = "revision #{new_revision}"
2020-12-18 17:24:40 -08:00
if current_revision.zero?
ohai "add #{new_text.inspect}"
else
ohai "replace #{old_text.inspect} with #{new_text.inspect}"
end
end
else
Homebrew.install_bundler_gems!
require "utils/ast"
Utils::Inreplace.inreplace(formula.path) do |s|
2020-12-18 17:24:40 -08:00
s = s.inreplace_string
if current_revision.zero?
Utils::AST.add_formula_stanza!(s, :revision, new_revision)
2020-12-18 17:24:40 -08:00
else
Utils::AST.replace_formula_stanza!(s, :revision, new_revision)
2020-12-18 17:24:40 -08:00
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
end
end
end
end
end