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

fixed eol config in gitattributes #1123

Merged
merged 6 commits into from
Jun 6, 2024
Merged

fixed eol config in gitattributes #1123

merged 6 commits into from
Jun 6, 2024

Conversation

Taz03
Copy link
Member

@Taz03 Taz03 commented May 25, 2024

No description provided.

@Taz03 Taz03 requested a review from a team as a code owner May 25, 2024 06:02
SquidXTV
SquidXTV previously approved these changes May 25, 2024
@Taz03 Taz03 added bug Something isn't working priority: major labels May 25, 2024
@Taz03 Taz03 self-assigned this May 25, 2024
scripts/pre-commit Outdated Show resolved Hide resolved
.gitattributes Outdated Show resolved Hide resolved
.gitattributes Outdated Show resolved Hide resolved
@surajkumar
Copy link
Contributor

Looks like this is biting us back, the reason we changed it LF was because on windows systems, when running spotless, it would change everything CLRF. The hard fix was forcing LF because nobody reads the docs lol

https://mirrors.edge.kernel.org/pub/software/scm/git/docs/gitattributes.html

Here's some documentation on .gitattributes

Since this is causing issues with other files, consider stealing sections of this:

# Ensure consistent line endings for text files
* text=auto

# Treat all Java files as text
*.java text

# Treat all Gradle files as text
*.gradle text

# Binary files
*.class binary
*.jar binary
*.war binary
*.ear binary
*.nar binary
*.kar binary
*.zip binary
*.exe binary
*.dll binary
*.so binary
*.dylib binary
*.o binary
*.a binary
*.lib binary
*.iso binary
*.tar binary
*.gz binary
*.7z binary
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.bmp binary
*.tiff binary
*.mp4 binary
*.mp3 binary
*.ogg binary
*.wav binary
*.flac binary
*.avi binary
*.mov binary
*.mkv binary
*.pdf binary
*.doc binary
*.docx binary
*.xls binary
*.xlsx binary
*.ppt binary
*.pptx binary

# Ensure Gradle wrapper scripts have LF line endings on all platforms
gradlew text eol=lf
gradlew.bat text eol=crlf

# IDE-specific files (for IntelliJ IDEA)
*.iml text
*.ipr text
*.iws text
.idea/ text

# Additional settings
# Explicitly mark UTF-8 files
*.md text eol=lf charset=utf-8
*.yml text eol=lf charset=utf-8
*.yaml text eol=lf charset=utf-8
*.json text eol=lf charset=utf-8
*.xml text eol=lf charset=utf-8

# Handle shell scripts properly
*.sh text eol=lf

@Taz03
Copy link
Member Author

Taz03 commented May 30, 2024

we still want all files LF so the config was fine, except we don't want to edit binary files because it'll make then corrupt. And also want .bat files to be CRLF.

And both of those changes are done in this pr

@marko-radosavljevic
Copy link
Contributor

marko-radosavljevic commented May 30, 2024

Yeah, auto normalization to LF is good @surajkumar, no worries. ☺️ ❤️

But you have to configure it properly. You can't force everything to LF, some win files won't work properly, and also git is not smart enough for every type of binary, and might corrupt them with changing line endings, so you might need to be explicit what to do with each binary. Also, if there is no file extension, you want to be explicit as well.

* text=auto

text

This attribute marks the path as a text file, which enables end-of-line conversion: When a matching file is added to the index, the file’s line endings are normalized to LF in the index. Conversely, when the file is copied from the index to the working directory, its line endings may be converted from LF to CRLF depending on the eol attribute, the Git config, and the platform (see explanation of eol below).

Text does normalization to LF automatically.

Set to string value "auto"

When text is set to "auto", Git decides by itself whether the file is text or binary. If it is text and the file was not already in Git with CRLF endings, line endings are converted on checkin and checkout as described above. Otherwise, no conversion is done on checkin or checkout.

Auto automatically decides if text or binary, and performs normalization to LF automatically only on text files, unless it's already in git with CRLF ending. (And we obviously don't want LF normalization on binaries, because it makes no sense, and it might corrupt those files)

So basically, this line is everything you need. It also does normalization on index (staging area) and doesn't force it in your working directory like eol=lf. Which means people can work with whatever software they prefer, and endings they want, but when committing, it will be normalized. If some binaries are not recognized, or file has no extension, you can manually specify that it is binary with this pattern *.jpg binary

Example config, since it's smarter to be explicit, and sometimes it is needed:

# This will do normalization to LF on index (staging area) 
* text=auto

*.java   text
*.html   text
*.css    text

# Explicit for linux files
*.sh     text eol=lf

# Explicit stuff for win files
*.bat    text eol=crlf

# Just to make sure git doesn't corrupt our binaries accidentally, we mark those as binary,
and, 
# it will not perform LF normalizaton. It's a good practice.
*.gif binary
*.jpg binary
*.jpeg binary
*.png binary

# No extensions, so we set them manually
/gradlew           text eol=lf

Copy link

sonarcloud bot commented May 31, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@Taz03 Taz03 mentioned this pull request Jun 1, 2024
Copy link
Contributor

@marko-radosavljevic marko-radosavljevic left a comment

Choose a reason for hiding this comment

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

That was just an example, but sure.. :D

If it works correctly, without you having to add any extra rules, I'm fine with it.

Of course test it, and apply it to everything with:

git rm -rf --cached .
git reset --hard HEAD```

@Taz03 Taz03 merged commit bf56085 into develop Jun 6, 2024
10 checks passed
@Taz03 Taz03 deleted the fixed-eol branch June 6, 2024 23:07
@ankitsmt211 ankitsmt211 mentioned this pull request Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: major
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants