git_extensions: move commit_message from utils/git
This commit is contained in:
parent
92d3eda914
commit
8b206dfa33
@ -89,7 +89,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
def signoff!(path, pr: nil, dry_run: false)
|
||||
subject, body, trailers = separate_commit_message(Utils::Git.commit_message(path))
|
||||
subject, body, trailers = separate_commit_message(path.git_commit_message)
|
||||
|
||||
if pr
|
||||
# This is a tap pull request and approving reviewers should also sign-off.
|
||||
@ -156,7 +156,7 @@ module Homebrew
|
||||
new_formula = Utils::Git.file_at_commit(path, file, "HEAD")
|
||||
|
||||
bump_subject = determine_bump_subject(old_formula, new_formula, formula_file, reason: reason).strip
|
||||
subject, body, trailers = separate_commit_message(Utils::Git.commit_message(path))
|
||||
subject, body, trailers = separate_commit_message(path.git_commit_message)
|
||||
|
||||
if subject != bump_subject && !subject.start_with?("#{formula_name}:")
|
||||
safe_system("git", "-C", path, "commit", "--amend", "-q",
|
||||
@ -181,7 +181,7 @@ module Homebrew
|
||||
messages = []
|
||||
trailers = []
|
||||
commits.each do |commit|
|
||||
subject, body, trailer = separate_commit_message(Utils::Git.commit_message(path, commit))
|
||||
subject, body, trailer = separate_commit_message(path.git_commit_message(commit))
|
||||
body = body.lines.map { |line| " #{line.strip}" }.join("\n")
|
||||
messages << "* #{subject}\n#{body}".strip
|
||||
trailers << trailer
|
||||
|
@ -85,4 +85,12 @@ module GitRepositoryExtension
|
||||
|
||||
Utils.popen_read("git", "show", "-s", "--format=%cd", "--date=short", "HEAD", chdir: self).chomp.presence
|
||||
end
|
||||
|
||||
# Gets the full commit message of the specified commit, or of the HEAD commit if unspecified.
|
||||
sig { params(commit: String).returns(T.nilable(String)) }
|
||||
def git_commit_message(commit = "HEAD")
|
||||
return unless git? && Utils::Git.available?
|
||||
|
||||
Utils.popen_read("git", "log", "-1", "--pretty=%B", commit, "--", chdir: self, err: :out).strip.presence
|
||||
end
|
||||
end
|
||||
|
@ -38,7 +38,7 @@ describe Homebrew do
|
||||
EOS
|
||||
end
|
||||
let(:formula_file) { path/"Formula/foo.rb" }
|
||||
let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" }
|
||||
let(:path) { (Tap::TAP_DIRECTORY/"homebrew/homebrew-foo").extend(GitRepositoryExtension) }
|
||||
|
||||
describe "Homebrew.pr_pull_args" do
|
||||
it_behaves_like "parseable arguments"
|
||||
@ -59,8 +59,8 @@ describe Homebrew do
|
||||
File.open(formula_file, "w") { |f| f.write(formula_version) }
|
||||
safe_system Utils::Git.git, "commit", formula_file, "-m", "version", "--author=#{secondary_author}"
|
||||
described_class.autosquash!(original_hash, path: path)
|
||||
expect(Utils::Git.commit_message(path)).to include("foo 2.0")
|
||||
expect(Utils::Git.commit_message(path)).to include("Co-authored-by: #{secondary_author}")
|
||||
expect(path.git_commit_message).to include("foo 2.0")
|
||||
expect(path.git_commit_message).to include("Co-authored-by: #{secondary_author}")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -75,7 +75,7 @@ describe Homebrew do
|
||||
safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)"
|
||||
end
|
||||
described_class.signoff!(path)
|
||||
expect(Utils::Git.commit_message(path)).to include("Signed-off-by:")
|
||||
expect(path.git_commit_message).to include("Signed-off-by:")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -52,19 +52,6 @@ describe Utils::Git do
|
||||
let(:files_hash2) { [@h2[0..6], ["README.md"]] }
|
||||
let(:cherry_pick_commit) { @cherry_pick_commit[0..6] }
|
||||
|
||||
describe "#commit_message" do
|
||||
it "returns the commit message" do
|
||||
expect(described_class.commit_message(HOMEBREW_CACHE, file_hash1)).to eq("File added")
|
||||
expect(described_class.commit_message(HOMEBREW_CACHE, file_hash2)).to eq("written to File")
|
||||
end
|
||||
|
||||
it "errors when commit doesn't exist" do
|
||||
expect {
|
||||
described_class.commit_message(HOMEBREW_CACHE, "bad_refspec")
|
||||
}.to raise_error(ErrorDuringExecution, /bad revision/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#cherry_pick!" do
|
||||
it "can cherry pick a commit" do
|
||||
expect(described_class.cherry_pick!(HOMEBREW_CACHE, cherry_pick_commit)).to be_truthy
|
||||
|
@ -89,8 +89,9 @@ module Utils
|
||||
end
|
||||
|
||||
def commit_message(repo, commit = nil)
|
||||
odeprecated "Utils::Git.commit_message(repo)", "Pathname(repo).git_commit_message"
|
||||
commit ||= "HEAD"
|
||||
Utils.safe_popen_read(git, "-C", repo, "log", "-1", "--pretty=%B", commit, "--", err: :out).strip
|
||||
Pathname(repo).extend(GitRepositoryExtension).git_commit_message(commit)
|
||||
end
|
||||
|
||||
def ensure_installed!
|
||||
|
Loading…
x
Reference in New Issue
Block a user