github.com/Finschia/finschia-sdk@v0.48.1/contrib/githooks/pre-commit (about) 1 #!/bin/bash 2 3 set -e 4 5 CMDS='git go gofmt goimports misspell' 6 STAGED_GO_FILES=$(git diff --cached --name-only -- '*.go') 7 8 f_echo_stderr() { 9 echo $@ >&2 10 } 11 12 f_exit_success() { 13 [ x"$@" != "x" ] && f_echo_stderr $@ || exit 0 14 } 15 trap f_exit_success EXIT 16 17 f_check_cmds() { 18 for cmd in ${CMDS}; do 19 which ${cmd} &>/dev/null || f_exit_success "couldn't find ${cmd}, skipping" 20 done 21 } 22 23 f_check_cmds 24 25 if [[ $STAGED_GO_FILES != "" ]]; then 26 f_echo_stderr "[pre-commit] fmt'ing staged files..." 27 for file in $STAGED_GO_FILES; do 28 if [[ $file =~ vendor/ ]] || [[ $file =~ client/docs/statik/ ]] || [[ $file =~ tests/mocks/ ]] || [[ $file =~ \.pb\.go ]]; then 29 continue 30 fi 31 32 gofmt -w -s $file 33 misspell -w $file 34 goimports -w -local github.com/Finschia/finschia-sdk $file 35 git add $file 36 37 done 38 fi 39 40 # Run go mod tidy 41 go mod tidy && git add go.mod go.sum