summaryrefslogtreecommitdiff
path: root/.githooks/pre-commit
blob: 95ecd68e8687a12d084734c593e13fc546a29f80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
# Pre-commit hook - fast checks only
# dependencies: php git bash grep xargs composer

set -e

echo "🔍 Running pre-commit checks..."

# Check if we have staged files
if git diff --cached --quiet; then
    echo "No staged changes found."
    exit 0
fi

# Lint only staged files
echo "📝 Linting staged files..."

# Get staged Go files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$' || true)

if [ -n "$STAGED_FILES" ]; then
    # Run Go linting on staged files
    go vet ./...
    if [ $? -eq 0 ]; then
        echo "✅ go vet passed"
    else
        echo "❌ go vet failed"
        exit 1
    fi

    golangci-lint run ./...
    if [ $? -eq 0 ]; then
        echo "✅ golangci-lint passed"
    else
        echo "❌ golangci-lint failed"
        exit 1
    fi
else
    echo "⏭️ Nothing to lint, skipping..."
fi

echo "🎉 Pre-commit checks completed successfully!"