From 4f3c5908731b54cfc10bbbc509e5064729155d2b Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 2 Nov 2020 12:21:18 +0000 Subject: [PATCH] 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. --- Library/Homebrew/dev-cmd/bottle.rb | 1 + Library/Homebrew/dev-cmd/pr-pull.rb | 24 ++---------------------- Library/Homebrew/dev-cmd/vendor-gems.rb | 6 ++---- Library/Homebrew/utils/git.rb | 7 +++++++ 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index e9b9e4b157f4a..9198dd67b835e 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -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"] diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index b4dfd27e97a14..9ff0229c155f2 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -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 @@ -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? diff --git a/Library/Homebrew/dev-cmd/vendor-gems.rb b/Library/Homebrew/dev-cmd/vendor-gems.rb index c336427a40bbf..f42945f2b2d93 100644 --- a/Library/Homebrew/dev-cmd/vendor-gems.rb +++ b/Library/Homebrew/dev-cmd/vendor-gems.rb @@ -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." diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index e2f592d431f38..59025a3064a69 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -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