11<#
22. SYNOPSIS
3- Sets up git pre-commit hooks for this repo (pre-commit framework ).
3+ Sets up git hooks for this repo (lefthook ).
44
55. DESCRIPTION
6- Installs the `pre-commit` package if missing and runs `pre-commit install`
6+ Installs `lefthook` if missing and runs `lefthook install`
77 so the lint/format/unit-test checks run automatically on every `git commit`.
88 Works on Windows PowerShell 5.1 and PowerShell 7+.
99#>
@@ -18,27 +18,27 @@ if (-not (Test-Command 'git')) {
1818 exit 1
1919}
2020
21- $Python = if (Test-Command ' python' ) { ' python' } elseif (Test-Command ' python3' ) { ' python3' } else { $null }
22- if (-not $Python ) {
23- Write-Error ' Python not found in PATH. Install Python 3 (python.org) with "Add to PATH" and retry.'
24- exit 1
25- }
26-
2721# Must run inside the repo so hooks land in .git/hooks.
2822$null = git rev- parse -- show-toplevel 2> $null
2923if ($LASTEXITCODE -ne 0 ) {
3024 Write-Error ' Not inside a git repository. Run this script from the repo root.'
3125 exit 1
3226}
3327
34- & $Python - m pre_commit -- version > $null 2>&1
35- if ($LASTEXITCODE -ne 0 ) {
36- Write-Host ' pre-commit not found, installing via pip...'
37- & $Python - m pip install -- user pre- commit
28+ if (-not (Test-Command ' lefthook' )) {
29+ if (Test-Command ' winget' ) {
30+ Write-Host ' lefthook not found, installing via winget...'
31+ winget install -- exact -- id evilmartians.lefthook
32+ } elseif (Test-Command ' scoop' ) {
33+ Write-Host ' lefthook not found, installing via scoop...'
34+ scoop install lefthook
35+ } else {
36+ Write-Error ' lefthook not found in PATH. Install it (winget install evilmartians.lefthook, or scoop install lefthook) and retry.'
37+ exit 1
38+ }
3839}
3940
40- # Use `python -m` so it works even if pip --user Scripts dir is not on PATH.
41- & $Python - m pre_commit install
41+ lefthook install
4242Write-Host ' '
4343Write-Host ' Done. Hooks will run on every commit.'
44- Write-Host ' To check everything right now: pre-commit run --all-files '
44+ Write-Host ' To check everything right now: lefthook run pre-commit '
0 commit comments