From 59cfef6db02a4c43c9ab777c17ce3cafd6803c8c Mon Sep 17 00:00:00 2001 From: EricFromCanada <enk3@outlook.com> Date: Tue, 8 Dec 2020 21:54:03 -0500 Subject: [PATCH] bump-formula-pr: handle additional edge cases --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 63 +++++++++++++++------ docs/Manpage.md | 2 +- manpages/brew.1 | 2 +- 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 19e28f8f32..33bbe3c42a 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -70,8 +70,8 @@ module Homebrew flag "--tag=", description: "Specify the new git commit <tag> for the formula." flag "--revision=", - depends_on: "--tag=", - description: "Specify the new git commit <revision> corresponding to the specified <tag>." + description: "Specify the new commit <revision> corresponding to the specified git <tag> "\ + "or specified <version>." switch "-f", "--force", description: "Ignore duplicate open PRs. Remove all mirrors if `--mirror` was not specified." @@ -121,6 +121,10 @@ module Homebrew def bump_formula_pr args = bump_formula_pr_args.parse + if args.revision.present? && args.tag.nil? && args.version.nil? + raise UsageError, "`--revision` must be passed with either `--tag` or `--version`!" + end + # As this command is simplifying user-run commands then let's just use a # user path, too. ENV["PATH"] = ENV["HOMEBREW_PATH"] @@ -177,21 +181,28 @@ module Homebrew check_closed_pull_requests(formula, tap_full_name, url: old_url, tag: new_tag, args: args) unless new_version false elsif !hash_type - odie "#{formula}: no --tag= or --version= argument specified!" if !new_tag && !new_version - new_tag ||= old_tag.gsub(old_version, new_version) - if new_tag == old_tag - odie <<~EOS - You need to bump this formula manually since the new tag - and old tag are both #{new_tag}. - EOS + if !new_tag && !new_version && !new_revision + raise UsageError, "#{formula}: no --tag= or --version= argument specified!" + end + + if old_tag + new_tag ||= old_tag.gsub(old_version, new_version) + if new_tag == old_tag + odie <<~EOS + You need to bump this formula manually since the new tag + and old tag are both #{new_tag}. + EOS + end + check_closed_pull_requests(formula, tap_full_name, url: old_url, tag: new_tag, args: args) unless new_version + resource_path, forced_version = fetch_resource(formula, new_version, old_url, tag: new_tag) + new_revision = Utils.popen_read("git -C \"#{resource_path}\" rev-parse -q --verify HEAD") + new_revision = new_revision.strip + else + odie "#{formula}: the current URL requires specifying a --revision= argument." unless new_revision end - check_closed_pull_requests(formula, tap_full_name, url: old_url, tag: new_tag, args: args) unless new_version - resource_path, forced_version = fetch_resource(formula, new_version, old_url, tag: new_tag) - new_revision = Utils.popen_read("git -C \"#{resource_path}\" rev-parse -q --verify HEAD") - new_revision = new_revision.strip false elsif !new_url && !new_version - odie "#{formula}: no --url= or --version= argument specified!" + raise UsageError, "#{formula}: no --url= or --version= argument specified!" else new_url ||= PyPI.update_pypi_url(old_url, new_version) unless new_url @@ -241,7 +252,7 @@ module Homebrew new_hash, ], ] - else + elsif new_tag [ [ formula_spec.specs[:tag], @@ -252,6 +263,24 @@ module Homebrew new_revision, ], ] + elsif new_url + [ + [ + /#{Regexp.escape(formula_spec.url)}/, + new_url, + ], + [ + formula_spec.specs[:revision], + new_revision, + ], + ] + else + [ + [ + formula_spec.specs[:revision], + new_revision, + ], + ] end old_contents = File.read(formula.path) unless args.dry_run? @@ -312,8 +341,8 @@ module Homebrew if new_formula_version < old_formula_version formula.path.atomic_write(old_contents) unless args.dry_run? odie <<~EOS - You need to bump this formula manually since changing the - version from #{old_formula_version} to #{new_formula_version} would be a downgrade. + You 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 formula.path.atomic_write(old_contents) unless args.dry_run? diff --git a/docs/Manpage.md b/docs/Manpage.md index ed716a523b..bde9166613 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -889,7 +889,7 @@ nor vice versa. It must use whichever style specification the formula already us * `--tag`: Specify the new git commit *`tag`* for the formula. * `--revision`: - Specify the new git commit *`revision`* corresponding to the specified *`tag`*. + Specify the new commit *`revision`* corresponding to the specified git *`tag`* or specified *`version`*. * `-f`, `--force`: Ignore duplicate open PRs. Remove all mirrors if `--mirror` was not specified. diff --git a/manpages/brew.1 b/manpages/brew.1 index 5c4fd5506d..00f2879d1f 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1236,7 +1236,7 @@ Specify the new git commit \fItag\fR for the formula\. . .TP \fB\-\-revision\fR -Specify the new git commit \fIrevision\fR corresponding to the specified \fItag\fR\. +Specify the new commit \fIrevision\fR corresponding to the specified git \fItag\fR or specified \fIversion\fR\. . .TP \fB\-f\fR, \fB\-\-force\fR -- GitLab