Skip to content

Commit

Permalink
Merge pull request #9030 from MikeMcQuaid/gpg-tweaks
Browse files Browse the repository at this point in the history
Unify and use Git username/email/GPG handling.
  • Loading branch information
MikeMcQuaid authored Nov 2, 2020
2 parents 5eebe35 + 4f3c590 commit 05bbb41
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
1 change: 1 addition & 0 deletions Library/Homebrew/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ def merge(args:)

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"]
Expand Down
24 changes: 2 additions & 22 deletions Library/Homebrew/dev-cmd/pr-pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,6 @@ def pr_pull_args
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
Expand Down Expand Up @@ -375,7 +354,8 @@ def pr_pull
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?
Expand Down
6 changes: 2 additions & 4 deletions Library/Homebrew/dev-cmd/vendor-gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ def vendor_gems
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."
Expand Down
7 changes: 7 additions & 0 deletions Library/Homebrew/utils/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ def set_name_email!(author: true, committer: true)
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
Expand Down

0 comments on commit 05bbb41

Please sign in to comment.