Skip to content

Commit af3bf61

Browse files
Ensure all trailers remain after Change-Id
Previously, only "Co-authored-by" appeared before Chang-Id, while other trailers (e.g., Signed-off-by, Reviewed-by) were placed after it. This change ensures that all trailers consistently appear before Change-Id. Co-authored-by: EricccTaiwan <[email protected]> Change-Id: I12c391c4ced8e200f26f53c34fc0e877b7af8561
1 parent edd54e1 commit af3bf61

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

scripts/commit-msg.hook

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -611,35 +611,30 @@ add_change_id() {
611611
print lines "\n"
612612
lines = ""
613613
}
614-
changeIdAfter = "^(" tolower("'"$CHANGE_ID_AFTER"'") "):"
614+
615615
numlines = split(lines, footer, "\n")
616616
617-
# Find the last line that starts with a comment character.
618-
coauthorIndex = 0
619-
for (line = 1; line <= numlines; line++) {
620-
if (match(tolower(footer[line]), /^co-authored-by:/)) {
621-
coauthorIndex = line
622-
}
623-
}
617+
trailers = ""
618+
other_footer = ""
624619
625620
for (line = 1; line <= numlines; line++) {
626-
if (unprinted && match(tolower(footer[line]), changeIdAfter) != 1) {
627-
# If the Change-Id is the first line in the footer, print it first.
628-
if (coauthorIndex == 0 || line > coauthorIndex) {
629-
print "Change-Id: I'"$id"'"
630-
unprinted = 0
631-
}
621+
if (match(tolower(footer[line]), /^(signed-off-by|acked-by|co-authored-by|reviewed-by|tested-by|suggested-by|reported-by):/)) {
622+
trailers = trailers footer[line] "\n"
623+
} else {
624+
other_footer = other_footer footer[line] "\n"
632625
}
633-
print footer[line]
626+
}
634627
635-
if(line == coauthorIndex && unprinted) {
636-
print "Change-Id: I'"$id"'"
637-
unprinted = 0
638-
}
628+
if (other_footer != "") {
629+
printf "%s", other_footer
639630
}
640-
if (unprinted) {
641-
print "Change-Id: I'"$id"'"
631+
632+
if (trailers != "") {
633+
printf "%s", trailers
642634
}
635+
636+
printf "Change-Id: I'"$id"'\n"
637+
643638
}' "$MSG" > "$T" && mv "$T" "$MSG" || rm -f "$T"
644639
}
645640

0 commit comments

Comments
 (0)