I have code (written in C#) that will run on both Linux and Windows. As part of the automated build process, unit/integration tests are run on TeamCity build machines. If a change is made, it will trigger both a Linux and Windows build, and the same unit tests will be executed on Linux and Windows.
Those build agents use git to pull down the source/build/test.
The desired behavior is for the Linux agent to have source code using Linux style (LF) line endings, while the Windows agent's code will have Windows style (CR LF) line endings. The reason for this is that the code uses multiline string literals as input to some of the unit tests, and the code under test uses Environment.NewLine
var example = @"This is a really,
really long string";
In both Linux and Windows I want to have the system defined Environment.NewLine appear in the string, but I've been unable to accomplish this given my constraints.
I do not have access to the build agents. Any settings or values that it would need to do it's job need to be captured in my source code, not some local value on the machine. My limited understanding tells me that I should rely on a .gitattributes
file, and while I've seen, and even slightly understand, some of the various settings around line endings that I can use within the .gitattributes
file.
I can't just configure the Windows machines to use core.autocrlf=true
and the Linux machines to use core.autocrlf=false
or some variation, unless I can do it only by adding or modifying files contained within my repository.
Is there a way to accomplish this using git, given my constraints?