Skip to content

Commit ba8814c

Browse files
Correct order of Co-authored-by in commit footer
This fix ensures that 'Co-authored-by' is properly placed above 'change-Id' in the commit footer. Co-authored-by: EricccTaiwan <[email protected]> Change-Id: I856457b5575a967096ad71c9e4271b45b8d1400a
1 parent 4bb347c commit ba8814c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

scripts/commit-msg.hook

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,12 +613,29 @@ add_change_id() {
613613
}
614614
changeIdAfter = "^(" tolower("'"$CHANGE_ID_AFTER"'") "):"
615615
numlines = split(lines, footer, "\n")
616+
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+
}
624+
616625
for (line = 1; line <= numlines; line++) {
617626
if (unprinted && match(tolower(footer[line]), changeIdAfter) != 1) {
618-
unprinted = 0
619-
print "Change-Id: I'"$id"'"
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+
}
620632
}
621633
print footer[line]
634+
635+
if(line == coauthorIndex && unprinted) {
636+
print "Change-Id: I'"$id"'"
637+
unprinted = 0
638+
}
622639
}
623640
if (unprinted) {
624641
print "Change-Id: I'"$id"'"

0 commit comments

Comments
 (0)