blob: ec9db60c15eaa4577bbf2de42aad1d3b9504d4ca [file] [log] [blame]
Damjan Marion26ce6ca2019-06-12 17:41:39 +02001#/bin/env bash
2
3KNOWN_FEATURES=$(cat MAINTAINERS | sed -ne 's/^I:[[:space:]]*//p')
4FEATURES=$(git show -s --format=%s --no-color | sed -e 's/\(.*\):.*/\1/')
5KNOWN_TYPES="fix refactor style docs test make"
6TYPE=$(git show -s --format=%b --no-color | sed -ne 's/^Type:[[:space:]]*//p')
7ERR="=============================== ERROR ==============================="
8
9# Chech that subject line contains at least one feature id
10if [ $(echo ${FEATURES} | wc -w) -eq 0 ]; then
11 echo $ERR
12 echo "git commit 'Subject:' line must contain at least one known feature id."
13 echo "feature id(s) must be listed before ':' and space delimited "
14 echo "if more then one is listed."
15 echo "Please reffer to MAINTAINERS file (I: lines) for known feature ids."
16 echo $ERR
17 exit 1
18fi
19
20# Check that feature ids in subject line are known
21for i in ${FEATURES}; do
22 is_known=false
23 for j in ${KNOWN_FEATURES}; do
24 [ "${i}" = "${j}" ] && is_known=true
25 done
26 if [ ${is_known} = "false" ] ; then
27 echo $ERR
28 echo "Unknown feature '${i}' in commit 'Subject:' line."
29 echo "Feature must exist in MAINTAINERS file. If this commit intruduces "
30 echo "new feature, then this commit must add new entry into the "
31 echo "MAINTAINERS file."
32 echo $ERR
33 exit 1
34 fi
35done
36
37# Check that Message body contains valid Type: entry
38is_known=false
39for i in ${KNOWN_TYPES}; do
40 [ "${i}" = "${TYPE}" ] && is_known=true
41done
42if [ ${is_known} = "false" ] ; then
43 echo $ERR
44 echo "Unknown commit type '${TYPE}' in commit message body."
45 echo "Commit message must contain known 'Type:' entry."
46 echo "Known types are: ${KNOWN_TYPES}"
47 echo $ERR
48 exit 1
49fi
50