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

心已入冬 提交于 2019-12-25 06:59:06

问题


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:

  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.




回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!