-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit-msg
executable file
·61 lines (49 loc) · 1.53 KB
/
commit-msg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
#
# All Contributions by Match Group
#
# Copyright © 2025 Tinder (Match Group, LLC)
#
# Licensed under the Match Group Modified 3-Clause BSD License.
# See https://github.com/Tinder/Commit-Message-Validation-Hook/blob/main/LICENSE for license information.
#
COMMIT_MSG=$(cat "$1" | grep -ve '^#')
LINE_1="$(echo "$COMMIT_MSG" | head -1)"
LINE_2="$(echo "$COMMIT_MSG" | tail -n +2 | head -1)"
LINE_N="$(echo "$COMMIT_MSG" | tail -n +3)"
match()
{
echo "$1" | grep -e "$2" >/dev/null
}
match "$LINE_1" '\S' || {
echo >&2 "Aborting commit due to empty commit message."
exit 1
}
abort()
{
echo >&2 "Aborting commit due to $1"
echo >&2 "-"
echo >&2 "$COMMIT_MSG"
echo >&2 "-"
echo >&2 "To temporarily bypass commit message validation, use \`git commit --no-verify\`."
exit 1
}
match "$LINE_1" '^[[:lower:]]' && \
abort "first line of commit message starting with a lowercase letter."
match "$LINE_1" '.*\.\s*$' && \
abort "first line of commit message ending with a period."
match "$LINE_1" '^..\{50\}' && \
abort "first line of commit message exceeding 50 character limit."
match "$LINE_2" '^$' || \
abort "second line of commit message not being empty."
match "$LINE_N" '^..\{72\}' && \
abort "line in body of commit message exceeding 72 character limit."
if command -v spellcheck >/dev/null
then
MISSPELLED_WORDS=$(echo "$COMMIT_MSG" | spellcheck)
if [ $? -ne 0 ]
then
NEWLINE=$'\n'
abort "misspelled words:${NEWLINE}${MISSPELLED_WORDS}"
fi
fi