Fix `install_git_hooks.ps1` failing when target file doesn't exist
fixes 5c3171171
of course I covered every case but the obvious one
This commit is contained in:
parent
8f7e613398
commit
84e337b05c
|
@ -4,16 +4,21 @@ if (Test-Path $targetDir -PathType Container) { # is Git repo
|
||||||
$PSCommandFilename = Split-Path $PSCommandPath -Leaf
|
$PSCommandFilename = Split-Path $PSCommandPath -Leaf
|
||||||
foreach ($f in Get-ChildItem "$PSScriptRoot/git_hooks") {
|
foreach ($f in Get-ChildItem "$PSScriptRoot/git_hooks") {
|
||||||
$target = Join-Path $targetDir $f.Name
|
$target = Join-Path $targetDir $f.Name
|
||||||
if ($(Get-FileHash $target).Hash -ne $(Get-FileHash $f.FullName).Hash) {
|
if (Test-Path $target -PathType Leaf) { # target file exists
|
||||||
$head = Get-Content $target -TotalCount 3
|
if ($(Get-FileHash $target).Hash -ne $(Get-FileHash $f.FullName).Hash) { # files differ
|
||||||
if ($magicHeader -in $head) {
|
$head = Get-Content $target -TotalCount 3
|
||||||
echo "[$PSCommandFilename] updating existing Git hook $($f.Name)"
|
if ($magicHeader -in $head) {
|
||||||
Copy-Item $f $target
|
echo "[$PSCommandFilename] updating existing Git hook $($f.Name)"
|
||||||
} else {
|
Copy-Item $f $target
|
||||||
echo "[$PSCommandFilename] found existing Git hook $($f.Name), please resolve conflict manually"
|
} else {
|
||||||
# should probably make the scripts extensible then...
|
echo "[$PSCommandFilename] found existing Git hook $($f.Name), please resolve conflict manually"
|
||||||
exit 1
|
# should probably make the scripts extensible then...
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
echo "[$PSCommandFilename] creating Git hook $($f.Name)"
|
||||||
|
Copy-Item $f $target
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue