bump-formula-pr: reflect new version in dry-run
- simulate version change for dry-run - make sure we're using :devel version if called with --devel Closes #318. Signed-off-by: ilovezfs <ilovezfs@icloud.com>
This commit is contained in:
parent
01e8e180a8
commit
cc0ca73183
@ -15,6 +15,39 @@
|
||||
require "formula"
|
||||
|
||||
module Homebrew
|
||||
def inreplace_pairs(path, replacement_pairs)
|
||||
if ARGV.dry_run?
|
||||
contents = path.open("r") { |f| Formulary.set_encoding(f).read }
|
||||
contents.extend(StringInreplaceExtension)
|
||||
replacement_pairs.each do |old, new|
|
||||
ohai "replace \"#{old}\" with \"#{new}\"" unless ARGV.flag?("--quiet")
|
||||
contents.gsub!(old, new)
|
||||
end
|
||||
if contents.errors.any?
|
||||
raise Utils::InreplaceError, path => contents.errors
|
||||
end
|
||||
contents
|
||||
else
|
||||
Utils::Inreplace.inreplace(path) do |s|
|
||||
replacement_pairs.each do |old, new|
|
||||
ohai "replace \"#{old}\" with \"#{new}\"" unless ARGV.flag?("--quiet")
|
||||
s.gsub!(old, new)
|
||||
end
|
||||
end
|
||||
path.open("r") { |f| Formulary.set_encoding(f).read }
|
||||
end
|
||||
end
|
||||
|
||||
def formula_version(formula, spec, contents = nil)
|
||||
name = formula.name
|
||||
path = formula.path
|
||||
if contents
|
||||
Formulary.from_contents(name, path, contents, spec).version
|
||||
else
|
||||
Formulary::FormulaLoader.new(name, path).get_formula(spec).version
|
||||
end
|
||||
end
|
||||
|
||||
def bump_formula_pr
|
||||
formula = ARGV.formulae.first
|
||||
odie "No formula found!" unless formula
|
||||
@ -51,32 +84,35 @@ module Homebrew
|
||||
safe_system "brew", "update"
|
||||
end
|
||||
|
||||
Utils::Inreplace.inreplace(formula.path) do |s|
|
||||
if new_url_hash
|
||||
old_url = formula_spec.url
|
||||
if ARGV.dry_run?
|
||||
ohai "replace '#{old_url}' with '#{new_url}'"
|
||||
ohai "replace '#{old_hash}' with '#{new_hash}'"
|
||||
else
|
||||
s.gsub!(old_url, new_url)
|
||||
s.gsub!(old_hash, new_hash)
|
||||
end
|
||||
else
|
||||
resource_specs = formula_spec.specs
|
||||
old_tag = resource_specs[:tag]
|
||||
old_revision = resource_specs[:revision]
|
||||
if ARGV.dry_run?
|
||||
ohai "replace '#{old_tag}' with '#{new_tag}'"
|
||||
ohai "replace '#{old_revision}' with '#{new_revision}'"
|
||||
else
|
||||
s.gsub!(/['"]#{old_tag}['"]/, "\"#{new_tag}\"")
|
||||
s.gsub!(old_revision, new_revision)
|
||||
end
|
||||
end
|
||||
old_formula_version = formula_version(formula, requested_spec)
|
||||
|
||||
replacement_pairs = if new_url_hash
|
||||
[
|
||||
[formula_spec.url, new_url],
|
||||
[old_hash, new_hash],
|
||||
]
|
||||
else
|
||||
[
|
||||
[formula_spec.specs[:tag], new_tag],
|
||||
[formula_spec.specs[:revision], new_revision],
|
||||
]
|
||||
end
|
||||
|
||||
new_formula = Formulary.load_formula_from_path(formula.name, formula.path)
|
||||
new_formula_version = new_formula.version
|
||||
new_contents = inreplace_pairs(formula.path, replacement_pairs)
|
||||
|
||||
new_formula_version = formula_version(formula, requested_spec, new_contents)
|
||||
|
||||
if new_formula_version < old_formula_version
|
||||
odie <<-EOS.undent
|
||||
You probably need to bump this formula manually since changing the
|
||||
version from #{old_formula_version} to #{new_formula_version} would be a downgrade.
|
||||
EOS
|
||||
elsif new_formula_version == old_formula_version
|
||||
odie <<-EOS.undent
|
||||
You probably need to bump this formula manually since the new version
|
||||
and old version are both #{new_formula_version}.
|
||||
EOS
|
||||
end
|
||||
|
||||
unless Formula["hub"].any_version_installed?
|
||||
if ARGV.dry_run?
|
||||
|
Loading…
x
Reference in New Issue
Block a user