Rainbond/precheck.sh
2019-08-04 21:29:33 +08:00

28 lines
402 B
Bash
Executable File

#!/bin/sh
STAGED_GO_FILES=$(git diff --cached --name-only | grep ".go$")
if [[ "$STAGED_GO_FILES" = "" ]]; then
exit 0
fi
PASS=true
for FILE in $STAGED_GO_FILES
do
goimports -w $FILE
golangci-lint run --fix --disable=typecheck $FILE
if [[ $? != 0 ]]; then
PASS=false
fi
done
if ! $PASS; then
printf "COMMIT FAILED\n"
exit 1
else
printf "COMMIT SUCCEEDED\n"
git add
fi
exit 0