40 lines
1.2 KiB
PowerShell
40 lines
1.2 KiB
PowerShell
$ErrorActionPreference = "Stop"
|
|
|
|
$repoRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot ".."))
|
|
$gitDir = Join-Path $repoRoot ".git"
|
|
$hooksDir = Join-Path $gitDir "hooks"
|
|
$hookPath = Join-Path $hooksDir "post-commit"
|
|
|
|
if (-not (Test-Path $gitDir)) {
|
|
throw "No .git directory found at $repoRoot"
|
|
}
|
|
|
|
if (-not (Test-Path $hooksDir)) {
|
|
New-Item -ItemType Directory -Path $hooksDir | Out-Null
|
|
}
|
|
|
|
$hook = @'
|
|
#!/bin/sh
|
|
# Runs the repository-owned graphify post-commit updater.
|
|
|
|
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) || exit 0
|
|
CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || git diff --name-only HEAD 2>/dev/null)
|
|
|
|
if [ -z "$CHANGED" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
export GRAPHIFY_CHANGED="$CHANGED"
|
|
|
|
if command -v pwsh >/dev/null 2>&1; then
|
|
(cd "$REPO_ROOT" && pwsh -NoProfile -ExecutionPolicy Bypass -File "Tools/GraphifyPostCommit.ps1") >/dev/null 2>&1 &
|
|
elif command -v powershell.exe >/dev/null 2>&1; then
|
|
(cd "$REPO_ROOT" && powershell.exe -NoProfile -ExecutionPolicy Bypass -File "Tools/GraphifyPostCommit.ps1") >/dev/null 2>&1 &
|
|
fi
|
|
|
|
exit 0
|
|
'@
|
|
|
|
[System.IO.File]::WriteAllText($hookPath, $hook, [System.Text.UTF8Encoding]::new($false))
|
|
Write-Host "Installed graphify post-commit hook: $hookPath"
|