fix: suppress CRLF warnings in auto-commit.ps1#2258
Merged
mnriem merged 4 commits intogithub:mainfrom Apr 17, 2026
Merged
Conversation
Replace 2> with 2>&1 redirection and assignment to properly suppress stderr output including CRLF warnings on Windows. Exit code logic preserved for change detection. Fixes github#2253
The 2>&1 approach still raises terminating errors under $ErrorActionPreference='Stop'. Instead, temporarily set SilentlyContinue around all native git calls that may emit CRLF warnings to stderr (rev-parse, diff, ls-files, add, commit). Adds 5 pytest tests (TestAutoCommitPowerShellCRLF) that set core.autocrlf=true with LF-ending files. On Windows runners this triggers actual CRLF warnings; on other platforms the tests pass trivially. Fixes github#2253
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Windows failures in the git extension’s PowerShell auto-commit hook when git emits CRLF-related stderr output, and adds regression tests around CRLF warning scenarios.
Changes:
- Update
auto-commit.ps1to temporarily relax PowerShell error handling aroundgitinvocations that can emit CRLF warnings. - Add a new PowerShell-focused CRLF test suite to validate auto-commit behavior with
core.autocrlf=true.
Show a summary per file
| File | Description |
|---|---|
extensions/git/scripts/powershell/auto-commit.ps1 |
Prevent CRLF stderr output from becoming terminating errors during repo detection, change detection, and commit steps. |
tests/extensions/git/test_git_extension.py |
Add regression tests intended to cover CRLF-warning behavior for auto-commit.ps1. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 4
- Use 'Continue' instead of 'SilentlyContinue' so error output is still captured in $out for diagnostics on real git failures. - Wrap all three EAP save/restore blocks in try/finally to guarantee restoration even on unexpected exceptions. - Fix CRLF test to commit a tracked LF file first, then modify it, so git diff --quiet HEAD actually inspects the tracked change and triggers the CRLF warning on Windows.
Contributor
There was a problem hiding this comment.
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
On Windows, probe git diff stderr before running the script to verify the test setup actually produces the expected CRLF warning. This makes the regression test deterministic on the Windows runner. On non-Windows the probe is skipped (warnings don't fire there).
mnriem
approved these changes
Apr 17, 2026
Contributor
There was a problem hiding this comment.
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
Collaborator
|
Thank you! |
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.
Description
Fixes #2253
The
auto-commit.ps1script fails on Windows when git emits CRLF line-ending warnings to stderr. With$ErrorActionPreference = 'Stop', PowerShell converts any stderr output from native commands into terminatingErrorRecordexceptions — crashing the script before the2>$nullredirection can suppress them.Root Cause
PowerShell raises a
NativeCommandErrorwhen it sees any stderr output from a native command under$ErrorActionPreference = 'Stop', terminating the script before stderr redirection takes effect. Lines using2>$nullare ineffective because the error is raised before the redirection is processed.Solution
Temporarily set
$ErrorActionPreference = 'Continue'around all native git calls that may emit stderr warnings (repo detection, change detection, and staging/commit). This prevents stderr from becoming a terminating error while still allowing2>&1capture for diagnostics on real failures. Each block usestry/finallyto guarantee the preference is restored.Changes
extensions/git/scripts/powershell/auto-commit.ps1— Three git call sites wrapped with$ErrorActionPreference = 'Continue'+try/finally:git rev-parse(repo detection)git diff/git ls-files(change detection — the original crash site)git add/git commit(staging and commit)tests/extensions/git/test_git_extension.py— NewTestAutoCommitPowerShellCRLFclass with 5 tests usingcore.autocrlf=true+ LF-ending tracked files. On Windows runners the CRLF warnings fire and validate the fix end-to-end.Why This Is Safe
$ErrorActionPreferencescope; restored viafinallyblocks'Continue'(not'SilentlyContinue') so error output is still captured in$outfor diagnostics$LASTEXITCODEis unaffected byErrorActionPreference)Testing
core.autocrlf=truetriggers actual CRLF warnings to exercise the fixTestAutoCommitPowerShelltests confirm no regressions