mirror of
https://github.com/icsharpcode/ILSpy.git
synced 2026-10-12 11:09:54 +00:00
A bare `bash` on Windows can resolve to the WSL launcher
(System32\bash.exe) ahead of Git Bash, running the pre-commit hook
inside a Linux distro. There the CRLF-checked-out script fails to parse
("$'\r': command not found"), and even with clean line endings the WSL
path would install a Linux dotnet-format instead of the Windows one.
Resolve Git Bash from git.exe's install location instead, the same
CRLF-tolerant shell git itself uses to run the hook; non-Windows
platforms keep using plain bash.
Assisted-by: Claude:claude-fable-5:Claude Code
23 lines
807 B
PowerShell
23 lines
807 B
PowerShell
#!/usr/bin/env pwsh
|
|
# Trigger the commit hook's formatter against the working tree without committing,
|
|
# applying the same formatting the pre-commit hook enforces.
|
|
$ErrorActionPreference = 'Stop'
|
|
$env:OPENSSL_ENABLE_SHA1_SIGNATURES = '1'
|
|
Push-Location (Join-Path $PSScriptRoot '..')
|
|
try {
|
|
# On Windows, a bare `bash` can resolve to the WSL launcher (System32\bash.exe),
|
|
# which runs the hook inside a Linux distro where the CRLF-checked-out script
|
|
# cannot even be parsed. Pin to Git Bash, the same CRLF-tolerant shell git
|
|
# itself uses to run the pre-commit hook.
|
|
$bash = if ($IsWindows) {
|
|
Join-Path (Split-Path (Split-Path (Get-Command git).Source)) 'bin\bash.exe'
|
|
}
|
|
else {
|
|
'bash'
|
|
}
|
|
& $bash BuildTools/pre-commit --format
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
}
|