-
Notifications
You must be signed in to change notification settings - Fork 17
/
commit-msg
executable file
·90 lines (73 loc) · 1.84 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
#
# An example hook script to check the commit log message.
# Called by "git commit" with one argument, the name of the file
# that has the commit message. The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the
# commit. The hook is allowed to edit the commit message file.
#
# To enable this hook, rename this file to "commit-msg".
# Uncomment the below to add a Signed-off-by line to the message.
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
# hook is more suited to it.
#
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
# This example catches duplicate Signed-off-by lines.
msg1=$(cat $1)
msg=${msg1%%#*}
typearr=("build" "chore" "ci" "docs" "feat" "fix" "perf" "refactor" "revert" "style" "test") #按照angular规范 可自定义
iftype=0
scopearr=("(scope)" "(assets)" "(theme)" "(package)" "(controller)" "(models)" "(db)") #可自定义
ifscope=0
type=${msg%:*}
if [ "$type" = "$msg" ]
then
echo "please input type"
exit 1
fi
scope=`echo "$type" |grep -Eo "\(.*?\)"`
tag=`echo "$type" |grep -Eo "\[.*?\]"`
if [ $tag ]
then
echo $tag
fi
# 判断scope
if [ $scope ]
then
for scp in ${scopearr[*]}
do
if [ $scp = $scope ]
then
ifscope=1
fi
done
if [ $ifscope -eq 0 ]
then
echo "scope should be:" ${scopearr[*]} ,\(add --no-verify to bypass\)
exit 1
fi
type=${msg%%(*}
fi
# 判断type
for ty in ${typearr[*]}
do
if [ $ty = $type ]
then
iftype=1
fi
done
if [ $iftype -eq 0 ]
then
echo "type should be:" ${typearr[*]} ,\(add --no-verify to bypass\)
exit 1
fi
# 判断comment长度
comment=${msg#*: }
len=`echo ${#comment}`
if [ $len -lt 5 ]
then
echo "comment less than 5" ,\(add --no-verify to bypass\)
exit 1
fi
exit 0