pr-pull: preserve trailers when signing off commit
This commit is contained in:
parent
3a7213c255
commit
ee9c335b51
@ -70,12 +70,22 @@ module Homebrew
|
|||||||
|
|
||||||
def signoff!(pr, path: ".")
|
def signoff!(pr, path: ".")
|
||||||
message = Utils.popen_read "git", "-C", path, "log", "-1", "--pretty=%B"
|
message = Utils.popen_read "git", "-C", path, "log", "-1", "--pretty=%B"
|
||||||
|
subject = message.lines.first.strip
|
||||||
|
|
||||||
|
# Skip the subject and separate lines that look like trailers (e.g. "Co-authored-by")
|
||||||
|
# from lines that look like regular body text.
|
||||||
|
trailers, body = message.lines.drop(1).partition { |s| s.match?(/^[a-z-]+-by:/i) }
|
||||||
|
trailers = trailers.uniq.join.strip
|
||||||
|
body = body.join.strip.gsub(/\n{3,}/, "\n\n")
|
||||||
|
|
||||||
close_message = "Closes ##{pr}."
|
close_message = "Closes ##{pr}."
|
||||||
message += "\n#{close_message}" unless message.include? close_message
|
body += "\n\n#{close_message}" unless body.include? close_message
|
||||||
|
new_message = [subject, body, trailers].join("\n\n").strip
|
||||||
|
|
||||||
if Homebrew.args.dry_run?
|
if Homebrew.args.dry_run?
|
||||||
puts "git commit --amend --signoff -m $message"
|
puts "git commit --amend --signoff -m $message"
|
||||||
else
|
else
|
||||||
safe_system "git", "-C", path, "commit", "--amend", "--signoff", "--allow-empty", "-q", "-m", message
|
safe_system "git", "-C", path, "commit", "--amend", "--signoff", "--allow-empty", "-q", "-m", new_message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user