Skip to content

chore: add repo-wide line-ending policy via .gitattributes - #734

Merged
linghengqian merged 1 commit into
version-fox:mainfrom
linghengqian:line-ending-policy
Oct 22, 2026
Merged

linghengqian merged 1 commit into
version-fox:mainfrom
linghengqian:line-ending-policy

Conversation

@linghengqian

Copy link
Copy Markdown
Member

Fixes #727

Summary

Adds a deliberate, repo-wide line-ending policy to .gitattributes, so what lands in the working tree no longer depends on each machine's core.autocrlf / core.eol. It also covers the completions/* rule that the closed #726 carried.

  • Baseline * text=auto. Git keeps auto-detecting binaries (shim.exe, test.zip and the images are never converted), and ordinary text follows the machine's checkout style as before.
  • text eol=lf for files that a shell or tool parses byte-for-byte: *.sh, *.ps1, completions/**, *.go, go.mod, go.sum, *.sha256, *.sha512.

The change only affects checkouts: git add --renormalize . stages nothing (every committed blob is already LF, binary or empty), so the content diff is limited to the new file, one line in AGENTS.md and one test.

Audit: why each group is pinned to LF

A core.autocrlf=true checkout (all text CRLF) was compared with an LF checkout:

Pinned What breaks with CRLF
*.sh, completions/** $'\r': command not found, which fails TestBashZshCompletionShellFormat. .goreleaser.yaml also ships completions/* as-is (archives, brew, deb/rpm).
*.ps1 Four scripts carry a #!/usr/bin/env pwsh shebang; with CRLF the interpreter becomes pwsh\r when run directly on Linux/macOS/WSL (env: $'pwsh\r': No such file or directory).
*.go gofmt -l flags all 175 Go files; with LF it lists only 3 pre-existing ones. AGENTS.md asks for gofmt / go fmt.
go.mod, go.sum go mod tidy -diff reports a CRLF go.sum, and the go command rewrites go.mod with LF.
*.sha256, *.sha512 Perl's shasum -c keeps the CR in the file name and cannot find shim.exe (uutils sha256sum -c tolerates it).

No other file type has a byte-level consumer that was found (Lua, YAML, TOML, Markdown, Inno Setup scripts, the MSIX manifest, docs), and on Linux the only test that fails on a CRLF checkout is TestBashZshCompletionShellFormat (the interactive internal/shared/printer test needs a TTY and was excluded). They therefore stay on the text=auto baseline.

Tests

  • New TestCompletionScriptsUseLFLineEndings fails if any file under completions/ contains a CR. The Bash/Zsh execution tests are skipped on Windows, where CI checkouts default to CRLF, so this is what makes the Windows job exercise the new rule. Its failure message also says how to refresh a stale checkout.
  • AGENTS.md documents the policy and how to verify a change to it.

Verification

Fresh clones of this branch with core.autocrlf=true, false, input and core.eol=crlf all gave:

  • git status clean right after clone;
  • all 190 eol=lf files CR-free, and the 9 binary/empty files byte-identical to an LF clone;
  • go test ./cmd/ ./cmd/commands/ passing, go mod tidy -diff clean, and gofmt -l listing only the 3 pre-existing files;
  • bash -n OK for install.sh, scripts/*.sh and completions/bash_autocomplete, and shasum -a 256/512 -c OK for shim.exe;
  • git add --renormalize . staging nothing.

The same checks on the tree before this change, with core.autocrlf=true, fail on bash -n, the pwsh shebang, shasum -c, go test ./cmd/, gofmt -l and go mod tidy -diff.

Notes for reviewers

  • Existing CRLF checkouts are not rewritten on pull. git status stays clean, but the pinned files keep their CRLF until they are checked out again, and the new test says so. git checkout -- <path> alone does not help because git skips files whose stat is unchanged; delete the files first, then check them out.
  • zsh, fish and pwsh were not available for the local runs, so the Zsh/Fish completion tests were skipped and .ps1 files with LF line endings were not executed in PowerShell; the Windows jobs in CI and the e2e workflows are the check for that.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.05%. Comparing base (feb6092) to head (6af647f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #734   +/-   ##
=======================================
  Coverage   51.05%   51.05%           
=======================================
  Files         111      111           
  Lines        8236     8236           
=======================================
  Hits         4205     4205           
  Misses       3609     3609           
  Partials      422      422           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

What lands in the working tree used to depend on each machine's
core.autocrlf, so a CRLF checkout broke the shipped completion scripts
and TestBashZshCompletionShellFormat.

Add .gitattributes with:

- `* text=auto` as the baseline: git keeps auto-detecting binaries
  (shim.exe, test.zip and the images are never converted) and ordinary
  text follows the machine's checkout style.
- `text eol=lf` for files that a shell or tool parses byte-for-byte:
  *.sh, *.ps1 (the scripts carry a `#!/usr/bin/env pwsh` shebang),
  completions/**, *.go (gofmt -l flags CRLF sources), go.mod, go.sum
  (go mod tidy -diff flags a CRLF go.sum) and the *.sha256/*.sha512
  manifests (shasum -c keeps the CR in the file name).

Only checkouts change: `git add --renormalize .` stages nothing, and
fresh clones with core.autocrlf=true, false and input all give a clean
`git status` and a passing `go test ./cmd/ ./cmd/commands/`.

Add TestCompletionScriptsUseLFLineEndings so Windows CI, where the
Bash/Zsh execution tests are skipped and checkouts default to CRLF,
catches a regression of the completions/** rule. Document the policy in
AGENTS.md.

Fixes version-fox#727

@linghengqian linghengqian left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @aooohan . Please help me review.

@aooohan aooohan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I checked 6af647f in fresh checkouts with both core.autocrlf=true and false. The 240 files covered by the LF rules stayed CR-free, the binary files were identical, and git add --renormalize . staged no content changes.

With Go 1.24.0, go test ./cmd/... passed in both checkouts. Bash syntax checks and the SHA-256/SHA-512 manifests passed too. The note about refreshing an existing CRLF checkout is useful; pulling the attributes file alone won't rewrite those files. I don't see a blocker here.

@linghengqian
linghengqian merged commit 3231dae into version-fox:main Oct 22, 2026
6 checks passed
@linghengqian
linghengqian deleted the line-ending-policy branch October 22, 2026 10:53
@linghengqian linghengqian added this to the 1.0.14 milestone Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Repo-wide line-ending policy via .gitattributes

2 participants