Skip to content

Commit

Permalink
misc/git: add pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
mna committed Mar 24, 2016
1 parent b60c92e commit abe3298
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
32 changes: 32 additions & 0 deletions misc/git/pre-commit
@@ -0,0 +1,32 @@
#!/bin/sh

echo ">>> golint"
for dir in $(go list ./... | grep -v /vendor/)
do
golint $dir
done
echo "<<< golint"
echo

echo ">>> go vet"
go vet $(go list ./... | grep -v /vendor/)
echo "<<< go vet"
echo

# Check for gofmt problems and report if any.
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$' | grep -v /vendor/)
[ -z "$gofiles" ] && echo "EXIT $vetres" && exit $vetres

if [ -n "$gofiles" ]; then
unformatted=$(gofmt -l $gofiles)

if [ -n "$unformatted" ]; then
# Some files are not gofmt'd.
echo >&2 "Go files must be formatted with gofmt. Please run:"
for fn in $unformatted; do
echo >&2 " gofmt -w $PWD/$fn"
done
fi
fi
echo

9 changes: 9 additions & 0 deletions misc/lint_tester.goo
@@ -0,0 +1,9 @@
package misc

import "fmt"

// golint error
func Exported(s string) {
fmt.Printf("%d", s) // go vet error
return // gofmt error
}

0 comments on commit abe3298

Please sign in to comment.