Files in checkout have EOL changed from LF to CRLF


#1

The checkout is changing line endings of files. This can lead to automated checks such as go fmt failing. In my case I have testdata where the byte offset of tokens is important, leading to my tests failing.

I use the following step to adjust files back to LF

- find . -name '*.go' -type f -print0 | xargs -0 sed -i ':a;N;$!ba;s/\r//g'

I tried to unset the “text” gitattribute, which according to gits documentation should prevent automatic line ending changes. However, the issue still persisted. For reference I have the following for my .gitattributes:

# We have tests which parse files and fail if file offsets change. So disable
# EOL conversions.
**/testdata/* -text

The PR which enabled windows support is https://github.com/sourcegraph/go-langserver/pull/329
I originally mentioned this issue in another discussion Go can't find GCC with go1.11.1 on Windows


Go can't find GCC with go1.11.1 on Windows
#2

You might be able to do it with gitattributes, but a bit different syntax. For example:
* text=auto
*.js text eol=lf
*.sass text eol=lf
*.json text eol=lf
*.css text eol=lf
*.html text eol=lf
*.htm text eol=lf


#3

The issue here appears to be that git is configured as follows (taken from a Windows-based build):

$ git config -l
core.symlinks=false
core.autocrlf=true
...

This feels like the wrong default (https://git-scm.com/docs/gitattributes#_checking_out_and_checking_in) because otherwise there’s a considerable amount of work required to undo this behaviour. If anything, I would suggest making the default false and then allowing people to configure it to true in the .travis.yml git: section (https://docs.travis-ci.com/user/customizing-the-build/#git-clone-depth)

My current work around is the following addition to my .travis.yml:

before_install:
  - cd ../..
  - mv $TRAVIS_REPO_SLUG _old
  - git config --global core.autocrlf false
  - git clone --depth=50 _old $TRAVIS_REPO_SLUG
  - cd $TRAVIS_REPO_SLUG

Edit to fix env var name

Edit to fix error in before_install


Feature request: Update Git configure `core.autocrlf`
#4

An update on my side. I have not tried travis windows support since I originally posted this issue. We ran into other issues so I am unsure what the current status of this is.

@AviVahl hi Avi sorry I missed your response. Unsetting the text attribute should disable any EOL conversions in git, which is what I did in the gitattributes. Forcing the line endings sounds like a reasonable workaround (for text data), but either way the proper gitattribute is not being respected. According to the git documentation it should work, but maybe there is an outdated windows version in the image?


#5

In rust-clippy we managed to work around this using the dos2unix utility on affected files: https://github.com/rust-lang/rust-clippy/pull/3418/files#diff-354f30a63fb0907d4ad57269548329e3R46


#6

Another workaround would be to use the .gitattributes file and enforce LF for lineendings:

# ./.gitattributes

* text=auto eol=lf

#7