Repository navigation
chore: add repo-wide line-ending policy via .gitattributes - #734
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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
e083c94 to
6af647f
Compare
linghengqian
left a comment
There was a problem hiding this comment.
CC @aooohan . Please help me review.
aooohan
left a comment
There was a problem hiding this comment.
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.
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'score.autocrlf/core.eol. It also covers thecompletions/*rule that the closed #726 carried.* text=auto. Git keeps auto-detecting binaries (shim.exe,test.zipand the images are never converted), and ordinary text follows the machine's checkout style as before.text eol=lffor 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 inAGENTS.mdand one test.Audit: why each group is pinned to LF
A
core.autocrlf=truecheckout (all text CRLF) was compared with an LF checkout:*.sh,completions/**$'\r': command not found, which failsTestBashZshCompletionShellFormat..goreleaser.yamlalso shipscompletions/*as-is (archives, brew, deb/rpm).*.ps1#!/usr/bin/env pwshshebang; with CRLF the interpreter becomespwsh\rwhen run directly on Linux/macOS/WSL (env: $'pwsh\r': No such file or directory).*.gogofmt -lflags all 175 Go files; with LF it lists only 3 pre-existing ones.AGENTS.mdasks forgofmt/go fmt.go.mod,go.sumgo mod tidy -diffreports a CRLFgo.sum, and the go command rewritesgo.modwith LF.*.sha256,*.sha512shasum -ckeeps the CR in the file name and cannot findshim.exe(uutilssha256sum -ctolerates 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 interactiveinternal/shared/printertest needs a TTY and was excluded). They therefore stay on thetext=autobaseline.Tests
TestCompletionScriptsUseLFLineEndingsfails if any file undercompletions/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.mddocuments the policy and how to verify a change to it.Verification
Fresh clones of this branch with
core.autocrlf=true,false,inputandcore.eol=crlfall gave:git statusclean right after clone;eol=lffiles CR-free, and the 9 binary/empty files byte-identical to an LF clone;go test ./cmd/ ./cmd/commands/passing,go mod tidy -diffclean, andgofmt -llisting only the 3 pre-existing files;bash -nOK forinstall.sh,scripts/*.shandcompletions/bash_autocomplete, andshasum -a 256/512 -cOK forshim.exe;git add --renormalize .staging nothing.The same checks on the tree before this change, with
core.autocrlf=true, fail onbash -n, thepwshshebang,shasum -c,go test ./cmd/,gofmt -landgo mod tidy -diff.Notes for reviewers
git statusstays 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,fishandpwshwere not available for the local runs, so the Zsh/Fish completion tests were skipped and.ps1files with LF line endings were not executed in PowerShell; the Windows jobs in CI and the e2e workflows are the check for that.