diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 2a9759adeb..3924598f05 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -73,6 +73,8 @@ module Homebrew switch "--only-json-tab", depends_on: "--json", description: "When passed with `--json`, the tab will be written to the JSON file but not the bottle." + flag "--committer=", + description: "Specify a committer name and email in `git`'s standard author format." flag "--root-url=", description: "Use the specified as the root of the bottle's URL instead of Homebrew's default." @@ -619,9 +621,15 @@ module Homebrew path.atomic_write(formula_ast.process) unless args.no_commit? - Utils::Git.set_name_email! + Utils::Git.set_name_email!(committer: args.committer.blank?) Utils::Git.setup_gpg! + if (committer = args.committer) + committer = Utils.parse_author!(committer) + ENV["GIT_COMMITTER_NAME"] = committer[:name] + ENV["GIT_COMMITTER_EMAIL"] = committer[:email] + end + short_name = formula_name.split("/", -1).last pkg_version = bottle_hash["formula"]["pkg_version"] diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index fb4e67d4cc..201b108a59 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -44,6 +44,8 @@ module Homebrew switch "--warn-on-upload-failure", description: "Warn instead of raising an error if the bottle upload fails. "\ "Useful for repairing bottle uploads that previously failed." + flag "--committer=", + description: "Specify a committer name and email in `git`'s standard author format." flag "--message=", depends_on: "--autosquash", description: "Message to include when autosquashing revision bumps, deletions, and rebuilds." @@ -365,9 +367,15 @@ module Homebrew mirror_repo = args.bintray_mirror || "mirror" tap = Tap.fetch(args.tap || CoreTap.instance.name) - Utils::Git.set_name_email! + Utils::Git.set_name_email!(committer: args.committer.blank?) Utils::Git.setup_gpg! + if (committer = args.committer) + committer = Utils.parse_author!(committer) + ENV["GIT_COMMITTER_NAME"] = committer[:name] + ENV["GIT_COMMITTER_EMAIL"] = committer[:email] + end + args.named.uniq.each do |arg| arg = "#{tap.default_remote}/pull/#{arg}" if arg.to_i.positive? url_match = arg.match HOMEBREW_PULL_OR_COMMIT_URL_REGEX diff --git a/Library/Homebrew/dev-cmd/pr-upload.rb b/Library/Homebrew/dev-cmd/pr-upload.rb index e0d7e91e9c..fedb8eace6 100644 --- a/Library/Homebrew/dev-cmd/pr-upload.rb +++ b/Library/Homebrew/dev-cmd/pr-upload.rb @@ -30,6 +30,8 @@ module Homebrew switch "--warn-on-upload-failure", description: "Warn instead of raising an error if the bottle upload fails. "\ "Useful for repairing bottle uploads that previously failed." + flag "--committer=", + description: "Specify a committer name and email in `git`'s standard author format." flag "--archive-item=", description: "Upload to the specified Internet Archive item (default: `homebrew`)." flag "--bintray-org=", @@ -103,6 +105,7 @@ module Homebrew bottle_args << "--debug" if args.debug? bottle_args << "--keep-old" if args.keep_old? bottle_args << "--root-url=#{args.root_url}" if args.root_url + bottle_args << "--committer='#{args.committer}'" if args.committer bottle_args << "--no-commit" if args.no_commit? bottle_args += json_files diff --git a/Library/Homebrew/test/utils_spec.rb b/Library/Homebrew/test/utils_spec.rb index 380b1d3803..c54a886574 100644 --- a/Library/Homebrew/test/utils_spec.rb +++ b/Library/Homebrew/test/utils_spec.rb @@ -210,6 +210,19 @@ describe "globally-scoped helper methods" do end end + specify "#parse_author!" do + parse_error_msg = /Unable to parse name and email/ + + expect(parse_author!("John Doe ")) + .to eq({ name: "John Doe", email: "john.doe@example.com" }) + expect { parse_author!("") } + .to raise_error(parse_error_msg) + expect { parse_author!("John Doe") } + .to raise_error(parse_error_msg) + expect { parse_author!("") } + .to raise_error(parse_error_msg) + end + specify "#disk_usage_readable" do expect(disk_usage_readable(1)).to eq("1B") expect(disk_usage_readable(1000)).to eq("1000B") diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 01fee6c88a..0888e7f046 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -467,6 +467,13 @@ module Kernel end.uniq.compact end + def parse_author!(author) + /^(?[^<]+?)[ \t]*<(?[^>]+?)>$/ =~ author + raise "Unable to parse name and email." if name.blank? && email.blank? + + { name: name, email: email } + end + def disk_usage_readable(size_in_bytes) if size_in_bytes >= 1_073_741_824 size = size_in_bytes.to_f / 1_073_741_824