I keep getting bit by an annoying gotcha that happens when Windows developers check out cookbooks from my Git repo with Git's autocrlf
set to true
. When they run vagrant up
to bring up a Linux VM, the cookbook files are mapped into the VM with CRLF line endings, which causes no end of obscure errors when the shell and other POSIX utilities try to operate on the (now invalid) template files that have been copied into the VM.
The fix for that is simple enough: re-clone the repository after changing the autocrlf
setting to input
or false
.
My problem is that, when you have the wrong line endings, the only symptoms are errors in strange places that in no way point to there being a problem with line endings.
How can I have Chef† check for the wrong line endings in, say, the cookbook template files and throw an error if it finds one? I think a simple Ruby snippet that does an assertion on the line endings in a given file that I can put at the top of a recipe would work.
Note: in the particular case of my repo, the sequence of steps is:
- Developer checks out repo
- Developer runs
vagrant up
- Vagrant kicks off a Chef run in the VM
- Finally, the repo's build script runs in the VM
† Or really anything else included in the repo