Damjan Marion | 26ce6ca | 2019-06-12 17:41:39 +0200 | [diff] [blame] | 1 | #/bin/env bash |
| 2 | |
| 3 | KNOWN_FEATURES=$(cat MAINTAINERS | sed -ne 's/^I:[[:space:]]*//p') |
| 4 | FEATURES=$(git show -s --format=%s --no-color | sed -e 's/\(.*\):.*/\1/') |
| 5 | KNOWN_TYPES="fix refactor style docs test make" |
| 6 | TYPE=$(git show -s --format=%b --no-color | sed -ne 's/^Type:[[:space:]]*//p') |
| 7 | ERR="=============================== ERROR ===============================" |
| 8 | |
| 9 | # Chech that subject line contains at least one feature id |
| 10 | if [ $(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 |
| 18 | fi |
| 19 | |
| 20 | # Check that feature ids in subject line are known |
| 21 | for 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 |
| 35 | done |
| 36 | |
| 37 | # Check that Message body contains valid Type: entry |
| 38 | is_known=false |
| 39 | for i in ${KNOWN_TYPES}; do |
| 40 | [ "${i}" = "${TYPE}" ] && is_known=true |
| 41 | done |
| 42 | if [ ${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 |
| 49 | fi |
| 50 | |