Skip to content

Commit

Permalink
hook: Detect caps in :/[]/{} prefixed subject
Browse files Browse the repository at this point in the history
This hook didn't detect cap'd subject when prefixed with
tag:/[tag]/{tag} eg.

tag(scope): Subject cap check failed
[tag] Subject cap check failed
{tag} Subject cap check failed

'@(+([[:alnum:]])?(\(+([[:alnum:]])\)):|\[+([[:alnum:][:punct:]])\]|\{+([[:alnum:][:punct:]])\}|squash\!)'
matches the prefixes and removes it from subject line before checking.
  • Loading branch information
ahmubashshir committed Aug 3, 2021
1 parent 3736433 commit f5ee215
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ validate_commit_message() {
# reset warnings
WARNINGS=()

# capture the subject, and remove the 'squash! ' prefix if present
COMMIT_SUBJECT=${COMMIT_MSG_LINES[0]/#squash! /}
# capture the subject, and remove the 'squash! ', 'tag: ', '[tag] ' or '{tag} ' prefix if present
shopt -s extglob
COMMIT_SUBJECT=${COMMIT_MSG_LINES[0]/#@(+([[:alnum:]])?(\(+([[:alnum:]])\)):|\[+([[:alnum:][:punct:]])\]|\{+([[:alnum:][:punct:]])\}|squash\!) /}
shopt -u extglob

# if the commit is empty there's nothing to validate, we can return here
COMMIT_MSG_STR="${COMMIT_MSG_LINES[*]}"
Expand Down

0 comments on commit f5ee215

Please sign in to comment.