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 .gitattribute to prevent line ending conversion on any machine #479

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

cfbao
Copy link
Member

@cfbao cfbao commented Aug 19, 2024

Why

Git's line ending conversion has been tampering with our source code on GitHub Actions runners to be inequivalent to ones we use on our local machines.

Which line ending is used (LF vs CRLF) in raw string literals is determined by which one you use in the source file (well... they are "literals").
E.g. given the source code

string s = """
	1
	2
	""";
Console.WriteLine(s == "1\n2");
Console.WriteLine(s == "1\r\n2");

the program will

  • print True False if the source file uses LF as newline characters
  • print False True if the source file uses CRLF as newline characters

On our dev machines, we set core.autocrlf=false in Git and have end_of_line = lf in .editorconfig, so we always have LF as newline characters.
GitHub Actions Windows runners seems to be using core.autocrlf=true, so all source files were checked out with CRLF line endings...(!!!) and hence the executables built has different behaviour, because it doesn't use equivalent source code!

Unsetting the text attribute should disable line ending conversion entirely on any machine.

Ticket

https://desire2learn.atlassian.net/browse/VUL-447

@github-actions github-actions bot added the size/XS A very small PR - good job! label Aug 19, 2024
@@ -0,0 +1 @@
* -text
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is unfortunate naming on Git's part.
The text attribute only controls line ending conversion. It doesn't affect whether Git treats the file as text or binary.

See:
https://git-scm.com/docs/gitattributes#_text
https://stackoverflow.com/a/10017566/5916310

@cfbao cfbao marked this pull request as ready for review August 19, 2024 20:31
@cfbao cfbao requested a review from a team as a code owner August 19, 2024 20:31
@cfbao cfbao merged commit 5c27c17 into main Aug 19, 2024
2 checks passed
@cfbao cfbao deleted the gitattributes branch August 19, 2024 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XS A very small PR - good job!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants