Leave line endings alone

I have never had so much “fun” with line endings until today. What started out as a simple investigation in TeamCity eventually turned into an exploratory trip into the maze of git’s treatment of line endings. Here is the recount.

“Louie, we have a technical debt, there are a lot of ssis tests failing in TeamCity, can you take a look?”

“Sure”

The tests are all simple and similar in nature. They just call ssis packages to load test files into tables. Upon inspection I know immediately that this is an environmental issue as the tests reported are usually the ones we never have problems with on the local dev environment.

I open up the ssis project in Visual Studio and inspect the first package. The flat file manager is configured with {CR}{LF} as the row delimiter, check. I locate the test file and check its line endings in Notepad++, and that’s also fine, CRLF everywhere.

And indeed the test works on my local box.

I remote into the TeamCity agent and locate the same test file. Unsurprisingly LF snakes down the screen when I click on “Show All Characters”. Bingo.

I think to myself, all I need to do is to tell TeamCity to pull the files down and convert eol to CRLF, but how? There is a switch to “Convert line-endings to CRLF” but that only solves 99% of my problems as some files don’t ask me why in the test set have to have LF as line-endings. Back to square one.

.gitattributes comes to mind.

Going through blogs on the topics of autocrlf and gitattributes, my mind is filled with joy as I scroll down the posts written by wise men before me. I apply the settings religiously and again and again my hope turns into disappointment. The files in TeamCity still have lines ending in LF.

Out of desperation, I start to search for words that randomly pop up in my head. Few searches later, I am blessed with the revelation below:

TeamCity indeed doesn’t support .gitattributes.

Oh my god! Does that mean we have no other options but to accept failure. Of course not! My mind starts to mull and ponder. How about…

How about we use .gitattributes to control the eol behaviour for all dev environments and ask TeamCity not to do any eol conversion by switching off “Convert line-endings to CRLF”, good idea.

.gitattributes now looks like this:

# Don't do any eol conversion during checkin and checkout
 *.[Cc][Ss][Vv] -text
 *.[Tt][Xx][Tt] -text

TeamCity no longer converts line-endings to CRLF. All good but there is one thing left to do. I need to modify line endings for all test files once and for all.

I overwrite the files (with correct line endings, most with CRLF, some with LF), I add, I commit and I push. At last, I am blessed with a sea of green tests in TeamCity again.

–oo00oo–
Further readings:
https://help.github.com/articles/dealing-with-line-endings/
http://stackoverflow.com/questions/11116636/how-do-i-ignore-file-extensions-in-git-regardless-of-case
https://teamcity-support.jetbrains.com/hc/en-us/community/posts/206822315-Binary-files-being-corrupted-by-Auto-CRLF