github.com/XiaoMi/Gaea@v1.2.5/misc/git/hooks/govet (about) 1 #!/bin/sh 2 # Copyright 2017 Google Inc. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 # git go vet pre-commit hook 17 # 18 # To use, store as .git/hooks/pre-commit inside your repository and make sure 19 # it has execute permissions. 20 21 if [ -z "$GOPATH" ]; then 22 echo "ERROR: pre-commit hook for go vet: \$GOPATH is empty. Please run 'source dev.env' to set the correct \$GOPATH." 23 exit 1 24 fi 25 26 # This script does not handle file names that contain spaces. 27 gofiles=$(git diff --cached --name-only --diff-filter=d | grep '.go$') 28 29 # If any checks are found to be useless, they can be disabled here. 30 # See the output of "go tool vet" for a list of flags. 31 vetflags="-all=true" 32 33 errors= 34 35 # Run on one file at a time because a single invocation of "go tool vet" 36 # with multiple files requires the files to all be in one package. 37 for gofile in $gofiles 38 do 39 if ! go tool vet $vetflags $gofile 2>&1; then 40 errors=YES 41 fi 42 done 43 44 [ -z "$errors" ] && exit 0 45 46 echo 47 echo "Please fix the go vet warnings above. To disable certain checks, change vetflags in misc/git/hooks/govet." 48 exit 1