From ba8814c25e7883fe409e658ab6db0bf04555f911 Mon Sep 17 00:00:00 2001 From: Chiu-Po-Ying Date: Mon, 10 Mar 2025 09:18:41 +0800 Subject: [PATCH] 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 Change-Id: I856457b5575a967096ad71c9e4271b45b8d1400a --- scripts/commit-msg.hook | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index 0ba27bf28..de8afd463 100755 --- a/scripts/commit-msg.hook +++ b/scripts/commit-msg.hook @@ -613,12 +613,29 @@ add_change_id() { } changeIdAfter = "^(" tolower("'"$CHANGE_ID_AFTER"'") "):" numlines = split(lines, footer, "\n") + + # Find the last line that starts with a comment character. + coauthorIndex = 0 + for (line = 1; line <= numlines; line++) { + if (match(tolower(footer[line]), /^co-authored-by:/)) { + coauthorIndex = line + } + } + for (line = 1; line <= numlines; line++) { if (unprinted && match(tolower(footer[line]), changeIdAfter) != 1) { - unprinted = 0 - print "Change-Id: I'"$id"'" + # If the Change-Id is the first line in the footer, print it first. + if (coauthorIndex == 0 || line > coauthorIndex) { + print "Change-Id: I'"$id"'" + unprinted = 0 + } } print footer[line] + + if(line == coauthorIndex && unprinted) { + print "Change-Id: I'"$id"'" + unprinted = 0 + } } if (unprinted) { print "Change-Id: I'"$id"'"