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

Adding .gitattributes #341

Closed
Michael1993 opened this issue Sep 25, 2020 · 7 comments · Fixed by #347
Closed

Adding .gitattributes #341

Michael1993 opened this issue Sep 25, 2020 · 7 comments · Fixed by #347

Comments

@Michael1993
Copy link
Member

To make JUnit Pioneer (and spotless) work more seamlessly, we should consider adding a .gitattributes file.
Specifically I am thinking about adding an option for line-endings (e.g.: * text eol=crlf).

@Bukama
Copy link
Member

Bukama commented Sep 25, 2020

What are the consequences for OS that have another line ending / break?

@Michael1993
Copy link
Member Author

Michael1993 commented Sep 25, 2020

I just tried on Windows 10, and spotless changed all line-endings to LF.
Which added every file in the project to the commit as "changed". 🤦
If we had .gitattributes this would not be an issue.

@Bukama
Copy link
Member

Bukama commented Sep 25, 2020

I just tried on Windows 10, and spotless changed all line-endings to LF.
Which added every file in the project to the commit as "changed". 🤦
If we had .gitattributes this would not be an issue.

Hmm never had this issue, but I have configured my Git to checkout LF for system, but keep the original LF for commiting/check in

@Bukama
Copy link
Member

Bukama commented Sep 26, 2020

I just tried on Windows 10, and spotless changed all line-endings to LF.
Which added every file in the project to the commit as "changed". 🤦
If we had .gitattributes this would not be an issue.

Hmm never had this issue, but I have configured my Git to checkout LF for system, but keep the original LF for commiting/check in

As the Git documentations says, that's because:

Note that setting core.autocrlf to true or input overrides core.eol

@dwalluck
Copy link
Contributor

The spotless authors suggest the use of .gitattributes as a fix, and you can see it used in their own repository, https://github.com/diffplug/spotless/blob/main/.gitattributes, as well as JUnit's own repository, https://github.com/junit-team/junit5/blob/main/.gitattributes.

I looked at diffplug/spotless#22, but I could not figure out if there is a way to just configure the plugin itself to handle line endings.

In my repository, I have used * -text which makes Git treat each file as binary, which means keep existing newlines. This seems like a better default behavior, since if you have a .bat or .sh file, you probably never want to change the newlines. However, this setting did not work with spotless, only * text eol=lf. Spotless seems to required that eol be set, and I don't think there's an option to keep eol unmodified, which would be the best option.

Another issue unrelated to spotless is that when using GitHub CI on Windows, it automatically changes all files newlines on checkout, and I couldn't figure out how to configure this, see actions/checkout#135.

@dwalluck
Copy link
Contributor

To make a long story short, if you're already on Linux or macOS, then you shouldn't notice any change with this. But, if you're on Windows, then this will fix the build for you and stop changing the newlines on all the source files (which for me are not the files that are checked out, but the ones that end up in the build tree).

Since even people on Windows don't want this Git "feature", I wonder if anyone does. The only thing to look out for is that if you ever need a Windows-specific file, you should add the file (or file extension) to the .gitattribues file. But, I don't see any such files in junit-pioneer.

@nipafx
Copy link
Member

nipafx commented Sep 29, 2020

Thanks @Michael1993 and @dwalluck for bringing this up. See #347 for my proposed solution.

Bukama pushed a commit that referenced this issue Sep 29, 2020
As observed in #341, without further configuration, Git uses the OS
default line ending (LF on Unix, CRLF on Windows) when writing files
to the working directory, e.g. during checkout. If other tools aren't
aware of that and edit line endings, the resulting diff is noisy.

Specifically this happened in #341, where Pioneer was checked out on
Windows (~> CRLF) and Spotless changed all line endings (to LF).

This change creates a `.gitattributes` file with the following
settings:

# all end-of-lines are normalized to LF when written to the repository
# https://git-scm.com/docs/gitattributes#_text
* text=auto

# force all text files on the working dir to have LF line endings
# https://git-scm.com/docs/gitattributes#_eol
* text eol=lf

Closes: #341
PR: #347
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants