diff --git a/git-hooks/install.ps1 b/git-hooks/install.ps1 index 61071fa..6e6ecb6 100644 --- a/git-hooks/install.ps1 +++ b/git-hooks/install.ps1 @@ -37,5 +37,13 @@ pwsh -NoProfile -NonInteractive -ExecutionPolicy Bypass \ Write-Host "Installed bash commit-msg hook → $HooksDir" } -git config --global core.hooksPath $HooksDir -Write-Host "Global git hooks path set to: $HooksDir" +# Git for Windows bash requires POSIX drive notation (e.g. /c/Users/..., not C:\Users\...) +if ($HooksDir -match '^([A-Za-z]):[/\\](.*)$') { + $drive = $Matches[1].ToLower() + $rest = $Matches[2] -replace '\\', '/' + $posixHooksDir = "/$drive/$rest" +} else { + $posixHooksDir = $HooksDir -replace '\\', '/' +} +git config --global core.hooksPath $posixHooksDir +Write-Host "Global git hooks path set to: $posixHooksDir" diff --git a/git-hooks/tests/install.Tests.ps1 b/git-hooks/tests/install.Tests.ps1 index 1fbe42b..d10a29d 100644 --- a/git-hooks/tests/install.Tests.ps1 +++ b/git-hooks/tests/install.Tests.ps1 @@ -29,6 +29,14 @@ Describe 'install.ps1 -UsePowerShell shim' { } } + It 'should convert Windows path to POSIX drive notation when setting core.hooksPath' { + if ($IsWindows) { + $configuredPath = git config --global core.hooksPath + $configuredPath | Should -Match '^/[a-z]/' + $configuredPath | Should -Not -Match '^[A-Za-z]:' + } + } + It 'should write the commit-msg shim without a UTF-8 BOM' { $shimPath = Join-Path $tempDir 'commit-msg' $shimPath | Should -Exist