2019-03-31 19:06:29 -04:00
|
|
|
# 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
|
2019-08-06 14:17:17 -04:00
|
|
|
`bump-revision` [<options>] <formula>
|
2019-03-31 19:06:29 -04:00
|
|
|
|
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.
|
2019-03-31 19:06:29 -04:00
|
|
|
EOS
|
|
|
|
switch "-n", "--dry-run",
|
2019-05-14 12:03:06 -04:00
|
|
|
description: "Print what would be done rather than doing it."
|
2019-08-06 13:23:19 -04:00
|
|
|
flag "--message=",
|
2019-08-20 00:04:14 -04:00
|
|
|
description: "Append <message> to the default commit message."
|
2020-07-30 18:40:10 +02:00
|
|
|
|
2020-04-18 12:13:43 -04:00
|
|
|
named :formula
|
2019-03-31 19:06:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def bump_revision
|
2020-07-27 03:59:52 +02:00
|
|
|
args = bump_revision_args.parse
|
2019-03-31 19:06:29 -04:00
|
|
|
|
2020-04-18 12:13:43 -04:00
|
|
|
# As this command is simplifying user-run commands then let's just use a
|
2019-03-31 19:06:29 -04:00
|
|
|
# user path, too.
|
|
|
|
ENV["PATH"] = ENV["HOMEBREW_PATH"]
|
|
|
|
|
2020-04-18 12:13:43 -04:00
|
|
|
formula = args.formulae.first
|
2019-03-31 19:06:29 -04:00
|
|
|
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
|
|
|
|
|
2020-07-12 20:05:27 -07:00
|
|
|
old = if formula.license
|
2020-07-30 09:30:44 -04:00
|
|
|
license_string = if formula.license.length > 1
|
|
|
|
formula.license
|
|
|
|
else
|
|
|
|
"\"#{formula.license.first}\""
|
|
|
|
end
|
2020-07-12 20:05:27 -07:00
|
|
|
# insert replacement revision after license
|
|
|
|
<<~EOS
|
2020-07-30 09:30:44 -04:00
|
|
|
license #{license_string}
|
2020-07-12 20:05:27 -07:00
|
|
|
EOS
|
|
|
|
elsif formula.path.read.include?("stable do\n")
|
2020-04-25 00:32:13 -04:00
|
|
|
# insert replacement revision after homepage
|
|
|
|
<<~EOS
|
|
|
|
homepage "#{formula.homepage}"
|
|
|
|
EOS
|
|
|
|
elsif hash_type
|
2019-03-31 19:06:29 -04:00
|
|
|
# insert replacement revision after hash
|
2020-03-13 21:15:06 +00:00
|
|
|
<<~EOS
|
2019-03-31 19:06:29 -04:00
|
|
|
#{hash_type} "#{old_hash}"
|
|
|
|
EOS
|
|
|
|
else
|
|
|
|
# insert replacement revision after :revision
|
2020-03-13 21:15:06 +00:00
|
|
|
<<~EOS
|
2020-07-30 09:32:29 -04:00
|
|
|
revision: "#{formula_spec.specs[:revision]}"
|
2019-03-31 19:06:29 -04:00
|
|
|
EOS
|
|
|
|
end
|
2020-04-26 15:11:31 +01:00
|
|
|
replacement = old + " revision 1\n"
|
2019-03-31 19:06:29 -04:00
|
|
|
|
|
|
|
else
|
|
|
|
old = "revision #{current_revision}"
|
|
|
|
replacement = "revision #{current_revision+1}"
|
|
|
|
end
|
|
|
|
|
|
|
|
if args.dry_run?
|
2020-03-04 17:28:24 +00:00
|
|
|
ohai "replace #{old.inspect} with #{replacement.inspect}" unless args.quiet?
|
2019-03-31 19:06:29 -04:00
|
|
|
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",
|
2019-05-14 12:03:06 -04:00
|
|
|
"--message=#{message}", "--", formula.path
|
2019-03-31 19:06:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|