#!/bin/sh MAX_SIZE=1024 # 1 MB limit in KB for file in $(git diff --cached --name-only --diff-filter=ACM); do if [ ! -e "$file" ]; then continue; fi size=$(du -k "$file" | cut -f1) if [ $size -gt $MAX_SIZE ]; then echo "Error: File $file is larger than the allowed size of $((MAX_SIZE / 1024)) MB." exit 1 fi done status=0 for file in $(git diff --cached --name-only | grep -E '\.go$'); do badfile=$(gofmt -l "$file") if test -n "$badfile" ; then echo "Error: file needs gofmt: $badfile" status=1 fi done # If any files were not formatted, exit with a non-zero status to abort the commit. if [ "$status" -ne 0 ]; then echo "git pre-commit check failed: some Go files are not formatted." exit 1 fi exit 0