Skip to content

Add a .gitattributes enforcing LF line endings - #677

Open
raffaelemancuso wants to merge 1 commit into
lrberge:masterfrom
raffaelemancuso:gitattributes-lf
Open

raffaelemancuso wants to merge 1 commit into
lrberge:masterfrom
raffaelemancuso:gitattributes-lf

Conversation

@raffaelemancuso

Copy link
Copy Markdown

Why

On Windows, Rcpp::compileAttributes() and roxygen2 write CRLF, while the
blobs in the repository are LF. Regenerating therefore rewrites
R/RcppExports.R and src/RcppExports.cpp in full — about 1,580 lines of
line-ending churn that buries whatever actually changed. I hit this while
preparing another PR: the real change was 56 lines, the diff showed 1,636.

With eol=lf, regenerating is a no-op unless the generated code really changed.
Verified: after this change, running compileAttributes() (which still writes
323 CRLF pairs into R/RcppExports.R) leaves git diff --quiet returning 0.

What is in it

* text=auto eol=lf

plus explicit binary entries, so the line-ending filter never touches binary
artifacts and git does not try to diff them as text.

I picked the binary list by scanning every tracked file for NUL bytes rather
than guessing from extensions: 184 files across .png, .PNG, .dta, .ttf,
.woff2, .RData and .pdf. The scan confirmed nothing binary falls outside
the rules. The uppercase *.PNG entry matters — there are three such files
under vignettes/images/, and these patterns are matched case-sensitively.
I also added entries for types likely to appear later (Office documents,
.rds/.rda, parquet, duckdb, archives).

Renormalisation

Only README.md needed it — it was the single text file in the repository
carrying CRLF. Its diff is line-endings only.

The 184 binary files were verified byte-identical afterwards by comparing
SHA-256 against HEAD, and git check-attr confirms they resolve with text
unset, so the eol rule is inert for them. R CMD INSTALL succeeds and the
help indices build.

One expected cosmetic effect: a file freshly written with CRLF shows as M in
git status with the notice "CRLF will be replaced by LF the next time Git
touches it"
, while git diff is empty and there is nothing to commit.

If you would rather keep the renormalisation out of git blame, the commit can
go in a .git-blame-ignore-revs.

Note

Independent of my two other PRs; they touch disjoint files.

Text files are now stored and checked out with LF, on every platform.

The motivation is generated files: on Windows, Rcpp::compileAttributes()
and roxygen2 write CRLF, so regenerating R/RcppExports.R and
src/RcppExports.cpp turned into a whole-file diff (~1,580 lines) that
buried the actual signature changes. With eol=lf the regeneration is a
no-op unless the generated code really changed.

Binary artifacts are listed explicitly so the line-ending filter never
touches them and git does not try to diff them as text: images, fonts,
pdf/Office documents, the .RData and .dta data sets, on-disk databases
and archives. The entries cover the types currently in the repository
(png/PNG, dta, ttf, woff2, RData, pdf) plus the ones likely to appear.

Only README.md needed renormalising; the 184 binary files in the
repository were verified byte-identical afterwards.

This branch has not been deployed

No deployments
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