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

Add a line ending (CRLF vs LF) setting #897

Closed
Zireael07 opened this issue May 26, 2020 · 29 comments
Closed

Add a line ending (CRLF vs LF) setting #897

Zireael07 opened this issue May 26, 2020 · 29 comments

Comments

@Zireael07
Copy link

Describe the project you are working on:
N/A (this is a generic issue)
Describe the problem or limitation you are having in your project:
Copying files from Windows to Linux machine causes spurious ^M (line feed) characters.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Line ending setting would make it possible for Windows Godot not to add line feed characters, making projects truly cross-platform.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
A line ending setting similar to the one most IDEs have (PyCharm, Sublime Text 3) and/or a CRLF to LF switch button.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Nope.

Is there a reason why this should be core and not an add-on in the asset library?:
Not possible to do outside of core (has to be done in script editor) and not necessary for GDScript-exposed parts of script editor.

Related: godotengine/godot#27057

@Calinou
Copy link
Member

Calinou commented May 26, 2020

Wouldn't it be better to configure your Git client to always commit files with LF line endings?

git config --global core.autocrlf true

To convert files that were committed before setting this option, use dos2unix and commit the changes. Still, I wonder if we should make Godot save files with LF line endings on Windows to avoid trouble. This is probably reasonable as even Notepad now supports LF line endings on Windows 10.

See Customizing Git configuration for more information.

@Calinou Calinou changed the title Line ending setting Add a line ending (CRLF vs LF) setting May 26, 2020
@Zireael07
Copy link
Author

Zireael07 commented May 26, 2020

