github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/contrib/hooks/govet.sh (about) 1 #!/bin/bash 2 3 4 #!/bin/sh 5 # Copyright 2012 The Go Authors. All rights reserved. 6 # Use of this source code is governed by a BSD-style 7 # license that can be found in the LICENSE file. 8 9 # git go vet pre-commit hook 10 # 11 # To use, store as .git/hooks/pre-commit inside your repository and make sure 12 # it has execute permissions. 13 14 if [ -z "$GOPATH" ]; then 15 echo "ERROR: pre-commit hook for go vet: \$GOPATH is empty. Please run 'source dev.env' to set the correct \$GOPATH." 16 exit 1 17 fi 18 19 # This script does not handle file names that contain spaces. 20 gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$' | grep -v '^vendor/') 21 22 # If any checks are found to be useless, they can be disabled here. 23 # See the output of "go tool vet" for a list of flags. 24 vetflags="-all=true" 25 26 errors= 27 28 # Run on one file at a time because a single invocation of "go tool vet" 29 # with multiple files requires the files to all be in one package. 30 echo -e "\033[32m Running go vet on staged files. Any errors won't allow you to commit.\033[0m" 31 for gofile in $gofiles 32 do 33 if ! go tool vet $vetflags $gofile 2>&1; then 34 errors=YES 35 fi 36 done 37 38 [ -z "$errors" ] && exit 0 39 40 echo 41 echo "Please fix the go vet warnings above. To disable certain checks, change vetflags in misc/git/hooks/govet." 42 exit 1 43