Skip to content

Pin format.ps1 to Git Bash on Windows - #3937

Merged
christophwille merged 1 commit into
masterfrom
fix/format-ps1-use-git-bash
Jul 30, 2026
Merged

Pin format.ps1 to Git Bash on Windows#3937
christophwille merged 1 commit into
masterfrom
fix/format-ps1-use-git-bash

Conversation

@christophwille

Copy link
Copy Markdown
Member

Why format.ps1 failed

format.ps1 invoked the hook with a bare bash. On Windows, PATH can resolve that to C:\WINDOWS\system32\bash.exe -- the WSL launcher -- not Git Bash. The hook script then executes inside the WSL distro and dies immediately with:

BuildTools/pre-commit: line 6: $'\r': command not found
...syntax error near unexpected token `$'in\r''

That's the classic CRLF failure: the repo is * text=auto, so on Windows BuildTools/pre-commit is checked out with CRLF line endings, and Linux bash treats each \r as 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 Linux dotnet and would install a Linux dotnet-format rather 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.ps1 didn't.

The fix

On Windows, resolve Git Bash from git.exe's install location (<git-root>\bin\bash.exe) instead of taking whatever bash is first on PATH; non-Windows platforms keep using plain bash.

Verified: .\BuildTools\format.ps1 now runs dotnet-format over ILSpy.sln and exits 0.

🤖 Generated with Claude Code

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
@christophwille
christophwille merged commit e2abac9 into master Jul 30, 2026
13 checks passed
@christophwille
christophwille deleted the fix/format-ps1-use-git-bash branch July 30, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants