aboutsummaryrefslogtreecommitdiff
path: root/.githooks/pre-commit
blob: 95fbb206b86aa7de02c5e6fd5a1da5cc8ddd8bb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
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