Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump-formula-pr: handle additional edge cases #9475

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 46 additions & 17 deletions Library/Homebrew/dev-cmd/bump-formula-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def bump_formula_pr_args
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."

Expand Down Expand Up @@ -121,6 +121,10 @@ def use_correct_linux_tap(formula, args:)
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"]
Expand Down Expand Up @@ -177,21 +181,28 @@ def bump_formula_pr
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
Expand Down Expand Up @@ -241,7 +252,7 @@ def bump_formula_pr
new_hash,
],
]
else
elsif new_tag
[
[
formula_spec.specs[:tag],
Expand All @@ -252,6 +263,24 @@ def bump_formula_pr
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?
Expand Down Expand Up @@ -312,8 +341,8 @@ def bump_formula_pr
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?
Expand Down
2 changes: 1 addition & 1 deletion docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down