-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepare-commit-msg
executable file
·77 lines (66 loc) · 2.16 KB
/
prepare-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
#!/bin/sh
#
# An example hook script to prepare the commit log message.
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source. The hook's purpose is to edit the commit
# message file. If the hook fails with a non-zero status,
# the commit is aborted.
#
# To enable this hook, rename this file to "prepare-commit-msg".
# This hook includes three examples. The first one removes the
# "# Please enter the commit message..." help message.
#
# The second includes the output of "git diff --name-status -r"
# into the message, just before the "git status" output. It is
# commented because it doesn't cope with --amend or with squashed
# commits.
#
# The third example adds a Signed-off-by line to the message, that can
# still be edited. This is rarely a good idea.
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3
if [ "${COMMIT_SOURCE}" != "" ]; then
exit 0
fi
defaultMessage(){
echo "">>${COMMIT_MSG_FILE}
echo "">>${COMMIT_MSG_FILE}
echo '##### COMMIT MESSAGE RULES #####'>>${COMMIT_MSG_FILE}
cat $(dirname "$0")/message/commit-message-format>>${COMMIT_MSG_FILE}
exit 0
}
originalMessage=`cat $1`
echo ${originalMessage} > /tmp/test
currentBranch=`git rev-parse --abbrev-ref HEAD`
branchType=`echo ${currentBranch} | awk -F '/' '{ print $1 }'`
issueNumber=`basename ${currentBranch}`
if [[ "${issueNumber}" =~ ^[a-zA-Z][a-zA-Z]*.*[0-9][0-9]*$ ]]; then
echo .>/dev/null
else
issueNumber="<Issue ID>"
fi
if [[ "${branchType}" =~ ^(feat|fix|refactor)$ ]]; then
commitType=${branchType}
elif [[ "${branchType}" =~ ^feature$ ]];then
commitType="feat"
elif [[ "${branchType}" =~ ^refacto$ ]];then
commitType="refactor"
elif [[ "${branchType}" =~ ^(chore|docs|style|perf|test|build)$ ]]; then
commitType=${branchType}
elif [[ "${branchType}" =~ ^doc$ ]]; then
commitType="docs"
else
defaultMessage
fi
if [[ "${commitType}" =~ ^(feat|fix|refactor)$ ]]; then
message=`echo "${commitType}: [${issueNumber}]"`
else
message=`echo "${commitType}:"`
fi
cat <<-EOF > ${COMMIT_MSG_FILE}
$(echo $message)
$(cat ${COMMIT_MSG_FILE})
EOF
defaultMessage