#!/bin/bash

# use as .git/hooks/commit-msg

COMMIT_MSG_FILE=$1

exec 1>&2

RET=0
changed=$(git diff --cached --name-only)

for f in $changed;
do
 # Only headers in include
 if echo $f | grep \src\/include\/.\*\.h\$  > /dev/null
 then
   RET=1
   # Check if it has a NEWS line
   if cat $COMMIT_MSG_FILE | grep -i "^NEWS:\s[-,a-zA-Z][a-zA-Z]*" > /dev/null
   then
       RET=0
       break
   fi
 fi
done

# If no NEWS line found, abort
if [ $RET = 1 ];
then
  echo "Your commit includes staged changes that indicate an API change which requires a NEWS line."
else
  echo "Your commit does not include API changes"
fi
exit 0
