I'm working on provisioning a few VMs using Vagrant
. Here's the situation:
Host: Windows 7 (64-bit)
Guest: Ubuntu 14.04 (64-bit)
I am having an issue getting the CRLF line endings to convert to LFs. This is causing the bash scripts in the shared folder to fail within the guest machine (see below).
vagrant@vagrant-host:/vagrant/bin$ sudo bash build-ubuntu-14.04.1-c
make.sh
build-ubuntu-14.04.1-cmake.sh: line 5: $'\r': command not found
build-ubuntu-14.04.1-cmake.sh: line 19: $'\r': command not found
: invalid option04.1-cmake.sh: line 21: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
build-ubuntu-14.04.1-cmake.sh: line 22: $'\r': command not found
build-ubuntu-14.04.1-cmake.sh: line 24: $'\r': command not found
build-ubuntu-14.04.1-cmake.sh: line 26: $'\r': command not found
build-ubuntu-14.04.1-cmake.sh: line 29: $'\r': command not found
build-ubuntu-14.04.1-cmake.sh: line 36: $'\r': command not found
build-ubuntu-14.04.1-cmake.sh: line 42: $'\r': command not found
build-ubuntu-14.04.1-cmake.sh: line 46: $'\r': command not found
build-ubuntu-14.04.1-cmake.sh: line 48: $'\r': command not found
build-ubuntu-14.04.1-cmake.sh: line 50: $'\r': command not found
build-ubuntu-14.04.1-cmake.sh: line 226: syntax error: unexpected end of file
In my Vagrantfile I have set the shell privisioner parameter binary
to false.
# Provision the VM
ubuntu.vm.provision "shell" do |s|
# replace Windows line endings with Unix line endings
s.binary = false
s.inline = "sudo apt-get update;
sudo bash vagrant/bin/build-ubuntu-14.04.1-cmake.sh"
end
As per the Vagrant documentation:
binary
(boolean) - Vagrant automatically replaces Windows line endings with Unix line endings. If this is true, then Vagrant will not do this. By default this is "false". If the shell provisioner is communicating over WinRM, this defaults to "true".
What's the issue here? Am I overlooking something in the documentation?
Update 1:
I have tried to edit my local Git settings as recommended in this Stack Overflow answer, but no luck. Also, I have added a .gitattributes
file to the root directory of the project and added the following to that file:
# detect all text files and automatically normalize them (convert CRLF to LF)
* text=auto
I have also read over "Dealing with line endings" document provided by Git. When I commit to my repository CRLFs are converted to LFs, but when I checkout changes in a Windows workspace the LFs are converted to CRLFs. This is the exact behavior I want in my Git workflow. The issue is with Vagrant. The binary
flag that I set doesn't perform the way the documentation describes.
Update 2:
Changing s.binary = true
fixed the issue. However, I think the wording in the documentation should be re-addressed. The documentation states that "If this [the flag] is true, then Vagrant will not do this [change CRLF to LF]." As I understand then, Vagrant will not change CRLFs to LFs if this flag is set. However, CRLFs are changed to LFs if this is set to true.
git
's line ending stuff only has an effect on data moving between the filesystem and the git database. It won't do a recursive dos2unix on your shared folder. It would be effective if you had a separate working directory for windows and for linux, and moved code between them withgit pull
, though. You could have the canonical committed version with LF endings, and the Windows checkout with CRLF line endings. (and the Linux checkout with no conversion, or with forced-to-LF endings.) – Gudrun1.7.1
– Kassey