Browse Source
Checks all .go files to be commited for proper formatting. The hook will be installed automatically by Makefile.pull/33/head
2 changed files with 37 additions and 2 deletions
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh |
||||
# |
||||
# Check that Go files have been formatted |
||||
# |
||||
|
||||
for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.go$"` ; do |
||||
# nf is the temporary checkout. This makes sure we check against the |
||||
# revision in the index (and not the checked out version). |
||||
nf=`git checkout-index --temp ${file} | cut -f 1` |
||||
newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1 |
||||
gofmt ${nf} > "${newfile}" 2>> /dev/null |
||||
diff -u -p "${nf}" "${newfile}" |
||||
r=$? |
||||
rm "${newfile}" |
||||
rm "${nf}" |
||||
if [ $r != 0 ] ; then |
||||
echo "=================================================================================================" |
||||
echo " Code format error in: $file " |
||||
echo " " |
||||
echo " Please fix before committing. Don't forget to run git add before trying to commit again. " |
||||
echo " If the whole file is to be committed, this should work (run from the top-level directory): " |
||||
echo " " |
||||
echo " go fmt $file; git add $file; git commit" |
||||
echo " " |
||||
echo "=================================================================================================" |
||||
exit 1 |
||||
fi |
||||
done |
Loading…
Reference in new issue