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

generate with a correct gitattributes #1569

Open
xenoterracide opened this issue Sep 11, 2024 · 2 comments
Open

generate with a correct gitattributes #1569

xenoterracide opened this issue Sep 11, 2024 · 2 comments
Labels

Comments

@xenoterracide
Copy link

xenoterracide commented Sep 11, 2024

it's annoying when I create a new project, the first thing I have to do is copy my .gitattributes from somewhere else lest something be committed incorrectly (like line ending fixes to lf in a .bat. autocrlf isn't really the recommended way to go these days. The best way is gitattributes. This is a good enough default for .gitattributes since these are the extensions/files that will get generated. I'm not certain if you generate with mvnw if you do then you will need to update for that.

* text=auto eol=lf
*.sh text eol=lf
*.bat text eol=crlf
*.jar -text
/gradlew text eol=lf

bat, cmd, ps will not work with lf line endings, any variant of an sh will not work with crlf, even on a windows bash (last time I tried) that's why this should be done.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 11, 2024
@mhalbritter
Copy link
Contributor

mhalbritter commented Sep 12, 2024

For reference, this is what gradle init creates:

#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew        text eol=lf

# These are Windows script files and should use crlf
*.bat           text eol=crlf

# Binary files should be left untouched
*.jar           binary

When creating such a .gitattributes file, this overrides git's core.autocrlf setting: https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings#per-repository-settings

// Edit: It only overwrites core.autocrlf for files which are specified in the .gitattributes and habe the eol= attribute set.

So, if we only look at files we create, we'd end up with:

# Gradle
/gradlew text eol=lf
*.bat text eol=crlf
*.jar binary

# Maven
/mvnw text eol=lf
*.cmd text eol=crlf

I'd talk about this with the team.

@xenoterracide
Copy link
Author

xenoterracide commented Sep 12, 2024

in the .gitattributes documentation I saw that it says that it now recommends -text

Well I guess I learned something new today, binary is a macro that includes -text

https://git-scm.com/docs/gitattributes#_defining_macro_attributes

I'd be happy with this as this is really only a problem for me when I'm trying to throw something quick together to give people as an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants