Skip to content

Commit 85bd3fb

Browse files
committed
sync_default_gems.rb: Support log.showSignature case
1 parent 953e1ef commit 85bd3fb

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

tool/sync_default_gems.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,18 @@ def message_filter(repo, sha, input: ARGF)
454454
puts subject, "\n", log
455455
end
456456

457+
def log_format(format, args, &block)
458+
IO.popen(%W[git log --no-show-signature --format=#{format}] + args, "rb", &block)
459+
end
460+
457461
# Returns commit list as array of [commit_hash, subject].
458462
def commits_in_ranges(gem, repo, default_branch, ranges)
459463
# If -a is given, discover all commits since the last picked commit
460464
if ranges == true
461465
# \r? needed in the regex in case the commit has windows-style line endings (because e.g. we're running
462466
# tests on Windows)
463467
pattern = "https://github\.com/#{Regexp.quote(repo)}/commit/([0-9a-f]+)\r?$"
464-
log = IO.popen(%W"git log -E --grep=#{pattern} -n1 --format=%B", "rb", &:read)
468+
log = log_format('%B', %W"-E --grep=#{pattern} -n1", &:read)
465469
ranges = ["#{log[%r[#{pattern}\n\s*(?i:co-authored-by:.*)*\s*\Z], 1]}..#{gem}/#{default_branch}"]
466470
end
467471

@@ -471,7 +475,7 @@ def commits_in_ranges(gem, repo, default_branch, ranges)
471475
range = "#{range}~1..#{range}"
472476
end
473477

474-
IO.popen(%W"git log --format=%H,%s #{range} --", "rb") do |f|
478+
log_format('%H,%s', %W"#{range} --") do |f|
475479
f.read.split("\n").reverse.map{|commit| commit.split(',', 2)}
476480
end
477481
end
@@ -626,7 +630,7 @@ def pickup_commit(gem, sha, edit)
626630
end or return nil
627631

628632
# Amend the commit if RDoc references need to be replaced
629-
head = `git log --format=%H -1 HEAD`.chomp
633+
head = log_format('%H', %W"-1 HEAD", &:read).chomp
630634
system(*%w"git reset --quiet HEAD~ --")
631635
amend = replace_rdoc_ref_all
632636
system(*%W"git reset --quiet #{head} --")

tool/test/test_sync_default_gems.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,29 @@ def setup
9090
@target = nil
9191
pend "No git" unless system("git --version", out: IO::NULL)
9292
@testdir = Dir.mktmpdir("sync")
93-
@git_config = %W"HOME GIT_CONFIG_GLOBAL".each_with_object({}) {|k, c| c[k] = ENV[k]}
93+
user, email = "Ruby", "[email protected]"
94+
@git_config = %W"HOME USER GIT_CONFIG_GLOBAL GNUPGHOME".each_with_object({}) {|k, c| c[k] = ENV[k]}
9495
ENV["HOME"] = @testdir
96+
ENV["USER"] = user
97+
ENV["GNUPGHOME"] = @testdir + '/.gnupg'
98+
expire = EnvUtil.apply_timeout_scale(30).to_i
99+
# Generate a new unprotected key with default parameters that
100+
# expires after 30 seconds.
101+
if @gpgsign = system(*%w"gpg --quiet --batch --passphrase", "",
102+
"--quick-generate-key", email, *%W"default default seconds=#{expire}")
103+
# Fetch the generated public key.
104+
signingkey = IO.popen(%W"gpg --quiet --list-public-key #{email}", &:read)[/^pub .*\n +\K\h+/]
105+
end
95106
ENV["GIT_CONFIG_GLOBAL"] = @testdir + "/gitconfig"
96-
git(*%W"config --global user.email [email protected]")
97-
git(*%W"config --global user.name", "Ruby")
107+
git(*%W"config --global user.email", email)
108+
git(*%W"config --global user.name", user)
98109
git(*%W"config --global init.defaultBranch default")
110+
if signingkey
111+
git(*%W"config --global user.signingkey", signingkey)
112+
git(*%W"config --global commit.gpgsign true")
113+
git(*%W"config --global gpg.program gpg")
114+
git(*%W"config --global log.showSignature true")
115+
end
99116
@target = "sync-test"
100117
SyncDefaultGems::REPOSITORIES[@target] = ["ruby/#{@target}", "default"]
101118
@sha = {}
@@ -129,6 +146,9 @@ def setup
129146

130147
def teardown
131148
if @target
149+
if @gpgsign
150+
system(*%W"gpgconf --kill all")
151+
end
132152
Dir.chdir(@origdir)
133153
SyncDefaultGems::REPOSITORIES.delete(@target)
134154
ENV.update(@git_config)
@@ -168,7 +188,7 @@ def git(*commands, **opts)
168188
end
169189

170190
def top_commit(dir, format: "%H")
171-
IO.popen(%W[git log --format=#{format} -1], chdir: dir, &:read)&.chomp
191+
IO.popen(%W[git log --no-show-signature --format=#{format} -1], chdir: dir, &:read)&.chomp
172192
end
173193

174194
def assert_sync(commits = true, success: true, editor: nil)

0 commit comments

Comments
 (0)