vagrantfile now is lowercase. backwards compatible, though. [closes GH-399]

This commit is contained in:
Mitchell Hashimoto 2011-07-09 15:18:52 -07:00
parent 1cf379a1f0
commit 24337b0ca4
5 changed files with 33 additions and 12 deletions

View File

@ -24,6 +24,8 @@
needs to be downloaded during an `up`. [GH-308]
- Multiple Chef provisioners no longer overwrite cookbook folders. [GH-407]
- `package` won't delete previously existing file. [GH-408]
- Vagrantfile by default is lowercase now and Vagrant properly finds old
uppercase Vagrantfiles. [GH-399]
## 0.7.6 (July 2, 2011)

View File

@ -7,7 +7,7 @@ module Vagrant
register "init [box_name] [box_url]", "Initializes the current folder for Vagrant usage"
def execute
template "Vagrantfile.erb", "Vagrantfile"
template "vagrantfile.erb", "vagrantfile"
end
end
end

View File

@ -6,7 +6,6 @@ module Vagrant
# defined as basically a folder with a "Vagrantfile." This class allows
# access to the VMs, CLI, etc. all in the scope of this environment.
class Environment
ROOTFILE_NAME = "Vagrantfile"
HOME_SUBDIRS = ["tmp", "boxes", "logs"]
DEFAULT_VM = :default
DEFAULT_HOME = "~/.vagrant"
@ -17,6 +16,9 @@ module Vagrant
# The `cwd` that this environment represents
attr_reader :cwd
# The valid name for a Vagrantfile for this environment.
attr_reader :vagrantfile_name
# The single VM that this environment represents, in the case of
# multi-VM.
attr_accessor :vm
@ -58,11 +60,18 @@ module Vagrant
:parent => nil,
:vm => nil,
:cwd => nil,
:vagrantfile_name => nil
}.merge(opts || {})
# Set the default working directory to look for the vagrantfile
opts[:cwd] ||= Dir.pwd
opts[:cwd] = Pathname.new(opts[:cwd])
# Set the default vagrantfile name, which can be either Vagrantfile
# or vagrantfile (capital for backwards compatibility)
opts[:vagrantfile_name] ||= ["Vagrantfile", "vagrantfile"]
opts[:vagrantfile_name] = [opts[:vagrantfile_name]] if !opts[:vagrantfile_name].is_a?(Array)
opts.each do |key, value|
instance_variable_set("@#{key}".to_sym, opts[key])
end
@ -261,7 +270,10 @@ module Vagrant
return @root_path if defined?(@root_path)
root_finder = lambda do |path|
return path if File.exist?(File.join(path.to_s, ROOTFILE_NAME))
vagrantfile_name.each do |rootfile|
return path if File.exist?(File.join(path.to_s, rootfile))
end
return nil if path.root? || !File.exist?(path)
root_finder.call(path.parent)
end
@ -327,9 +339,12 @@ module Vagrant
@config_loader ||= Config.new(parent ? parent.config_loader : nil)
@config_loader.load_order = [:default, :box, :home, :root, :sub_vm]
@config_loader.set(:default, File.expand_path("config/default.rb", Vagrant.source_root))
@config_loader.set(:box, File.join(box.directory, ROOTFILE_NAME)) if !first_run && vm && box
@config_loader.set(:home, File.join(home_path, ROOTFILE_NAME)) if !first_run && home_path
@config_loader.set(:root, File.join(root_path, ROOTFILE_NAME)) if root_path
vagrantfile_name.each do |rootfile|
@config_loader.set(:box, File.join(box.directory, rootfile)) if !first_run && vm && box
@config_loader.set(:home, File.join(home_path, rootfile)) if !first_run && home_path
@config_loader.set(:root, File.join(root_path, rootfile)) if root_path
end
# If this environment is representing a sub-VM, then we push that
# proc on as the last configuration.

View File

@ -248,20 +248,23 @@ class EnvironmentTest < Test::Unit::TestCase
Pathname.new("/")
]
rootfile = "Foo"
search_seq = sequence("search_seq")
paths.each do |path|
File.expects(:exist?).with(path.join(@klass::ROOTFILE_NAME).to_s).returns(false).in_sequence(search_seq)
File.expects(:exist?).with(path.join(rootfile).to_s).returns(false).in_sequence(search_seq)
File.expects(:exist?).with(path).returns(true).in_sequence(search_seq) if !path.root?
end
assert !@klass.new(:cwd => paths.first).root_path
assert !@klass.new(:cwd => paths.first, :vagrantfile_name => rootfile).root_path
end
should "should set the path for the rootfile" do
rootfile = "Foo"
path = Pathname.new(File.expand_path("/foo"))
File.expects(:exist?).with(path.join(@klass::ROOTFILE_NAME).to_s).returns(true)
File.expects(:exist?).with(path.join(rootfile).to_s).returns(true)
assert_equal path, @klass.new(:cwd => path).root_path
assert_equal path, @klass.new(:cwd => path, :vagrantfile_name => rootfile).root_path
end
should "not infinite loop on relative paths" do
@ -269,8 +272,9 @@ class EnvironmentTest < Test::Unit::TestCase
end
should "only load the root path once" do
env = @klass.new
File.expects(:exist?).with(env.cwd.join(@klass::ROOTFILE_NAME).to_s).returns(true).once
rootfile = "foo"
env = @klass.new(:vagrantfile_name => rootfile)
File.expects(:exist?).with(env.cwd.join(rootfile).to_s).returns(true).once
assert_equal env.cwd, env.root_path
assert_equal env.cwd, env.root_path