Topics

git, gofmt, and line endings

espy
 

One of my first code contributions to EdgeX was a change to a Go package (not yet public), and at the time I was surprised when reviewing the diff to see "^M" characters at the ends of lines.

My subsequent Google search/investigation left me with a bit of headache. Who could think that in 2017, we still have differing ways of denoting line endings on different OSes?

The crux of the biscuit (as Frank Zappa would've said) is that Linux and OS X/macOS use LF to terminate lines of text, whereas Windows uses CRLF.

There are various ways to deal with this problem, however after reading multiple blog posts about this, it's still not super clear what our recommended approach should be. For a good primer on the problem, checkout [1] or [2].

It turns out that the Go community has gone a bit further than git community, and mandated use of LF as it's standard. The gofmt tool will automatically convert CRLFs to LFs, and there doesn't appear to be anyway to disable this [3]. So, if we stand by our decision to always use gofmt (which is standard practice in the Go community), then we all need to be aware of the issue, and may have some short term pain converting any code which originated on Windows.

I'd like to propose that we discuss this at the next core WG meeting, as well as the next Go meeting.

Regards,
/tony

[1] http://adaptivepatchwork.com/2012/03/01/mind-the-end-of-your-line/
[2] https://help.github.com/articles/dealing-with-line-endings/
[3] https://github.com/golang/go/issues/2242