diff options
Diffstat (limited to '.githooks')
-rwxr-xr-x | .githooks/pre-commit | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..95fbb20 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,12 @@ +#!/bin/sh + +# This hook formats every Go file with `go fmt` before committing them. +# It helps to enforce the Go style guide for those who forget to format their code properly. + +STAGED="$(git diff --cached --name-only -- '*.go')" +if [ -n "$STAGED" ]; then + for file in $STAGED; do + go fmt "$file" + git add "$file" + done +fi |