Skip to content

Commit 209e089

Browse files
authored
Merge pull request #6 from DanielVoogsgerd/extended_regex
2 parents 8add0bc + 883ba4d commit 209e089

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

conventional-pre-commit.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ msg_file=$1
2121
# join types with | to form regex ORs
2222
r_types="($(IFS='|'; echo "${types[*]}"))"
2323
# optional (scope)
24-
r_scope="(\([\w \/-]+\))?"
24+
r_scope="(\([[:alnum:] \/-]+\))?"
2525
# optional breaking change indicator and colon delimiter
2626
r_delim='!?:'
2727
# subject line, body, footer
28-
r_subject=" [\w][\s\S]+"
28+
r_subject=" [[:alnum:]].+"
2929
# the full regex pattern
3030
pattern="^$r_types$r_scope$r_delim$r_subject$"
3131

32-
# check commit message
33-
if ! grep -Pq "$pattern" "$msg_file"; then
34-
echo "[Commit message] $( cat $msg_file )"
35-
echo "
32+
# Check if commit is conventional commit
33+
if grep -Eq "$pattern" "$msg_file"; then
34+
exit 0
35+
fi
36+
37+
echo "[Commit message] $( cat $msg_file )"
38+
echo "
3639
Your commit message does not follow Conventional Commits formatting
3740
https://www.conventionalcommits.org/
3841
@@ -53,5 +56,4 @@ Optionally, include a scope in parentheses after the type for more context:
5356
5457
fix(account): remove infinite loop
5558
"
56-
exit 1
57-
fi
59+
exit 1

0 commit comments

Comments
 (0)