-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/go: document Git setup to preserve go.mod line endings on Windows #31870
Comments
gofmt does the same thing, which we've repeatedly agreed is fine (#16355, etc). I see no reason why we'd decide on a different policy for |
Ah ok, I see this is well-debated territory. My initial reaction if I were a windows end-user is to complain and disagree, but I will try and digest the referenced issue. |
Actually, there is one difference from the gofmt issue: we never ran gofmt for you automatically, but now that we're in the business of automatically rewriting I'm not sure that changes my opinion, but it is a difference. |
Here's a transcript of
and viewing the inconsequential diffs.
|
@bruceadowns, since the standard for Go tools is newline-only line endings, and even Notepad now supports that standard, it seems like the cleanest solution is to configure your Git client not to transform the line-endings to CRLF in the first place. You can configure your Git client to avoid spurious diffs by setting |
Ok, that seems like the most expedient solution for the go team. Though, I experimented with the noted settings and got the noted spurious results. Step 1 - Override git default eol settings on Windows
Step 2 - Add new files using vscode
Step 3 - View files on Linux
|
Thanks for the info @bcmills! I tried the git client settings you mentioned (core.autocrlf and core.eol), but do not get positive results. |
@bruceadowns, I generally assume that folks have some sort of format on save hook configured. Beyond that, I'm not sure why |
I suspect some client setting is out of alignment, and that will generally be the case for this overarching issue. With that said, I suspect it will not be difficult finding degenerate workflows for Windows, and subsequent ham-handed solutions to fix. This is why countless projects (scm and otherwise) have historically supported native line endings to cater to the enterprise Windows customer. |
It is cleanest solution for us Go tool developers, because we don't need to do anything. But it puts burden on every Go user that encounters this problem. They would have to deal with the problem one way or the other. Imagine if we decided to use CRLF, not LF as line delimiters in go.mod. We would have plenty of people complaining about the decision. And looking for solutions. I think, this at least needs to be documented somewhere. Maybe in Also should your suggested Git settings be local to repo or global for the whole computer? What if another development tool supplier recommends the opposite of what you recommend? Maybe we could just leave go.mod file as is (keep whatever line delimiter file has)? Alex |
@bcmills can you, please, answer my questions here #31870 (comment) I will reopen this issue, so we don't forget. Perhaps something can be done about this before go1.13 is released. Thank you. Alex |
Similar issue using Goland (Idea) on Windows 10.
Using
After another round of reading, nothing new. The only issue that I can't solve is the reading of EOF. I suspect that the last CR triggers io.EOF but the last LF is also returned. This is confusing |
add
|
Issue cannot be reproduce including EOF with
|
I'm looking for a first-time issue, so this seems safe to start with. I think it could be a FAQ on https://github.com/golang/go/wiki/Modules |
I would still try and just fix the issue instead. Things should just work. And proposed resolution of making Go users adjust their Git settings will not scale (see https://devblogs.microsoft.com/oldnewthing/20081211-00/?p=19873 for why this proposal is wrong). I would try and do what I suggested in #31870 (comment)
Alex |
Sorry for the late response. I understand your point of view, and I'm by no means qualified to take a decision, as I've seen you've debated in other similar issues as well. I agree that making Go users adjust their Git settings might not be the best solution, but my 2c in regards to why standardization to LF could make sense : The only editor currently without LF support seems to be Notepad, and I don't know if this should drive the decision. |
I have nothing against making LF standard line ending. But how do you propose to enforce this rule? Do you expect users, who struggle with this issue, somehow magically find correspondent help text at https://github.com/golang/go/wiki/Modules and adjust their Git settings ? What if their company (or open source project) rules recommend different Git settings - settings that contradict yours?
Normally go.mod will be updated by Go tools. But it can also be updated by Git or editor program.
I don't think gofmt touches go.mod file.
I am not worried about editors. I agree that most editors will handle files with whatever line endings just fine. I am worried about Git complaining that go.mod has changed after
This is how most common Git installation behaves on Windows (I selected
I propose we use LF in go.mod, but avoid rewriting CRLF into LF unless there are other non-trivial changes. This will stop triggering confusing Git warnings when building Go code.
I agree. We should not worry about what editors support. Alex |
That sounds reasonable. |
Sounds good to me, too. I'm not very familiar with the codebase, so it would take me a few days, but with some help I could try to implement a first approach. |
To be clear: we should avoid rewriting the |
How do you categorize a trivial vs non-trivial go.mod change? (i.e. what is the criteria) |
I interpreted "non-trivial" to mean semantically meaningful. Not whitespace or comments or line order. |
Comments are arguably non-trivial. Whitespace and line order are certainly trivial. |
Please, have a go. Feel free to ask for help if you get stuck.
I agree with that. Solution does not need to be perfect. Something quick and simple should be good enough. Alex |
Warning... unpopular opinion alert... The Go standard tooling should support OS native line endings when rewriting source files. This includes, but is not limited to, gofmt.exe, goimports.exe, and go.exe modules. All tools should come with CR, LF, CRLF, and AUTO end-of-line modes, thus eliminating the need for developers to contort their environment settings. I understand that this is an unfashionably banal debate, but consider that all major version control systems including git, svn, bazaar, and perforce support the ability to transmogrify line endings. And I presume these vendors chose to support it for good reason, regardless of intent. Though windows is no longer my primary target, the support for native line endings made my past life much easier. Everything just worked. Compare that positivity with the ham-handed solutions noted in previous comments. This hodgepodge of environmental workarounds will continue to frustrate until fully addressed. One simple proposal:
These flags may be set to If my argument persuades, and the proposal seems worthy, I am willing to submit PRs against https://go.googlesource.com/go and https://go.googlesource.com/tools for consideration. If not, the argument is left for posterity. |
This goes beyond what this issue is about. If you want to pursue this further, I suggest you open new issue / proposal. See https://github.com/golang/proposal for details. Thank you. Alex |
Understood. I will consider a new proposal iff there are significant upvotes. |
Change https://golang.org/cl/204878 mentions this issue: |
Updates #31870 Updates #33326 Fixes #34822 Change-Id: I1337f171133c20800eacc6b0955ede5a394ea7eb Reviewed-on: https://go-review.googlesource.com/c/go/+/204878 Run-TryBot: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
This is now implemented at head. Is there anything remaining to be done for this issue? |
That's probably sufficient. |
No. All looks good here. Thank you very much. Alex |
It seems that the Go toolchain wants to normalize go.mod's line endings even if there are no changes to the file (golang/go#31870). This normalization is disallowed by the -mod=readonly build flag, causing builds to fail. This is likely fixed by golang/go@cf3be9b, but that won't land until Go 1.14, and in any event the line ending normalization will still occur if there are changes to go.mod/go.sum generated on Windows. Signed-off-by: Jacob Howard <[email protected]>
Saves having Windows users experience pain and suffering as documented here: golang/go#31870
Saves having Windows users experience pain and suffering as documented here: golang/go#31870
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
That go.mod line endings do not change.
What did you see instead?
That changing the line endings of go.mod creates an artificial difference.
The text was updated successfully, but these errors were encountered: