-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-hooks.ps1
More file actions
127 lines (108 loc) · 4.25 KB
/
setup-hooks.ps1
File metadata and controls
127 lines (108 loc) · 4.25 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Setup script to install Git hooks for DivineOS
# Run this after cloning the repository: powershell -ExecutionPolicy Bypass -File setup-hooks.ps1
Write-Host "Setting up Git hooks for DivineOS..." -ForegroundColor Green
# Create hooks directory if it doesn't exist
$hooksDir = ".git/hooks"
if (-not (Test-Path $hooksDir)) {
New-Item -ItemType Directory -Path $hooksDir -Force | Out-Null
Write-Host "Created $hooksDir directory"
}
# Configure Git to use the hooks directory
git config core.hooksPath $hooksDir
Write-Host "Configured Git to use hooks from $hooksDir"
# Create pre-commit hook (bash script that Git can execute on all platforms)
$preCommitContent = @'
#!/bin/bash
# Pre-commit hook for DivineOS
# Enforces ruff formatting, linting, mypy, doc-drift, dead-code, and shellcheck
set -e
echo "Running ruff format check..."
ruff format --check src/ tests/ || {
echo "Formatting violations detected. Running ruff format to fix..."
ruff format src/ tests/
echo "Files formatted. Please review and stage the changes:"
git diff --name-only
echo "After reviewing, run: git add . && git commit"
exit 1
}
echo "Running ruff lint check..."
ruff check src/ tests/ || {
echo "Linting violations detected. Please fix them before committing."
exit 1
}
echo "Running mypy type check..."
mypy src/divineos --ignore-missing-imports || {
echo "Type errors detected. Please fix them before committing."
exit 1
}
echo "Checking doc counts for drift..."
python scripts/check_doc_counts.py --fix 2>/dev/null || true
git add CLAUDE.md README.md src/divineos/seed.json 2>/dev/null || true
python scripts/check_doc_counts.py || {
echo "Doc counts have drifted. Update CLAUDE.md, README.md, and/or seed.json."
exit 1
}
echo "Running vulture dead-code check..."
if command -v vulture &>/dev/null; then
vulture src/divineos/ scripts/vulture_whitelist.py --min-confidence 70 || {
echo "Dead code detected. Remove it or add to scripts/vulture_whitelist.py."
exit 1
}
else
echo " (vulture not installed, skipping — pip install vulture)"
fi
echo "Running shellcheck on hooks..."
if command -v shellcheck &>/dev/null; then
shellcheck .claude/hooks/*.sh || {
echo "Shellcheck violations in hook scripts. Fix them before committing."
exit 1
}
else
echo " (shellcheck not installed, skipping)"
fi
echo "All checks passed!"
exit 0
'@
$preCommitPath = "$hooksDir/pre-commit"
Set-Content -Path $preCommitPath -Value $preCommitContent -Encoding UTF8
Write-Host "Created pre-commit hook at $preCommitPath"
# Pre-push hook (branch-freshness check). Refuses to push branches whose
# base is stale relative to origin/main — the silent-revert precondition
# named in claim d3baec5a. Delegates to the standalone
# scripts/check_branch_freshness.sh so logic stays testable.
$prePushContent = @'
#!/bin/bash
# pre-push hook for DivineOS — branch-freshness check.
# Refuses to push a branch whose base is older than origin/main.
# Set DIVINEOS_SKIP_FRESHNESS_CHECK=1 to bypass.
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) || exit 0
SCRIPT="$REPO_ROOT/scripts/check_branch_freshness.sh"
if [[ ! -x "$SCRIPT" ]]; then
exit 0
fi
"$SCRIPT" origin main
RC=$?
if [[ $RC -eq 1 ]]; then
exit 1
fi
exit 0
'@
$prePushPath = "$hooksDir/pre-push"
Set-Content -Path $prePushPath -Value $prePushContent -Encoding UTF8
Write-Host "Created pre-push hook at $prePushPath"
Write-Host ""
Write-Host "Git hooks setup complete!" -ForegroundColor Green
Write-Host ""
Write-Host "The following checks will run before each commit:" -ForegroundColor Cyan
Write-Host " 1. ruff format --check (formatting compliance)"
Write-Host " 2. ruff check (linting)"
Write-Host " 3. mypy (type checking)"
Write-Host " 4. doc count drift (test/command counts vs reality)"
Write-Host " 5. vulture dead-code (if installed)"
Write-Host " 6. shellcheck on hooks (if installed)"
Write-Host ""
Write-Host "Pre-push hook blocks pushes from branches whose base is stale" -ForegroundColor Cyan
Write-Host "relative to origin/main (silent-revert prevention, claim d3baec5a)."
Write-Host "Bypass with: DIVINEOS_SKIP_FRESHNESS_CHECK=1 git push"
Write-Host ""
Write-Host "If any check fails, the commit will be blocked and you'll need to fix the issues." -ForegroundColor Cyan