19 lines
465 B
Bash
Executable file
19 lines
465 B
Bash
Executable file
#!/usr/bin/env bash
|
|
# Reject commits containing Go files that aren't gofmt-formatted.
|
|
set -euo pipefail
|
|
|
|
files="$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$' || true)"
|
|
|
|
if [ -z "$files" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
unformatted="$(gofmt -l $files)"
|
|
|
|
if [ -n "$unformatted" ]; then
|
|
echo "gofmt: the following files are not formatted:"
|
|
echo "$unformatted"
|
|
echo
|
|
echo "Run 'gofmt -w <file>...' and re-stage before committing."
|
|
exit 1
|
|
fi
|