heptagon/tools/git-hooks/pre-commit
Cédric Pasteur ab5de4e769 Compatibility with Mac OS X
Default wc command in Mac OS X does not have
a '-L' option
2010-07-16 14:35:33 +02:00

37 lines
709 B
Bash
Executable file

#!/bin/sh
bad=0
check_file() {
name=$1
tmp=$2
if [ `awk ' { if ( length > x ) { x = length } } END { print x }' $tmp` -gt 80 ]; then
echo "File \"$name\" has lines with more than 80 columns."
bad=1
fi
grep -P '\t' $tmp > /dev/null
if [ $? -eq 0 ]; then
echo "File \"$name\" has tabulations in it."
bad=1
fi
grep -P '( |\t)+$' $tmp > /dev/null
if [ $? -eq 0 ]; then
echo "File \"$name\" has trailing whitespace."
bad=1
fi
}
for f in $(git diff-index --cached --name-only HEAD --diff-filter=ACMR | egrep "\.ml(i?)$")
do
tf=$(git checkout-index --temp $f | cut -f 1)
trap "rm -f -- $tf" EXIT
check_file $f $tf
rm -f -- $tf
trap - EXIT
done
exit $bad