Don't require root path to load an environment. (Makes `vagrant box` commands work again without a Vagrantfile)

This commit is contained in:
Mitchell Hashimoto 2010-09-16 18:14:41 -06:00
parent 49df1875c4
commit ba8307712d
3 changed files with 11 additions and 3 deletions

View File

@ -12,6 +12,8 @@ module Vagrant
# This returns an array of {VM} objects depending on the arguments
# given to the command.
def target_vms(name=nil)
raise Errors::NoEnvironmentError.new if !env.root_path
name ||= self.name rescue nil
@target_vms ||= begin

View File

@ -220,7 +220,6 @@ module Vagrant
def load!
if !loaded?
@loaded = true
raise Errors::NoEnvironmentError.new if !root_path
self.class.check_virtualbox!
load_config!
load_vm!
@ -242,7 +241,7 @@ module Vagrant
loader.queue << File.expand_path("config/default.rb", Vagrant.source_root)
loader.queue << File.join(box.directory, ROOTFILE_NAME) if !first_run && box
loader.queue << File.join(home_path, ROOTFILE_NAME) if !first_run && home_path
loader.queue << File.join(root_path, ROOTFILE_NAME)
loader.queue << File.join(root_path, ROOTFILE_NAME) if root_path
# If this environment is representing a sub-VM, then we push that
# proc on as the last configuration.

View File

@ -27,7 +27,14 @@ class CommandHelpersTest < Test::Unit::TestCase
context "vms from args" do
setup do
@env = vagrant_env
@env.stubs(:root_path).returns(7)
end
should "raise an exception if no root path" do
@env.stubs(:root_path).returns(nil)
assert_raises(Vagrant::Errors::NoEnvironmentError) {
command([], @env).target_vms
}
end
should "only calculate the result once" do