Unify and use Git username/email/GPG handling.

We're using essentially the same logic to setup Git for committing in
multiple places but the way we're doing so is inconsistent. Moved to
using two shared utility methods and use them consistently.
This commit is contained in:
Mike McQuaid 2020-11-02 12:21:18 +00:00
parent fd007219cc
commit 4f3c590873
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
4 changed files with 12 additions and 26 deletions

View File

@ -549,6 +549,7 @@ module Homebrew
unless args.no_commit? unless args.no_commit?
Utils::Git.set_name_email! Utils::Git.set_name_email!
Utils::Git.setup_gpg!
short_name = formula_name.split("/", -1).last short_name = formula_name.split("/", -1).last
pkg_version = bottle_hash["formula"]["pkg_version"] pkg_version = bottle_hash["formula"]["pkg_version"]

View File

@ -64,27 +64,6 @@ module Homebrew
end end
end end
def setup_git_environment!
# Passthrough Git environment variables
ENV["GIT_COMMITTER_NAME"] = ENV["HOMEBREW_GIT_NAME"] if ENV["HOMEBREW_GIT_NAME"]
ENV["GIT_COMMITTER_EMAIL"] = ENV["HOMEBREW_GIT_EMAIL"] if ENV["HOMEBREW_GIT_EMAIL"]
# Depending on user configuration, git may try to invoke gpg.
return unless Utils.popen_read("git config --get --bool commit.gpgsign").chomp == "true"
begin
gnupg = Formula["gnupg"]
rescue FormulaUnavailableError
nil
else
if gnupg.any_version_installed?
path = PATH.new(ENV.fetch("PATH"))
path.prepend(gnupg.any_installed_prefix/"bin")
ENV["PATH"] = path
end
end
end
# Separates a commit message into subject, body, and trailers. # Separates a commit message into subject, body, and trailers.
def separate_commit_message(message) def separate_commit_message(message)
subject = message.lines.first.strip subject = message.lines.first.strip
@ -375,7 +354,8 @@ module Homebrew
mirror_repo = args.bintray_mirror || "mirror" mirror_repo = args.bintray_mirror || "mirror"
tap = Tap.fetch(args.tap || CoreTap.instance.name) tap = Tap.fetch(args.tap || CoreTap.instance.name)
setup_git_environment! Utils::Git.set_name_email!
Utils::Git.setup_gpg!
args.named.uniq.each do |arg| args.named.uniq.each do |arg|
arg = "#{tap.default_remote}/pull/#{arg}" if arg.to_i.positive? arg = "#{tap.default_remote}/pull/#{arg}" if arg.to_i.positive?

View File

@ -35,10 +35,8 @@ module Homebrew
ohai "git add vendor/bundle" ohai "git add vendor/bundle"
system "git", "add", "vendor/bundle" system "git", "add", "vendor/bundle"
if Formula["gpg"].optlinked? Utils::Git.set_name_email!
ENV["PATH"] = PATH.new(ENV["PATH"]) Utils::Git.setup_gpg!
.prepend(Formula["gpg"].opt_bin)
end
ohai "git commit" ohai "git commit"
system "git", "commit", "--message", "brew vendor-gems: commit updates." system "git", "commit", "--message", "brew vendor-gems: commit updates."

View File

@ -126,6 +126,13 @@ module Utils
ENV["GIT_COMMITTER_EMAIL"] = Homebrew::EnvConfig.git_email if committer ENV["GIT_COMMITTER_EMAIL"] = Homebrew::EnvConfig.git_email if committer
end end
def setup_gpg!
return unless Formula["gnupg"].optlinked?
ENV["PATH"] = PATH.new(ENV["PATH"])
.prepend(Formula["gnupg"].opt_bin)
end
def origin_branch(repo) def origin_branch(repo)
Utils.popen_read(git, "-C", repo, "symbolic-ref", "-q", "--short", Utils.popen_read(git, "-C", repo, "symbolic-ref", "-q", "--short",
"refs/remotes/origin/HEAD").chomp.presence "refs/remotes/origin/HEAD").chomp.presence