chore: normalise line endings to lf and enforce it - #4
Merged
Conversation
Line endings differed per file and per repository, and an edit made on Windows - or by any tool that normalises newlines - silently rewrote a whole file. That turned a 29 line README change into a 273 line diff and a 101 line change to BaseCache.java into a 459 line diff, which makes a review impossible and a commit look far riskier than it is. Three parts, because none of them is sufficient alone: .gitattributes normalises on `git add`, so a contributor core.autocrlf setting cannot put CRLF into the index. Extensions are listed explicitly rather than relying on `text=auto` alone: event-processor-contract has had a `* text=auto eol=lf` rule since its line ending PR and still carried a CRLF .gitignore and a mixed README, so the heuristic is not something to depend on. Batch files keep CRLF, cmd.exe wants it. `git add --renormalize .`, in this commit, for the files already committed. Adding the attributes does not retroact - that is exactly how the two files above kept their CRLF for years. A CI check, which is the actual guarantee: `git ls-files --eol` reports what is in the index, so anything that slips past the attributes fails the build with the offending files listed. .editorconfig is there so an editor does not fight the attributes in the working tree. Verified per repository with `git diff --cached --ignore-cr-at-eol --stat`: apart from the files this commit adds, nothing changed but line endings. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Makes LF the line ending everywhere, and stops it drifting again.
Why
Line endings differed per file and per repository, so an edit made on Windows — or by any tool that normalises newlines — silently rewrote a whole file. That turned a 29 line README change into a 273 line diff, and a 101 line change to
BaseCache.javainto a 459 line diff. A diff that size cannot be reviewed and makes a commit look far riskier than it is.Three parts, because none of them is enough alone
.gitattributesnormalises ongit add, so a contributor'score.autocrlfcannot put CRLF into the index. Extensions are listed explicitly rather than relying ontext=autoalone —event-processor-contracthas carried a* text=auto eol=lfrule since its own line ending PR and still had a CRLF.gitignoreand a mixedREADME.md, so the heuristic is not something to depend on.*.batand*.cmdkeep CRLF, because cmd.exe wants it.git add --renormalize ., in this commit, for what is already committed. Adding the attributes does not retroact — that is precisely how those two files kept their CRLF for years.A CI check, which is the actual guarantee, in
.github/workflows/validate.yml:git ls-files --eolreports what is in the index, not the working tree, so it cannot be fooled by a local checkout and it names the offending files. This is what turns the convention into enforcement..editorconfigis there so an editor does not fight the attributes in the working tree.This commit
55 files changed, 2261 insertions(+), 2166 deletions(-), of which 52 are line endings only.Verified with
git diff --cached --ignore-cr-at-eol --statbefore committing: apart from the files this commit adds, nothing changed but line endings. Worth reproducing on the merge commit rather than reading 251 files —After merging
Working copies keep their old CRLF until the files are re-checked-out —
eol=lfapplies on checkout and git will not rewrite files it considers unmodified. Nothing breaks, and the nextgit addnormalises anyway, but to refresh a clone in one go:Untracked files are not touched by either command. Afterwards
mvnw.cmdis the only file left with CRLF in the working tree, which is intended.