Together-Java / TJ-Bot

TJ-Bot is a Discord Bot used on the Together Java server. It is maintained by the community, anyone can contribute.
https://togetherjava.org
GNU General Public License v3.0
98 stars 82 forks source link

fixed eol config in gitattributes #1123

Closed Taz03 closed 1 month ago

surajkumar commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

Yeah, auto normalization to LF is good @surajkumar, no worries. :relaxed: :heart:

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
sonarcloud[bot] commented 1 month ago

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