Files
synapbus/scripts/hooks/pre-commit
T
Algis DumbrisandClaude Opus 4.6 7de0114927 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>
2026-03-13 20:17:15 +02:00

32 lines
1016 B
Bash
Executable File

#!/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"