Set VAGRANT_HOME env var to change vagrant home directory
This commit is contained in:
parent
a5d8193982
commit
9a158cf45a
|
@ -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)
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue