feat: add pre-commit and pre-push git hooks

Pre-commit runs go vet, golangci-lint (optional), and fast tests.
Pre-push runs full test suite and build verification.
Installable via `make hooks`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Algis Dumbris
2026-03-13 20:17:15 +02:00
co-authored by Claude Opus 4.6
parent fcb8da613c
commit 7de0114927
3 changed files with 55 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Pre-commit hook: fast quality checks on staged Go files
set -e
echo "🔍 Pre-commit checks..."
# Check if any Go files are staged
STAGED_GO_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$' || true)
if [ -z "$STAGED_GO_FILES" ]; then
echo "✅ No Go files staged, skipping checks"
exit 0
fi
# 1. go vet
echo " Running go vet..."
CGO_ENABLED=0 go vet ./... || { echo "❌ go vet failed"; exit 1; }
# 2. golangci-lint (skip if not installed)
if command -v golangci-lint &> /dev/null; then
echo " Running golangci-lint..."
golangci-lint run --new-from-rev=HEAD~1 ./... || { echo "❌ golangci-lint failed"; exit 1; }
else
echo " ⚠️ golangci-lint not found, skipping (install: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest)"
fi
# 3. Fast unit tests (short mode)
echo " Running fast tests..."
CGO_ENABLED=0 go test -short -count=1 ./... || { echo "❌ tests failed"; exit 1; }
echo "✅ All pre-commit checks passed"