From 24337b0ca46b4821f32d69144c8ae5a8a0894b80 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 9 Jul 2011 15:18:52 -0700 Subject: [PATCH] vagrantfile now is lowercase. backwards compatible, though. [closes GH-399] --- CHANGELOG.md | 2 ++ lib/vagrant/command/init.rb | 2 +- lib/vagrant/environment.rb | 25 +++++++++++++++---- .../{Vagrantfile.erb => Vagrantfile.erb.bak} | 0 test/vagrant/environment_test.rb | 16 +++++++----- 5 files changed, 33 insertions(+), 12 deletions(-) rename templates/commands/init/{Vagrantfile.erb => Vagrantfile.erb.bak} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 210c15849..fd07dabbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/vagrant/command/init.rb b/lib/vagrant/command/init.rb index 3e2b4b9a8..3a9576777 100644 --- a/lib/vagrant/command/init.rb +++ b/lib/vagrant/command/init.rb @@ -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 diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index d7a985296..0adf83fc0 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -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. diff --git a/templates/commands/init/Vagrantfile.erb b/templates/commands/init/Vagrantfile.erb.bak similarity index 100% rename from templates/commands/init/Vagrantfile.erb rename to templates/commands/init/Vagrantfile.erb.bak diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index 004db8058..babc5a715 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -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