From ccde62082b0af08582f3d00ebf1e2b2426f9c814 Mon Sep 17 00:00:00 2001 From: Seeker <meaningseeking@protonmail.com> Date: Mon, 7 Sep 2020 10:22:08 -0700 Subject: [PATCH] bump-formula-pr: update mirrors automatically --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 34 ++++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 4f6153a87c..f98e505216 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -145,20 +145,12 @@ module Homebrew formula_spec = formula.stable odie "#{formula}: no #{requested_spec} specification found!" unless formula_spec + old_mirrors = formula_spec.mirrors new_mirrors ||= args.mirror new_mirror ||= determine_mirror(new_url) new_mirrors ||= [new_mirror] unless new_mirror.nil? - if !new_mirrors && !formula_spec.mirrors.empty? - if args.force? - opoo "#{formula}: Removing all mirrors because a --mirror= argument was not specified." - else - odie <<~EOS - #{formula}: a --mirror= argument for updating the mirror URL was not specified. - Use --force to remove all mirrors. - EOS - end - end + check_for_mirrors(formula, old_mirrors, new_mirrors, args: args) if new_url hash_type, old_hash = if (checksum = formula_spec.checksum) [checksum.hash_type, checksum.hexdigest] @@ -196,7 +188,14 @@ module Homebrew odie "#{formula}: no --url= or --version= argument specified!" else new_url ||= PyPI.update_pypi_url(old_url, new_version) - new_url ||= old_url.gsub(old_version, new_version) + unless new_url + new_url = old_url.gsub(old_version, new_version) + if !new_mirrors && !old_mirrors.empty? + new_mirrors = old_mirrors.map do |old_mirror| + old_mirror.gsub(old_version, new_version) + end + end + end if new_url == old_url odie <<~EOS You need to bump this formula manually since the new URL @@ -389,6 +388,19 @@ module Homebrew end end + def check_for_mirrors(formula, old_mirrors, new_mirrors, args:) + return if new_mirrors || old_mirrors.empty? + + if args.force? + opoo "#{formula}: Removing all mirrors because a --mirror= argument was not specified." + else + odie <<~EOS + #{formula}: a --mirror= argument for updating the mirror URL(s) was not specified. + Use --force to remove all mirrors. + EOS + end + end + def fetch_resource(formula, new_version, url, **specs) resource = Resource.new resource.url(url, specs) -- GitLab