问题
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?
回答1:
Well, it seems it's too late to fix things at this point with configuration settings
The algorithm used by git
is follows:
- 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
- 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:
- 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)
- 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.
回答2:
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.
来源:https://stackoverflow.com/questions/27155378/how-do-i-get-chef-cookbooks-to-be-downloaded-in-unix-format-on-windows