Tweak pre-commit to ignore vendor directory.

This commit is contained in:
Jeffrey Regan 2017-11-17 17:28:34 -08:00 committed by jregan
parent bcbe5fae3f
commit 4b7a63c631
2 changed files with 15 additions and 6 deletions

View File

@ -1,5 +1,13 @@
#!/bin/bash
# Runs pre-commit tests.
#
# Instead of failing on first error, complete all checks, then fail if need be.
# Echo go's version to verify against go's behavior below.
# Different versions do different things with respect to vendored code.
go version
# Assert state.
if [ -n "$failIt" ]; then
echo "Expecting failIt to be empty."
exit 1
@ -7,25 +15,25 @@ fi
wantEmpty=$(gofmt -s -d -l . 2>&1 )
if [ -n "$wantEmpty" ]; then
printf >&2 'gofmt failed for:\n%s\n' "$wantEmpty"
printf >&2 '\ngofmt failed for:\n%s\n' "$wantEmpty"
failIt=1
fi
wantEmpty=$(goimports -l .)
wantEmpty=$(goimports -l $(find . -type f -name '*.go' -not -path "./vendor/*") 2>&1)
if [ -n "$wantEmpty" ]; then
printf >&2 'goimports failed for:\n%s\n' "$wantEmpty"
printf >&2 '\ngoimports failed for:\n%s\n' "$wantEmpty"
failIt=1
fi
wantEmpty=$(go vet -all ./... 2>&1)
if [ -n "$wantEmpty" ]; then
printf >&2 'govet failed for:\n%s\n' "$wantEmpty"
printf >&2 '\ngo vet failed for:\n%s\n' "$wantEmpty"
failIt=1
fi
wantEmpty=$(golint ./...)
if [ -n "$wantEmpty" ]; then
printf >&2 'golint failed for:\n%s\n' "$wantEmpty"
printf >&2 '\ngolint failed for:\n%s\n' "$wantEmpty"
failIt=1
fi
@ -35,3 +43,4 @@ if [ -n "$failIt" ]; then
fi
go test -v ./...

View File

@ -21,7 +21,7 @@ import (
"io/ioutil"
"path"
"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"