Pin format.ps1 to Git Bash on Windows - #3937
Merged
Merged
Conversation
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
siegfriedpammer
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
format.ps1failedformat.ps1invoked the hook with a barebash. On Windows, PATH can resolve that toC:\WINDOWS\system32\bash.exe-- the WSL launcher -- not Git Bash. The hook script then executes inside the WSL distro and dies immediately with:That's the classic CRLF failure: the repo is
* text=auto, so on WindowsBuildTools/pre-commitis checked out with CRLF line endings, and Linux bash treats each\ras part of the command. Switching the WSL distribution doesn't help -- any Linux distro's bash chokes the same way, and even with clean line endings the WSL path would need a Linuxdotnetand would install a Linuxdotnet-formatrather than the Windows one.Git Bash tolerates CRLF scripts and is what git itself uses when it runs the real pre-commit hook -- which is why committing worked while
format.ps1didn't.The fix
On Windows, resolve Git Bash from
git.exe's install location (<git-root>\bin\bash.exe) instead of taking whateverbashis first on PATH; non-Windows platforms keep using plainbash.Verified:
.\BuildTools\format.ps1now runs dotnet-format overILSpy.slnand exits 0.🤖 Generated with Claude Code