2012-10-16 14:31:23 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
exitstatus=0
|
2012-10-22 21:21:24 +00:00
|
|
|
|
|
|
|
#third_party imports.
|
|
|
|
cd third_party
|
|
|
|
rewrite=`./rewrite-imports.sh -l`
|
|
|
|
cd ..
|
|
|
|
if [ -n "$rewrite" ]
|
|
|
|
then
|
|
|
|
exitstatus=1
|
|
|
|
for r in $rewrite
|
|
|
|
do
|
|
|
|
echo $r
|
|
|
|
done
|
|
|
|
echo "The above need their imports to be fixed. Use rewrite-imports.sh -w"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#gofmt and trailing space errors
|
2012-10-16 14:31:23 +00:00
|
|
|
committed=`git diff-index --cached --name-only HEAD`
|
|
|
|
for c in $committed
|
|
|
|
do
|
2013-04-25 17:25:05 +00:00
|
|
|
if [ ! -e "$c" ]
|
|
|
|
then
|
|
|
|
continue
|
|
|
|
fi
|
2012-10-16 14:31:23 +00:00
|
|
|
gofile=`echo $c | grep -E '.*\.go$'`
|
2013-02-25 18:28:06 +00:00
|
|
|
javafile=`echo $c | grep -E '.*\.java$'`
|
2012-10-16 14:31:23 +00:00
|
|
|
if [ -n "$gofile" ]
|
|
|
|
then
|
2013-10-23 17:21:27 +00:00
|
|
|
fmtdiff=`git show ":$c" | gofmt -d 2>&1`
|
2012-10-16 14:31:23 +00:00
|
|
|
if [ -n "$fmtdiff" ]
|
|
|
|
then
|
|
|
|
echo "gofmt needed on "$c
|
|
|
|
exitstatus=1
|
|
|
|
fi
|
2013-02-25 18:28:06 +00:00
|
|
|
fi
|
|
|
|
if [ -n "$gofile" -o -n "$javafile" ]
|
|
|
|
then
|
2012-10-16 14:31:23 +00:00
|
|
|
trailspace=`git diff-index --cached --check HEAD $c | grep 'trailing whitespace'`
|
|
|
|
if [ -n "$trailspace" ]
|
|
|
|
then
|
|
|
|
echo $trailspace
|
|
|
|
exitstatus=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$exitstatus" -ne 0 ]
|
|
|
|
then
|
|
|
|
echo "You can override this check with 'git commit --no-verify'"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit $exitstatus
|