github.com/skf/moby@v1.13.1/hack/validate/gofmt (about) 1 #!/bin/bash 2 3 export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 source "${SCRIPTDIR}/.validate" 5 6 IFS=$'\n' 7 files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | 8 grep -v '^vendor/' | 9 grep -v '^cli/compose/schema/bindata.go' || true) ) 10 unset IFS 11 12 badFiles=() 13 for f in "${files[@]}"; do 14 # we use "git show" here to validate that what's committed is formatted 15 if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then 16 badFiles+=( "$f" ) 17 fi 18 done 19 20 if [ ${#badFiles[@]} -eq 0 ]; then 21 echo 'Congratulations! All Go source files are properly formatted.' 22 else 23 { 24 echo "These files are not properly gofmt'd:" 25 for f in "${badFiles[@]}"; do 26 echo " - $f" 27 done 28 echo 29 echo 'Please reformat the above files using "gofmt -s -w" and commit the result.' 30 echo 31 } >&2 32 false 33 fi