#!/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 ...' and re-stage before committing." exit 1 fi