chore: install-git-hooks.ps1 for Windows
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
# Install git hooks + local manifest wrappers (not committed to git).
|
||||
# Run from repo root: .\contrib\install-git-hooks.ps1
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$Root = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
|
||||
$HookSrc = Join-Path $Root "contrib\hooks\pre-commit"
|
||||
$HookDst = Join-Path $Root ".git\hooks\pre-commit"
|
||||
$LocalDir = Join-Path $Root ".local"
|
||||
$LocalScript = Join-Path $LocalDir "build-release-manifest.ps1"
|
||||
$LocalScriptSh = Join-Path $LocalDir "build-release-manifest.sh"
|
||||
|
||||
if (-not (Test-Path (Join-Path $Root ".git"))) {
|
||||
throw "Not a git repository: $Root"
|
||||
}
|
||||
|
||||
if (-not (Test-Path $HookSrc)) {
|
||||
throw "Missing hook file: $HookSrc"
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force -Path (Split-Path $HookDst) | Out-Null
|
||||
Copy-Item -Force $HookSrc $HookDst
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $LocalDir | Out-Null
|
||||
|
||||
@'
|
||||
# Local manifest wrapper (gitignored). Manual generation on Windows.
|
||||
$ErrorActionPreference = "Stop"
|
||||
$Root = git -C "$PSScriptRoot\.." rev-parse --show-toplevel 2>$null
|
||||
if (-not $Root) {
|
||||
$Root = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
|
||||
}
|
||||
$py = Get-Command python -ErrorAction SilentlyContinue
|
||||
if (-not $py) { $py = Get-Command python3 -ErrorAction SilentlyContinue }
|
||||
if (-not $py) { throw "python not found in PATH" }
|
||||
& $py.Source (Join-Path $Root "contrib\manifest\generate.py") @args
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
'@ | Set-Content -Path $LocalScript -Encoding UTF8
|
||||
|
||||
@'
|
||||
#!/bin/bash
|
||||
# Local manifest wrapper (gitignored). Git Bash.
|
||||
set -euo pipefail
|
||||
ROOT="$(git rev-parse --show-toplevel)"
|
||||
exec python3 "$ROOT/contrib/manifest/generate.py" "$@"
|
||||
'@ | Set-Content -Path $LocalScriptSh -Encoding ASCII -NoNewline
|
||||
Add-Content -Path $LocalScriptSh -Value "`n" -NoNewline
|
||||
|
||||
Write-Host "OK: pre-commit hook -> $HookDst"
|
||||
Write-Host "OK: manual script (PS) -> $LocalScript"
|
||||
Write-Host "OK: manual script (sh) -> $LocalScriptSh"
|
||||
Write-Host ""
|
||||
Write-Host "Manual: .\.local\build-release-manifest.ps1"
|
||||
Write-Host " python contrib\manifest\generate.py"
|
||||
Write-Host "Pre-commit runs on version bump (python required in PATH)."
|
||||
Reference in New Issue
Block a user