Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 86e4254

Browse files
charliechiouEricccTaiwan
andcommittedMar 11, 2025·
Ensure proper footer sorting of footer
When no trailer was configured in git configuration, TRAILERS_BY_REGEX remained empty. This caused the subsequent match condition to always evaluate to true, leading to incorrect footer sorting regardless of their content. To address this issue, the update ensures that when the configuration is empty, default terms are used to initialize TRAILERS_BY_REGEX. The sorting mechanism is then adjusted to prioritize other footers, configured trailers, and the change-id. Co-authored-by: EricccTaiwan <yphbchou0911@gmail.com> Change-Id: I6df5438b7ec6c85f5438f869b44cd14589c03339
1 parent 5d61cfd commit 86e4254

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed
 

‎scripts/commit-msg.hook

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ build_commit_trailer_regex() {
151151
"Git-Dch[$separators] (Ignore|Short|Full)"
152152
)
153153

154+
default_trailers_by=(
155+
'Signed-off-by'
156+
'Reviewed-by'
157+
'Co-authored-by'
158+
'Acked-by'
159+
'Suggested-by'
160+
'Tested-by'
161+
'Reported-by'
162+
)
163+
154164
# Read custom trailer keys from git config and add them either to specials or trailers.
155165
# This loop reads lines matching 'trailer.*.key'.
156166
while read -r _ key; do
@@ -170,6 +180,10 @@ build_commit_trailer_regex() {
170180
fi
171181
done < <(git config --get-regexp 'trailer.*.key')
172182

183+
if [[ ${#trailers_by[@]} -eq 0 ]]; then
184+
trailers_by=("${default_trailers_by[@]}")
185+
fi
186+
173187
# Possible trailers :
174188
# - Acked-by
175189
# - Co-authored-by
@@ -178,8 +192,7 @@ build_commit_trailer_regex() {
178192
# - Signed-off-by
179193
# - Suggested-by
180194
# - Tested-by
181-
TRAILERS_BY_REGEX="^($(IFS='|'; echo "${trailers_by[*]}")):"
182-
195+
TRAILERS_BY_REGEX="/($(IFS='|'; echo "${trailers_by[*]}" | tr '[:upper:]' '[:lower:]'))/"
183196
# Begin constructing the regex.
184197
TRAILER_REGEX='^('
185198

@@ -610,7 +623,7 @@ add_change_id() {
610623
other_footer = ""
611624
612625
for (line = 1; line <= numlines; line++) {
613-
if (match(tolower(footer[line]), TRAILERS_BY_REGEX)) {
626+
if (match(tolower(footer[line]), '"$TRAILERS_BY_REGEX"')) {
614627
trailers = trailers footer[line] "\n"
615628
} else {
616629
other_footer = other_footer footer[line] "\n"

0 commit comments

Comments
 (0)
Please sign in to comment.