Simplify Git hook installation

This commit is contained in:
YoshiRulz 2024-06-09 12:25:01 +10:00
parent e424e716f8
commit 124a1ea509
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 3 additions and 5 deletions

View File

@ -1,5 +1,4 @@
#!/usr/bin/env -S dotnet pwsh
# placed here by BizHawk build scripts and may be updated automatically
$msg = Get-Content $args[0] -TotalCount 1 # this commit hook is always passed the commit message scratch file's path, so read the first line of that
if ($msg -Match "^fix(?:ed|es)? #\d+$") {
echo "An issue reference alone is not a suitable commit message. Vetoed."

View File

@ -1,12 +1,11 @@
$targetDir = "$PSScriptRoot/../.git/hooks"
if (Test-Path $targetDir -PathType Container) { # is Git repo
$PSCommandFilename = Split-Path $PSCommandPath -Leaf
foreach ($f in Get-ChildItem "$PSScriptRoot/git_hook_shims") {
$target = Join-Path $targetDir $f.Name
foreach ($f in Get-ChildItem "$PSScriptRoot/git_hooks") {
$target = Join-Path $targetDir (Split-Path $f -LeafBase)
if (!(Test-Path $target -PathType Leaf)) { # target file doesn't exist
echo "[$PSCommandFilename] creating Git hook $($f.Name)"
Copy-Item $f $target
#TODO generate shim? the only difference between different shims would be the filename in the Batch part (and if there was an equivalent to `basename $0` then that would be the same too
Copy-Item "$PSScriptRoot/git_hook_shim.sh" $target
#TODO use symlinks on Linux
} elseif ($(Get-FileHash $target).Hash -ne $(Get-FileHash $f.FullName).Hash) { # files differ
$head = Get-Content $target -TotalCount 3