diff --git a/CHANGELOG.md b/CHANGELOG.md index 1308ec73e..8c2af39e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ - Vagrant source now has a `contrib` directory where contributions of miscellaneous addons for Vagrant will be added. - Vagrantfiles are now loaded only once (instead of 4+ times) [GH-238] + - Ability to move home vagrant dir (~/.vagrant) by setting VAGRANT_HOME + environmental variable. ## 0.7.0.beta (December 24, 2010) diff --git a/config/default.rb b/config/default.rb index 99a58a4d6..f313af3b8 100644 --- a/config/default.rb +++ b/config/default.rb @@ -1,7 +1,6 @@ Vagrant::Config.run do |config| # default config goes here config.vagrant.dotfile_name = ".vagrant" - config.vagrant.home = "~/.vagrant" config.vagrant.host = :detect config.ssh.username = "vagrant" diff --git a/lib/vagrant/config/vagrant.rb b/lib/vagrant/config/vagrant.rb index ee4856e0b..545ec4859 100644 --- a/lib/vagrant/config/vagrant.rb +++ b/lib/vagrant/config/vagrant.rb @@ -4,15 +4,10 @@ module Vagrant configures :vagrant attr_accessor :dotfile_name - attr_accessor :home attr_accessor :host - def initialize - @home = nil - end - def validate(errors) - [:dotfile_name, :home, :host].each do |field| + [:dotfile_name, :host].each do |field| errors.add(I18n.t("vagrant.config.common.error_empty", :field => field)) if !instance_variable_get("@#{field}".to_sym) end end diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 73bc26cf8..f10bf12f6 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -9,6 +9,7 @@ module Vagrant ROOTFILE_NAME = "Vagrantfile" HOME_SUBDIRS = ["tmp", "boxes", "logs"] DEFAULT_VM = :default + DEFAULT_HOME = "~/.vagrant" # Parent environment (in the case of multi-VMs) attr_reader :parent @@ -82,12 +83,11 @@ module Vagrant root_path.join(config.vagrant.dotfile_name) rescue nil end - # The path to the home directory, expanded relative to the root path, - # and converted into a Pathname object. + # The path to the home directory and converted into a Pathname object. # # @return [Pathname] def home_path - @_home_path ||= Pathname.new(File.expand_path(config.vagrant.home, root_path)) + @_home_path ||= Pathname.new(File.expand_path(ENV["VAGRANT_HOME"] || DEFAULT_HOME)) end # The path to the Vagrant tmp directory diff --git a/lib/vagrant/test_helpers.rb b/lib/vagrant/test_helpers.rb index 231d66005..72cb58849 100644 --- a/lib/vagrant/test_helpers.rb +++ b/lib/vagrant/test_helpers.rb @@ -31,8 +31,8 @@ module Vagrant str = args.shift || "" File.open(path.to_s, "w") do |f| + f.puts "ENV['VAGRANT_HOME'] = '#{home_path}'" f.puts "Vagrant::Config.run do |config|" - f.puts "config.vagrant.home = '#{home_path}'" f.puts "config.vm.base_mac = 'foo' if !config.vm.base_mac" f.puts "config.vm.box = 'base'" f.puts str diff --git a/test/vagrant/config/vagrant_test.rb b/test/vagrant/config/vagrant_test.rb index a2436dee0..4ca3091e6 100644 --- a/test/vagrant/config/vagrant_test.rb +++ b/test/vagrant/config/vagrant_test.rb @@ -8,7 +8,6 @@ class ConfigVagrantTest < Test::Unit::TestCase context "validation" do setup do @config.dotfile_name = "foo" - @config.home = "foo" @config.host = "foo" @errors = Vagrant::Config::ErrorRecorder.new @@ -26,13 +25,6 @@ class ConfigVagrantTest < Test::Unit::TestCase assert !@errors.errors.empty? end - should "be invalid with no home" do - @config.home = nil - - @config.validate(@errors) - assert !@errors.errors.empty? - end - should "be invalid with no host" do @config.host = nil diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index 2810a6e3b..1932ef10d 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -61,8 +61,21 @@ class EnvironmentTest < Test::Unit::TestCase end context "home path" do + setup do + @env = @klass.new + end + should "return the home path if it loaded" do - expected = Pathname.new(File.expand_path(@env.config.vagrant.home, @env.root_path)) + ENV["VAGRANT_HOME"] = nil + + expected = Pathname.new(File.expand_path(@klass::DEFAULT_HOME)) + assert_equal expected, @env.home_path + end + + should "return the home path set by the environmental variable" do + ENV["VAGRANT_HOME"] = "foo" + + expected = Pathname.new(File.expand_path(ENV["VAGRANT_HOME"])) assert_equal expected, @env.home_path end end