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
|
#!/bin/sh
# copy this file to .git/hooks (i.e., overwrite the file .git/hooks/pre-commit)
# to perform source checks before commits
check_source () {
echo $1
$PWD/scripts/src_check $1
if [ $? -eq 0 ]
then
APIS=`echo "$1" | grep -F "_api.h"`
if [ ${#APIS} -ne 0 ]; then
echo "WARNING: you are committing API headers:"
echo $APIS
git diff --cached $APIS
exec < /dev/tty
echo
read -p "Are you sure? [yn]" reply
echo
case $reply in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
* ) echo "Please answer yes or no.";;
esac
fi
else
return 1
fi
return 0
}
# different versions of git use different letters for deleted/removed files
FILES=`git diff --cached --name-status HEAD | \
awk '$1 != "R" && $1 != "D" { print $2 }' | \
grep -v -e 'src/external' | \
grep -e '.*\.c$' -e '.*\.h$'`
if [ ${#FILES} -gt 0 ]
then
check_source $FILES
fi
|