As I noted in the original issue, dos2unix will not recognize many files as text files, and therefore will do nothing. (IIRC it completely ignored tscn, escn, res and tres, and I'm not sure if it got .gd, either)

(As for Git client - valid point, but at the time I started working on those, I was exclusively on Windows and didn't know about that setting, and now I'm wary of switching that as it might mess up other forks)

@aaronfranke
Copy link
Member

aaronfranke commented May 26, 2020

I don't think there should be a setting, it should just always use LF line endings. The vast majority of tools on Windows support LF just fine, even Notepad supports LF.

There are many ways to enforce this for your project using external tools. Git has the core.autocrlf setting, there is the .gitattributes file, and you could also use this formatting script. The first thing it does is use recode to try to convert files to UTF-8, so dos2unix will recognize those files as text files. dos2unix works perfectly fine with tscn etc, I just tested it on a tscn file.

I recommend using the input setting, since it converts to LF whenever possible:

git config --global core.autocrlf input

@Zireael07
Copy link
Author

Thanks for the tip re: the formatting script.

Yes, always using LF would probably be an even simpler solution to the problem.

@aaronfranke
Copy link
Member

Closing and archiving, as the solution is "it's better to always use LF and Godot currently does this".

@Zireael07
Copy link
Author

Why archive? Windows, by default, uses CRLF and Godot does not currently "do this [referring to always using LF], as evidenced by the fact my files were full of carriage returns.
Either give us the switch or auto-convert.

@aaronfranke
Copy link
Member

@Zireael07 Can you provide the steps to reproduce this? I just created an empty project with Godot 3.2.3rc3 on Windows, then created a GDScript file, and it was filled with LF, no carriage returns anywhere.

@Zireael07
Copy link
Author

Zireael07 commented Aug 5, 2020

It was several months ago, but I believe I manually copied a Godot project from Windows 7 to the Linux laptop. It was likely created in Godot 3.1. or even earlier. Or maybe I pulled from a Git repo that was not configured as autocrlf true - as I said, it was quite a long time ago. (It's likely that a new project in a newer version will use LF indeed, but many people have started with older versions and simply migrated them to each new patch version)

@paul-marechal
Copy link

paul-marechal commented Aug 10, 2020

@Zireael07 Can you provide the steps to reproduce this? I just created an empty project with Godot 3.2.3rc3 on Windows, then created a GDScript file, and it was filled with LF, no carriage returns anywhere.

@aaronfranke This is actually an issue when versioning Godot files. I just spent the past 3 days collaborating on a small mini game with 3 other people, and I must say that the git experience was hectic thanks to Godot not using CRLF.

Git for Windows has a core.autocrlf indeed, which should convert LF from the upstream repo to CRLF locally, and then back the other way once you push. This is because applications on Windows are expected to use CRLF when writing text-like files.

The biggest pain now of having Godot use LF on Windows is that the git client will mark all the files with LF returns as different when doing git status. When doing git diff you get a bunch of warnings telling you that LF will be converted to CRLF followed by your actual changes. The confusing part is that even though you might not edit a file directly, Godot still overwrites some of them automatically, replacing the original CRLF by LF, which is counter productive because it makes git trip and it will convert it back anyway.

I think that it should be an option at the very least, and bonus point to make it CRLF by default on Windows.

@paul-marechal
Copy link

git config --global core.autocrlf input

Ok just saw this. Not sure what to think about it. On one hand I feel it would be nice for Godot to use the correct platform line ending, but on the other hand I understand you guys prefer giving users the responsibility of handling the issue. Meh.

@aaronfranke
Copy link
Member

CRLF is only expected on Windows for legacy applications. Modern applications should use LF everywhere.

With Godot, you should always have core.autocrlf set to input. This converts CRLF to LF when committing, and keeps LF when checking out local files. This basically allows Git to remove CR when it was inserted by mistake, and with this setting Git will never "trip" regardless of what files you commit.

@Zireael07
Copy link
Author

@marechal-p: I had the opposite problem, git diff tripping on Linux because of the CRLF.

As I said, I don't remember if I used git, maybe I copied files manually. And dos2unix ran on the whole folder completely ignored tscn and escn - otherwise I wouldn't have had the problem that led to creating this issue.

@paul-marechal
Copy link

I just opened a PR to mention this in the docs: godotengine/godot-docs#3891

@Avantir-Chaosfire
Copy link

I'm also affected by this, but not because of git (autocrlf does the trick). Rather, I'm using C# with Visual Studio, which always uses CRLF. And Godot always uses LF. And I often need to have files open in different editors because of the way debugging and error reporting works. So while all the files use CRLF, Godot keeps overwriting them with LF and causing Visual Studio to complain about inconsistent line endings. There's no reason not to have an option for this, you're just taking power away from the user. By all means, try and set up the default value such that most users won't have to change it. But some people always will.

@aaronfranke
Copy link
Member

@Avantir-Chaosfire You can configure Visual Studio to use LF as stated in this documentation: https://docs.microsoft.com/en-us/visualstudio/ide/encodings-and-line-breaks?view=vs-2019

@Avantir-Chaosfire
Copy link

@aaronfranke You can configure that on file by file basis, but not for Visual Studio as a whole.

@lostminds
Copy link

I just encountered this problem in Godot 4.0.beta6 and would sure like Godot either to always use the same line endings regardless of plattform (apparently it still doesn't) or allow the user to specify what to use for a project. In my case I use a mac as my main development computer and use a github repository for the code.

If I download the project to my windows machine and open the project in Godot there it rewrites and changes the line endings on all .import and .tres files in the project, so git shows they're all modified with new line endings but no changes in content. So apparently the line endings are still different at least between mac and windows, and also for some reason Godot overwrites all these files as a part of loading the project even if you don't modify anything?

@YuriSizov
Copy link
Contributor

@lostminds Git has a setting to convert line endings when you checkout or pull to match the local system, and to convert them back when you push. This is pretty much a must-have setting when you work across multiple operating systems, and it should solve your problems.

@Zireael07
Copy link
Author

@YuriSizov Not everyone uses Git, though! At the time of opening this issue, the project I was working on was a throwaway thing, so no Git either...

@YuriSizov
Copy link
Contributor

@Zireael07 Yeah, that's fair, I was just addressing the case from the comment where Git is used.

@aaronfranke
Copy link
Member

@lostminds I can't reproduce this issue, any operations I perform using Godot on Windows result in the files staying LF.

@lostminds
Copy link

@aaronfranke I just tried it again and this time it didn't change any of the .import files (may have been because last time was the first time I ran 4.0.beta6 on windows, so it re-imported all assets). But still it changed all shader .tres files, the Theme.tres file and the .godot project file from LF to CRLF line endings according to my github client.

While I didn't modify or work with any of these files I did export the project (for windows), but in my mind that shouldn't modify any of these files.

@aaronfranke
Copy link
Member

aaronfranke commented Nov 29, 2022

What do you mean by "it changed"? When you just "open the project in Godot"? Godot does not take it upon itself to go into all your files and modify them. Unless it's part of an open scene in the editor, Godot won't change the files on disk. If you open and close the Godot editor without opening any scenes, it won't change anything in your project (except project.godot). So, please describe the specific actions you are doing.

My suspicion is that you have Git configured incorrectly (run git config --global core.autocrlf input to fix).

@lostminds
Copy link

What do you mean by "it changed"? When you just "open the project in Godot"?

Ok, to be more specific: If I just open the project in Godot, this also loaded two scenes that were open last time I opened the project. This as you suspected does not modify any files, except for the project .godot file which gets the line endings changed as soon as the project is opened.

If I then immediately run the game from the editor without doing anything else the rest of the files mentioned above get changed. In other words the visual shader .tres files (8-9 of them) and the UITheme .tres file get modified changing the line endings from LF to CRLF.

I understand that there is a git setting like you mention to compensate for this issue by having git convert the line endings like you and others have mentioned. However, that's just a way to work around with the issue, and I don't see how that could be the cause of the files being changed by godot when running the project? While I guess technically possible I think it seems unlikely that the issue is the git client incorrectly reporting the change in line endings.

@Zireael07
Copy link
Author

@lostminds This is a sad consequence of two issues: one, that Godot opens and resaves the project .godot file when it opens - this once caused me to not be able to open projects, when I had a sneaky drive failure that first manifested as this problem; and two, save on run, which is generally a good thing, but in this case it seems to change the line endings.

Even more reason to have a line ending setting

@lostminds
Copy link

@Zireael07 Indeed. According to the discussion above Godot should never output CRLF line endings at all, which would also be fine for me. So hopefully this is just a bug that will be fixed. Regarding save on run I think it's fine and sort of expected for modified open scenes and resources once you know about it. But it's unexpected to me that it would re-save shader resources that haven't been modified, so maybe that is also a separate bug and the CRLF issue just makes it visible.

@hawkerm
Copy link

hawkerm commented Sep 7, 2024

Working with Godot and C# with Visual Studio 2022 on Windows 10, I'm constantly getting this dialog when opening files in VS, it's a pain:

image

Generally, most applications use the environment line ending for the system they're on, for Windows, that'd be CRLF. So, it'd be nice to see at least a setting/option for this rather than having to reconfigure a bunch of my other tools and configuration that I use for other projects/environments fine on Windows elsewhere already today.

@aaronfranke
Copy link
Member

@hawkerm I recommend configuring Visual Studio to use LF instead. This way your files will have consistent line endings regardless of operating system. Plus, if Git strips the carriage returns, or if you copy a file from Mac/Linux, you will have to deal with LF on Windows anyway.

@Manenderrr
Copy link

Forcing the user to use a specific line ending without possibility of customisation does not sound great

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

No branches or pull requests

9 participants