From 95aba27e59caf8a94747529130070958f39a6545 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 5 Sep 2013 14:46:15 -0700 Subject: [PATCH] core: VAGRANT_VAGRANTFILE affects only project vagrantfile [GH-2130] --- CHANGELOG.md | 2 ++ lib/vagrant/environment.rb | 17 +++++++---------- test/unit/vagrant/environment_test.rb | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67d1b26b7..99d6c119f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ BUG FIXES: - core: Fix various issues where using the same options hash in a Vagrantfile can cause errors. + - core: `VAGRANT_VAGRANTFILE` env var only applies to the project + Vagrantfile name. [GH-2130] - provisioners/puppet: No more "shared folders cannot be found" error. [GH-2134] diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index f1899c529..4ef18f2e1 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -85,9 +85,8 @@ module Vagrant # those continue to work as well, but anything custom will take precedence. opts[:vagrantfile_name] ||= ENV["VAGRANT_VAGRANTFILE"] if \ ENV.has_key?("VAGRANT_VAGRANTFILE") - opts[:vagrantfile_name] ||= ["Vagrantfile", "vagrantfile"] opts[:vagrantfile_name] = [opts[:vagrantfile_name]] if \ - !opts[:vagrantfile_name].is_a?(Array) + opts[:vagrantfile_name] && !opts[:vagrantfile_name].is_a?(Array) # Set instance variables for all the configuration parameters. @cwd = opts[:cwd] @@ -251,7 +250,7 @@ module Vagrant home_vagrantfile = nil root_vagrantfile = nil home_vagrantfile = find_vagrantfile(home_path) if home_path - root_vagrantfile = find_vagrantfile(root_path) if root_path + root_vagrantfile = find_vagrantfile(root_path, @vagrantfile_name) if root_path # Create the configuration loader and set the sources that are global. # We use this to load the configuration, and the list of machines we are @@ -539,11 +538,8 @@ module Vagrant root_finder = lambda do |path| # Note: To remain compatible with Ruby 1.8, we have to use # a `find` here instead of an `each`. - found = vagrantfile_name.find do |rootfile| - File.exist?(File.join(path.to_s, rootfile)) - end - - return path if found + vf = find_vagrantfile(path, @vagrantfile_name) + return path if vf return nil if path.root? || !File.exist?(path) root_finder.call(path.parent) end @@ -715,8 +711,9 @@ module Vagrant # # @param [Pathname] path Path to search in. # @return [Pathname] - def find_vagrantfile(search_path) - @vagrantfile_name.each do |vagrantfile| + def find_vagrantfile(search_path, filenames=nil) + filenames ||= ["Vagrantfile", "vagrantfile"] + filenames.each do |vagrantfile| current_path = search_path.join(vagrantfile) return current_path if current_path.exist? end diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index 971bca9f7..5f571f7cb 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -581,6 +581,31 @@ VF machine.config.ssh.port.should == 100 end + it "should load the box configuration for a V2 box and custom Vagrantfile name" do + register_provider("foo") + + environment = isolated_environment do |env| + env.file("some_other_name", <<-VF) +Vagrant.configure("2") do |config| + config.vm.box = "base" +end +VF + + env.box2("base", :foo, :vagrantfile => <<-VF) +Vagrant.configure("2") do |config| + config.ssh.port = 100 +end +VF + end + + env = with_temp_env("VAGRANT_VAGRANTFILE" => "some_other_name") do + environment.create_vagrant_env + end + + machine = env.machine(:default, :foo) + machine.config.ssh.port.should == 100 + end + it "should load the box configuration for other formats for a V2 box" do register_provider("foo", nil, box_format: "bar")