Skip to content

Commit 9914de5

Browse files
committed
Improve the logic of the file entry Git hooks to support more cases
In addition to starting with a "*", file entries now need a ":" somewhere in them. This helps reduce false positives with bulleted lists. Also, support multiple files separated by commas after a "*". * build-aux/git-hooks/commit-msg-files.awk (check_commit_msg_files): Accumulate file entries over multiple lines to support the above.
1 parent 2e85ac2 commit 9914de5

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

build-aux/git-hooks/commit-msg-files.awk

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,28 @@ function check_commit_msg_files(commit_sha, verbose, changes, good, \
5959
if (verbose && ! msg)
6060
msg = $0
6161

62-
# Find lines that reference files. We look at any line starting
63-
# with "*" (possibly prefixed by "; ") where the file part starts
64-
# with an alphanumeric character. The file part ends if we
65-
# encounter any of the following characters: [ ( < { :
66-
if (/^(; )?\*[ \t]+[[:alnum:]]/ && match($0, /[[:alnum:]][^[(<{:]*/)) {
67-
# There might be multiple files listed on this line, separated
62+
# Find file entries in the commit message. We look at any line
63+
# starting with "*" (possibly prefixed by "; ") followed by a ":",
64+
# possibly on a different line. If we encounter a blank line
65+
# without seeing a ":", then we don't treat that as a file entry.
66+
67+
# Accumulate the contents of a (possible) file entry.
68+
if (/^[ \t]*$/)
69+
filenames_str = ""
70+
else if (/^(; )?\*[ \t]+[[:alnum:]]/)
71+
filenames_str = $0
72+
else if (filenames_str)
73+
filenames_str = (filenames_str $0)
74+
75+
# We have a file entry; analyze it.
76+
if (filenames_str && /:/) {
77+
# Delete the leading "*" and any trailing information.
78+
sub(/^(; )?\*[ \t]+/, "", filenames_str)
79+
sub(/[ \t]*[[(<:].*$/, "", filenames_str)
80+
81+
# There might be multiple files listed in this entry, separated
6882
# by spaces (and possibly a comma). Iterate over each of them.
69-
split(substr($0, RSTART, RLENGTH), filenames, ",?([[:blank:]]+|$)")
70-
83+
split(filenames_str, filenames, ",[ \t]+")
7184
for (i in filenames) {
7285
# Remove trailing slashes from any directory entries.
7386
sub(/\/$/, "", filenames[i])
@@ -83,6 +96,8 @@ function check_commit_msg_files(commit_sha, verbose, changes, good, \
8396
good = 0
8497
}
8598
}
99+
100+
filenames_str = ""
86101
}
87102
}
88103
close(cmd)

0 commit comments

Comments
 (0)