From 84e337b05c79a0ddb78876de7b5201ace2f1d723 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 7 Jun 2024 15:54:39 +1000 Subject: [PATCH] Fix `install_git_hooks.ps1` failing when target file doesn't exist fixes 5c3171171 of course I covered every case but the obvious one --- Dist/install_git_hooks.ps1 | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Dist/install_git_hooks.ps1 b/Dist/install_git_hooks.ps1 index 2d2d4cd870..dbae733b31 100644 --- a/Dist/install_git_hooks.ps1 +++ b/Dist/install_git_hooks.ps1 @@ -4,16 +4,21 @@ if (Test-Path $targetDir -PathType Container) { # is Git repo $PSCommandFilename = Split-Path $PSCommandPath -Leaf foreach ($f in Get-ChildItem "$PSScriptRoot/git_hooks") { $target = Join-Path $targetDir $f.Name - if ($(Get-FileHash $target).Hash -ne $(Get-FileHash $f.FullName).Hash) { - $head = Get-Content $target -TotalCount 3 - if ($magicHeader -in $head) { - echo "[$PSCommandFilename] updating existing Git hook $($f.Name)" - Copy-Item $f $target - } else { - echo "[$PSCommandFilename] found existing Git hook $($f.Name), please resolve conflict manually" - # should probably make the scripts extensible then... - exit 1 + if (Test-Path $target -PathType Leaf) { # target file exists + if ($(Get-FileHash $target).Hash -ne $(Get-FileHash $f.FullName).Hash) { # files differ + $head = Get-Content $target -TotalCount 3 + if ($magicHeader -in $head) { + echo "[$PSCommandFilename] updating existing Git hook $($f.Name)" + Copy-Item $f $target + } else { + echo "[$PSCommandFilename] found existing Git hook $($f.Name), please resolve conflict manually" + # should probably make the scripts extensible then... + exit 1 + } } + } else { + echo "[$PSCommandFilename] creating Git hook $($f.Name)" + Copy-Item $f $target } } }