Skip to content
Snippets Groups Projects
Unverified Commit 4f3c5908 authored by Mike McQuaid's avatar Mike McQuaid
Browse files

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.
parent fd007219
No related branches found
No related tags found
No related merge requests found
......@@ -549,6 +549,7 @@ module Homebrew
unless args.no_commit?
Utils::Git.set_name_email!
Utils::Git.setup_gpg!
short_name = formula_name.split("/", -1).last
pkg_version = bottle_hash["formula"]["pkg_version"]
......
......@@ -64,27 +64,6 @@ module Homebrew
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.
def separate_commit_message(message)
subject = message.lines.first.strip
......@@ -375,7 +354,8 @@ module Homebrew
mirror_repo = args.bintray_mirror || "mirror"
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|
arg = "#{tap.default_remote}/pull/#{arg}" if arg.to_i.positive?
......
......@@ -35,10 +35,8 @@ module Homebrew
ohai "git add vendor/bundle"
system "git", "add", "vendor/bundle"
if Formula["gpg"].optlinked?
ENV["PATH"] = PATH.new(ENV["PATH"])
.prepend(Formula["gpg"].opt_bin)
end
Utils::Git.set_name_email!
Utils::Git.setup_gpg!
ohai "git commit"
system "git", "commit", "--message", "brew vendor-gems: commit updates."
......
......@@ -126,6 +126,13 @@ module Utils
ENV["GIT_COMMITTER_EMAIL"] = Homebrew::EnvConfig.git_email if committer
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)
Utils.popen_read(git, "-C", repo, "symbolic-ref", "-q", "--short",
"refs/remotes/origin/HEAD").chomp.presence
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment