blob: 7fda0a35053d2414cb054cd132260df80f099522 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#!/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"
# run goimports if it's there
if command -v goimports >/dev/null 2>&1; then
goimports -w "$file"
fi
git add "$file"
done
fi
|