Pint uses LF line endings in Windows when git core.autocrlf=true
jhm-ciberman opened this issue · comments
- Pint Version: 1.2.1
- PHP Version: 8.1.12
Description:
We have developers who use windows in local environment, so we have core.autocrlf=true
in git to preserve the CRLF
on windows but commit with LF
.
When running pint, it changes all the line endings from CRLF
to LF
causing hundreds of changed files in the source control, even when the content wasn't changed at all.
I think the expected behaviors would be to preserve the line endings of the target OS. Or do you recomend us to switch to disable core.autocrlf
?
Steps To Reproduce:
- Enable
core.autocrlf=true
if not already enabled:git config --global core.autocrlf true
- Clone any laravel repository and
composer install
. - Run Laravel pint.
All the CRLF
will be changed to LF
causing hundreds of file changes.
Since this is the first report about this situation, I would advise you to stick to what is suggested by Pint. If we start to receive more reports of people asking for this feature, we will reconsider it. Thank you for the detailed report.
@nunomaduro does php-cs-fixer have a setting to leave CRLF alone?
@taylorotwell Actually, found that there is an option to specify the endingLine
: #136.
@jhm-ciberman Do you mind of follow the following steps to see if this solution we have prepared works for you?
// Run this command in your application:
composer require laravel/pint:dev-feat/line-ending --dev
// Set the following options in your `pint.json`:
{
"lineEnding": "\r\n"
}
// Run Pint again.
@nunomaduro Sorry the delay, we had a big rollover this week. It worked perfectly, all lines have changed to CRLF
and now git is happy. But I have some questions:
If I checkout our repo from Unix and run pint from Unix this will cause the opposite (LF
-> CRLF
) causing thousands of file changes, am I right?
At the moment I've done what you said in the beginning and stuck with LF
for both Unix and Windows changing my .gitattributes
file to:
- * text=auto
+ * text=auto eol=lf
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
CHANGELOG.md export-ignore
And configuring pint with the default of LF
:
{
"preset": "laravel"
}
This makes git checkout with LF
on both Unix and Windows and pint to use LF
as newline both on Unix and Windows.
Do you recommend me this approach?
Thank you for reporting this issue!
As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.
If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.
Thank you!
We don't really know what to do here ourselves. Feel free to send in a PR if you can come up with something 👍
I've been thinking about this and I think that instead of changing pint it should be better if the default laravel/laravel .gitattributes file configures git to checkout using LF
instead of the default CRLF
.
Every editor supports LF
on Windows and even the .editorconfig
for a default laravel installation uses LF
so I think it would be better to change the default .gitignore
to match Laravel Pint and the default .editorconfig
.
- * text=auto
+ * text=auto eol=lf
*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php
/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
This could be a great improvement for Laravel 10.X for windows users. This will also match the line endings with production.
What do you think? @taylorotwell
Edit: Even the .styleci.yaml for a default installation uses the laravel
preset which uses the unix_style_endings
fixer.
We changed the default in the skeleton. I guess this can be closed now?
Yes, sure! Thank you!