-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathcommit-msg
More file actions
executable file
·80 lines (69 loc) · 1.88 KB
/
commit-msg
File metadata and controls
executable file
·80 lines (69 loc) · 1.88 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
#
# This hook verifies that the commit message follows deis commit style
# To install this hook run the following command from the deis git root
# cp contrib/util/commit-msg .git/hooks/commit-msg
set -eo pipefail
RED=$(tput setaf 1)
NORMAL=$(tput sgr0)
subject_regex="^(feat|fix|docs|style|ref|test|chore)\(.+\): [\w\s\d]*"
capital_regex="^.+\): [a-z][\w\s\d]*"
MESSAGE[1]="file"
i=1 # the first array variable is at index 1
while read line
do
MESSAGE[$i]=$line
let i++
done < "$1"
SUBJECT=${MESSAGE[1]}
if ! [[ $SUBJECT =~ $subject_regex ]]; then
echo "${RED}ERROR - Invalid subject line."
echo ""
echo "$SUBJECT"
echo ""
echo "It must be in the format: {type}({scope}): {subject}"
echo ""
echo "The following {type}s are allowed:"
echo "feat"
echo "fix"
echo "docs"
echo "style"
echo "ref"
echo "test"
echo "chore"
echo ""
echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
exit 1
fi
if ! [[ $SUBJECT =~ $capital_regex ]]; then
echo "${RED}ERROR - Don't the capitalize commit message."
echo ""
echo "$SUBJECT"
echo ""
echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
exit 1
fi
if [[ ${#SUBJECT} -gt 50 ]]; then
echo "${RED}ERROR - Subject can't be longer than 50 characters."
echo ""
echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
exit 1
fi
if [[ ${#MESSAGE[2]} -gt 0 ]]; then
echo "${RED}ERROR - Second line must be blank"
echo ""
echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
exit 1
fi
cnt=${#MESSAGE[@]}
for (( i = 3 ; i <= cnt ; i++ ))
do
if [[ ${#MESSAGE[$i]} -gt 72 ]]; then
echo "${RED}ERROR on line $i - can't be longer than 72 characters."
echo ""
echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
exit 1
fi
done
echo "Your commit message follows the deis commit style"
exit 0