How do I get chef cookbooks to be downloaded in Unix format on Windows?

488 views Asked by At

I'm using Vagrant, Chef solo and berkshelf to run up a Linux VM on Windows 7 using VirtualBox.

Cookbooks are downloaded from git and arrive with windows line endings. One of these is a Perl script, which is then uploaded to the vm and executed. However it fails because the first line is

#!/usr/bin/perl

and the Linux VM sees this as the command

#!/usr/bin/perl^M

How can I configure whichever tool needs it (probably Chef?) to download .pl files in Unix format?

2

There are 2 answers

2
user3159253 On

Well, it seems it's too late to fix things at this point with configuration settings

The algorithm used by git is follows:

  1. at index time git may convert a text file from platform specific end-of-line style (i.e. CRLF on Windows, and LF on Linux and Mac, probably CR on old Macs) to an "internal EOL representation" which is LF
  2. at checkout git converts the internal representation into platform-specific EOLs in all text files

The setting controlling whether this logic is applied or not is called core.autocrlf

So to finally solve the problem you should prepare your repository to be "cross-platform", i.e. re-index the files in all (necessary) commits so that they are put into the index as "converted text files". Is it a public repository in which existing commits shouldn't be modified or not? The recipe how to fix things depends on the "publicity".

You need to decide what is more important for you:

  1. you need proper line endings in all existing commits in the repository . However all existing commits will be overwritten and other users of the repository will have to re-clone it and then re-apply all their changes (w/ a lot of trivial conflicts)
  2. you wish to fix line endings by creating fixes only for top commits in the actual branches. Existing checkouts will get new commits as usual, and potential users problems will be less.

Here's the recipe for both methods.

0
paulmorriss On

As I can't change the cookbook repository what I did was to clone it locally and then add a file .gitattributes which contained this line:

*.pl text eol=lf

That fixed the problem.