-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·103 lines (89 loc) · 3.66 KB
/
Copy pathpre-commit
File metadata and controls
executable file
·103 lines (89 loc) · 3.66 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
# pre-commit hook for Hyperpolymath Language Policy enforcement
# Install: cp hooks/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
ERRORS=0
echo "Hyperpolymath Pre-commit Checks"
echo "================================"
# Check for banned file types in staged files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
# Check for TypeScript
TS_FILES=$(echo "$STAGED_FILES" | grep -E '\.(ts|tsx)$' | grep -v '\.d\.ts$' || true)
if [ -n "$TS_FILES" ]; then
echo -e "${RED}✗ TypeScript files not allowed. Use AffineScript instead.${NC}"
echo "$TS_FILES"
ERRORS=$((ERRORS + 1))
fi
# Check for Go
GO_FILES=$(echo "$STAGED_FILES" | grep -E '\.go$' || true)
if [ -n "$GO_FILES" ]; then
echo -e "${RED}✗ Go files not allowed. Use Rust instead.${NC}"
echo "$GO_FILES"
ERRORS=$((ERRORS + 1))
fi
# Check for Python (except Ansible)
PY_FILES=$(echo "$STAGED_FILES" | grep -E '\.py$' | grep -v 'ansible' | grep -v 'molecule' || true)
if [ -n "$PY_FILES" ]; then
echo -e "${RED}✗ Python files not allowed (except for Ansible). Rewrite in Rust/AffineScript.${NC}"
echo "$PY_FILES"
ERRORS=$((ERRORS + 1))
fi
# Check for Makefiles
MAKEFILES=$(echo "$STAGED_FILES" | grep -iE '(^|/)Makefile(\.|$)|\.mk$' | grep -v '.github' || true)
if [ -n "$MAKEFILES" ]; then
echo -e "${RED}✗ Makefiles not allowed. Use Mustfile/justfile instead.${NC}"
echo "$MAKEFILES"
ERRORS=$((ERRORS + 1))
fi
# Check for Java/Kotlin
JVM_FILES=$(echo "$STAGED_FILES" | grep -E '\.(java|kt|kts)$' || true)
if [ -n "$JVM_FILES" ]; then
echo -e "${RED}✗ Java/Kotlin files not allowed. Use Rust/Tauri/Dioxus instead.${NC}"
echo "$JVM_FILES"
ERRORS=$((ERRORS + 1))
fi
# Check for Swift
SWIFT_FILES=$(echo "$STAGED_FILES" | grep -E '\.swift$' || true)
if [ -n "$SWIFT_FILES" ]; then
echo -e "${RED}✗ Swift files not allowed. Use Tauri/Dioxus instead.${NC}"
echo "$SWIFT_FILES"
ERRORS=$((ERRORS + 1))
fi
# Check for SPDX headers on source files
SOURCE_FILES=$(echo "$STAGED_FILES" | grep -E '\.(rs|res|js|jsx|mjs|sh|bash|zig|ex|exs|gleam|ml|mli|adb|ads|ncl)$' || true)
for file in $SOURCE_FILES; do
if [ -f "$file" ] && ! head -5 "$file" | grep -q "SPDX-License-Identifier"; then
echo -e "${YELLOW}⚠ Missing SPDX header: $file${NC}"
fi
done
# Registry / topology drift guard (standards repo only — runs where the
# generator is present). The verifiable spec registry records a content
# hash per spec home; when a tracked file under a home changes without
# regenerating, the recorded source_hash goes stale and registry-verify.yml
# reds main. (It did, three times, when spec-home edits merged without a
# regenerate.) Catch it locally, before the commit, instead of in CI.
if [ -f scripts/build-registry.sh ]; then
if ! bash scripts/build-registry.sh --check >/dev/null 2>&1; then
echo -e "${RED}✗ REGISTRY.a2ml / TOPOLOGY.md are stale — regenerate before committing.${NC}"
echo " A tracked file under a spec home (or STATE.a2ml) changed without"
echo " regenerating the derived registry/topology."
echo " Fix: bash scripts/build-registry.sh"
echo " git add .machine_readable/REGISTRY.a2ml TOPOLOGY.md"
ERRORS=$((ERRORS + 1))
fi
fi
# Final result
echo ""
if [ $ERRORS -gt 0 ]; then
echo -e "${RED}Pre-commit check failed with $ERRORS error(s)${NC}"
echo ""
echo "See: https://github.com/hyperpolymath/standards for language policy"
exit 1
else
echo -e "${GREEN}✓ All pre-commit checks passed${NC}"
fi