-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit-msg
More file actions
39 lines (35 loc) · 1.14 KB
/
commit-msg
File metadata and controls
39 lines (35 loc) · 1.14 KB
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
#!/usr/bin/env bash
unset GREP_OPTIONS
COMMIT_MSG_ERROR_FOUND=0
MSG="$1"
ERROR_TEXT="\n"
#
# Check for maximum line length
#
checkForLineLength() {
if egrep -q '^[^#].{74}' "$MSG"; then
COMMIT_MSG_ERROR_FOUND=1
ERROR_TEXT="${ERROR_TEXT} - The maximum line length of 74 characters is exceeded.\n"
fi
}
#
# Check for existence of the commit type text
#
checkForCommitType() {
if ! egrep -q '\[[^]]+\] .+$' "$MSG"; then
COMMIT_MSG_ERROR_FOUND=1
ERROR_TEXT="${ERROR_TEXT} - Your first line has to contain a commit type like '[BUGFIX]'.\n"
fi
}
checkForLineLength
checkForCommitType
# Abort commit on message format errors
if [ $COMMIT_MSG_ERROR_FOUND -eq 1 ]; then
echo -e " "
echo -e "------------------------------------------------------------------"
echo -e " >> ERROR in your commit message: "
echo -e " $ERROR_TEXT"
echo -e " "
echo -e " You should fix this and then do commit --amend etc. "
echo -e "------------------------------------------------------------------\n"
fi