Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Git EOL consistent with .editorconfig (LF) #2231

Merged
merged 1 commit into from
Mar 10, 2024

Conversation

sharpjs
Copy link
Contributor

@sharpjs sharpjs commented Mar 10, 2024

What's In This PR

The .editorconfig file sets end_of_line = lf, but .gitattributes does not. This leaves Git to behave as per its own configuration or defaults. On Windows, it is very common (and IMO, best practice) to enable the autocrlf feature to perform EOL normalization, which transforms LF to CRLF on checkout and performs the inverse transformation on commit. For Iosevka, however, the result is that a fresh git clone consists of files with CRLFs, in contravention of the .editorconfig.

One consequence is that a Windows user following the Docker build instructions can generate a container image whose build.sh contains CRLFs, which Bash does not understand. This results in containerized Iosevka builds failing with a rather cryptic error:

image

Another consequence is that tools that understand .editorconfig might complain about inconsistent line endings and convert the CRLFs to LFs on save, generating seemingly spurious changes in git status.

A few Git commands fix this, but an easier way is to ensure that Git checks out using LF regardless of the developer's platform or Git configuration. This PR does that.

An Alternative Way

A slightly more complicated way would be to enable Git EOL normalization everywhere except for the one file that must use LF. Doing so would enable Windows users to use CRLF while everyone else (and the repository itself) remains using LF. This is the choice I make for my own repositories if the build tools support both LF and CRLF. If you'd prefer this, I am happy to change the PR.

.editorconfig

First, remove the line end_of_line = lf.
Then add:

[/docker/*.sh]
end_of_line = lf

.gitattributes

Add:

# Autodetect text files and perform EOL normalization
* text=auto

# Bash understands LF only
/docker/*.sh text eol=lf

@be5invis be5invis enabled auto-merge (squash) March 10, 2024 20:19
@be5invis be5invis merged commit b698082 into be5invis:dev Mar 10, 2024
5 checks passed
@sharpjs sharpjs deleted the git-eol branch March 11, 2024 00: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.

2 participants