Merge pull request #8606 from SeekingMeaning/bump-formula-pr/dry-run-write
bump-formula-pr: make `--dry-run` conflict with `--write`
This commit is contained in:
commit
2314ddf9f5
@ -32,9 +32,11 @@ module Homebrew
|
|||||||
switch "-n", "--dry-run",
|
switch "-n", "--dry-run",
|
||||||
description: "Print what would be done rather than doing it."
|
description: "Print what would be done rather than doing it."
|
||||||
switch "--write",
|
switch "--write",
|
||||||
depends_on: "--dry-run",
|
description: "Make the expected file modifications without taking any Git actions."
|
||||||
description: "When passed along with `--dry-run`, perform a not-so-dry run by making the expected "\
|
switch "--commit",
|
||||||
"file modifications but not taking any Git actions."
|
depends_on: "--write",
|
||||||
|
description: "When passed with `--write`, generate a new commit after writing changes "\
|
||||||
|
"to the formula file."
|
||||||
switch "--no-audit",
|
switch "--no-audit",
|
||||||
description: "Don't run `brew audit` before opening the PR."
|
description: "Don't run `brew audit` before opening the PR."
|
||||||
switch "--strict",
|
switch "--strict",
|
||||||
@ -66,6 +68,7 @@ module Homebrew
|
|||||||
switch "-f", "--force",
|
switch "-f", "--force",
|
||||||
description: "Ignore duplicate open PRs. Remove all mirrors if --mirror= was not specified."
|
description: "Ignore duplicate open PRs. Remove all mirrors if --mirror= was not specified."
|
||||||
|
|
||||||
|
conflicts "--dry-run", "--write"
|
||||||
conflicts "--no-audit", "--strict"
|
conflicts "--no-audit", "--strict"
|
||||||
conflicts "--url", "--tag"
|
conflicts "--url", "--tag"
|
||||||
max_named 1
|
max_named 1
|
||||||
@ -83,7 +86,7 @@ module Homebrew
|
|||||||
previous_branch = "master" if previous_branch.empty?
|
previous_branch = "master" if previous_branch.empty?
|
||||||
formula_path = formula.path.to_s[%r{(Formula/.*)}, 1]
|
formula_path = formula.path.to_s[%r{(Formula/.*)}, 1]
|
||||||
|
|
||||||
if args.dry_run?
|
if args.dry_run? || args.write?
|
||||||
ohai "git remote add #{homebrew_core_remote} #{homebrew_core_url}"
|
ohai "git remote add #{homebrew_core_remote} #{homebrew_core_url}"
|
||||||
ohai "git fetch #{homebrew_core_remote} #{homebrew_core_branch}"
|
ohai "git fetch #{homebrew_core_remote} #{homebrew_core_branch}"
|
||||||
ohai "git cat-file -e #{origin_branch}:#{formula_path}"
|
ohai "git cat-file -e #{origin_branch}:#{formula_path}"
|
||||||
@ -245,8 +248,7 @@ module Homebrew
|
|||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
read_only_run = args.dry_run? && !args.write?
|
old_contents = File.read(formula.path) unless args.dry_run?
|
||||||
old_contents = File.read(formula.path) unless read_only_run
|
|
||||||
|
|
||||||
if new_mirrors
|
if new_mirrors
|
||||||
replacement_pairs << [
|
replacement_pairs << [
|
||||||
@ -296,7 +298,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
new_contents = Utils::Inreplace.inreplace_pairs(formula.path,
|
new_contents = Utils::Inreplace.inreplace_pairs(formula.path,
|
||||||
replacement_pairs.uniq.compact,
|
replacement_pairs.uniq.compact,
|
||||||
read_only_run: read_only_run,
|
read_only_run: args.dry_run?,
|
||||||
silent: args.quiet?)
|
silent: args.quiet?)
|
||||||
|
|
||||||
new_formula_version = formula_version(formula, requested_spec, new_contents)
|
new_formula_version = formula_version(formula, requested_spec, new_contents)
|
||||||
@ -313,13 +315,13 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
if new_formula_version < old_formula_version
|
if new_formula_version < old_formula_version
|
||||||
formula.path.atomic_write(old_contents) unless read_only_run
|
formula.path.atomic_write(old_contents) unless args.dry_run?
|
||||||
odie <<~EOS
|
odie <<~EOS
|
||||||
You need to bump this formula manually since changing the
|
You need to bump this formula manually since changing the
|
||||||
version from #{old_formula_version} to #{new_formula_version} would be a downgrade.
|
version from #{old_formula_version} to #{new_formula_version} would be a downgrade.
|
||||||
EOS
|
EOS
|
||||||
elsif new_formula_version == old_formula_version
|
elsif new_formula_version == old_formula_version
|
||||||
formula.path.atomic_write(old_contents) unless read_only_run
|
formula.path.atomic_write(old_contents) unless args.dry_run?
|
||||||
odie <<~EOS
|
odie <<~EOS
|
||||||
You need to bump this formula manually since the new version
|
You need to bump this formula manually since the new version
|
||||||
and old version are both #{new_formula_version}.
|
and old version are both #{new_formula_version}.
|
||||||
@ -332,7 +334,7 @@ module Homebrew
|
|||||||
alias_rename.map! { |a| formula.tap.alias_dir/a }
|
alias_rename.map! { |a| formula.tap.alias_dir/a }
|
||||||
end
|
end
|
||||||
|
|
||||||
unless read_only_run
|
unless args.dry_run?
|
||||||
PyPI.update_python_resources! formula, new_formula_version, silent: args.quiet?, ignore_non_pypi_packages: true
|
PyPI.update_python_resources! formula, new_formula_version, silent: args.quiet?, ignore_non_pypi_packages: true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -346,7 +348,7 @@ module Homebrew
|
|||||||
changed_files = [formula.path]
|
changed_files = [formula.path]
|
||||||
changed_files += alias_rename if alias_rename.present?
|
changed_files += alias_rename if alias_rename.present?
|
||||||
|
|
||||||
if args.dry_run?
|
if args.dry_run? || (args.write? && !args.commit?)
|
||||||
ohai "try to fork repository with GitHub API" unless args.no_fork?
|
ohai "try to fork repository with GitHub API" unless args.no_fork?
|
||||||
ohai "git fetch --unshallow origin" if shallow
|
ohai "git fetch --unshallow origin" if shallow
|
||||||
ohai "git add #{alias_rename.first} #{alias_rename.last}" if alias_rename.present?
|
ohai "git add #{alias_rename.first} #{alias_rename.last}" if alias_rename.present?
|
||||||
@ -358,24 +360,15 @@ module Homebrew
|
|||||||
ohai "create pull request with GitHub API (base branch: #{base_branch})"
|
ohai "create pull request with GitHub API (base branch: #{base_branch})"
|
||||||
else
|
else
|
||||||
|
|
||||||
if args.no_fork?
|
safe_system "git", "fetch", "--unshallow", "origin" if shallow && !args.commit?
|
||||||
remote_url = Utils.popen_read("git remote get-url --push origin").chomp
|
|
||||||
username = formula.tap.user
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
remote_url, username = GitHub.forked_repo_info!(tap_full_name)
|
|
||||||
rescue *GitHub.api_errors => e
|
|
||||||
formula.path.atomic_write(old_contents)
|
|
||||||
odie "Unable to fork: #{e.message}!"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
safe_system "git", "fetch", "--unshallow", "origin" if shallow
|
|
||||||
safe_system "git", "add", *alias_rename if alias_rename.present?
|
safe_system "git", "add", *alias_rename if alias_rename.present?
|
||||||
safe_system "git", "checkout", "--no-track", "-b", branch, origin_branch
|
safe_system "git", "checkout", "--no-track", "-b", branch, origin_branch unless args.commit?
|
||||||
safe_system "git", "commit", "--no-edit", "--verbose",
|
safe_system "git", "commit", "--no-edit", "--verbose",
|
||||||
"--message=#{formula.name} #{new_formula_version}",
|
"--message=#{formula.name} #{new_formula_version}",
|
||||||
"--", *changed_files
|
"--", *changed_files
|
||||||
|
return if args.commit?
|
||||||
|
|
||||||
|
remote_url, username = determine_remote_and_username(formula, tap_full_name, old_contents, args: args)
|
||||||
safe_system "git", "push", "--set-upstream", remote_url, "#{branch}:#{branch}"
|
safe_system "git", "push", "--set-upstream", remote_url, "#{branch}:#{branch}"
|
||||||
safe_system "git", "checkout", "--quiet", previous_branch
|
safe_system "git", "checkout", "--quiet", previous_branch
|
||||||
pr_message = <<~EOS
|
pr_message = <<~EOS
|
||||||
@ -514,4 +507,19 @@ module Homebrew
|
|||||||
FileUtils.mv alias_rename.last, alias_rename.first if alias_rename.present?
|
FileUtils.mv alias_rename.last, alias_rename.first if alias_rename.present?
|
||||||
odie "`brew audit` failed!"
|
odie "`brew audit` failed!"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def determine_remote_and_username(formula, tap_full_name, old_contents, args:)
|
||||||
|
if args.no_fork?
|
||||||
|
remote_url = Utils.popen_read("git remote get-url --push origin").chomp
|
||||||
|
username = formula.tap.user
|
||||||
|
[remote_url, username]
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
GitHub.forked_repo_info!(tap_full_name)
|
||||||
|
rescue *GitHub.api_errors => e
|
||||||
|
formula.path.atomic_write(old_contents)
|
||||||
|
odie "Unable to fork: #{e.message}!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -841,7 +841,9 @@ nor vice versa. It must use whichever style specification the formula already us
|
|||||||
* `-n`, `--dry-run`:
|
* `-n`, `--dry-run`:
|
||||||
Print what would be done rather than doing it.
|
Print what would be done rather than doing it.
|
||||||
* `--write`:
|
* `--write`:
|
||||||
When passed along with `--dry-run`, perform a not-so-dry run by making the expected file modifications but not taking any Git actions.
|
Make the expected file modifications without taking any Git actions.
|
||||||
|
* `--commit`:
|
||||||
|
When passed with `--write`, generate a new commit after writing changes to the formula file.
|
||||||
* `--no-audit`:
|
* `--no-audit`:
|
||||||
Don't run `brew audit` before opening the PR.
|
Don't run `brew audit` before opening the PR.
|
||||||
* `--strict`:
|
* `--strict`:
|
||||||
|
|||||||
@ -1155,7 +1155,11 @@ Print what would be done rather than doing it\.
|
|||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-write\fR
|
\fB\-\-write\fR
|
||||||
When passed along with \fB\-\-dry\-run\fR, perform a not\-so\-dry run by making the expected file modifications but not taking any Git actions\.
|
Make the expected file modifications without taking any Git actions\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-\-commit\fR
|
||||||
|
When passed with \fB\-\-write\fR, generate a new commit after writing changes to the formula file\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-no\-audit\fR
|
\fB\-\-no\-audit\fR
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user