Skip to content

fix(test): make the branch guard ordering test line-ending agnostic - #629

Merged
DevSecNinja merged 1 commit into
mainfrom
fix/chezmoi-branch-guard-test
Jul 29, 2026
Merged

fix(test): make the branch guard ordering test line-ending agnostic#629
DevSecNinja merged 1 commit into
mainfrom
fix/chezmoi-branch-guard-test

Conversation

@DevSecNinja

Copy link
Copy Markdown
Owner

The test added in #623 fails on Linux and macOS. It is currently red on main.

Cause

$guard = $body.IndexOf('Test-ChezmoiSourceBranch' + [Environment]::NewLine)

.gitattributes pins *.ps1 to eol=crlf, so the working tree is CRLF on every OS — but [Environment]::NewLine is LF on Linux/macOS. The match therefore only ever succeeded on Windows.

CI runs the Pester suite on Windows, which is why this passed review and still broke main for anyone running the suite locally on Linux or macOS.

Reproduced on a clean clone of main:

[-] Update-Chezmoi branch guard wiring.Runs the branch guard before pulling
 Expected the actual value to be greater than '-1', but got -1.
Tests Passed: 31, Failed: 1

Fix

Normalise CRLF to LF before matching. My bug from #623.

Verification

  • 463 Pester tests pass on Linux (was 462 passing + 1 failing)
  • Grepped for the same pattern elsewhere: the only other [Environment]::NewLine is in install.ps1, where it is correct (joining output for display)

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

The test introduced in #623 matched against
'Test-ChezmoiSourceBranch' + [Environment]::NewLine. .gitattributes pins
*.ps1 to eol=crlf, so the working tree is CRLF on every OS, while
[Environment]::NewLine is LF on Linux and macOS - so the match only ever
succeeded on Windows.

CI runs the Pester suite on Windows, which is why this passed review and
still broke main for anyone running the suite on Linux or macOS.

Normalise CRLF to LF before matching instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@DevSecNinja
DevSecNinja merged commit c0e07dd into main Jul 29, 2026
12 checks passed
@DevSecNinja
DevSecNinja deleted the fix/chezmoi-branch-guard-test branch July 29, 2026 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant