github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/.gitprecommit/go_fmt.sh (about) 1 #!/bin/bash 2 if git rev-parse --verify HEAD >/dev/null 2>&1 3 then 4 against=HEAD 5 else 6 # Initial commit: diff against an empty tree object 7 EMPTY_TREE=$(git hash-object -t tree /dev/null) 8 against=${EMPTY_TREE} 9 fi 10 11 FILES=$(git diff --cached --diff-filter=d --name-only "${against}") 12 if [[ -n "${FILES}" ]]; then 13 for f in ${FILES}; do 14 if [[ "${f}" == *.go ]]; then 15 gofmt -w -s "${f}" 16 fi 17 done 18 fi