Raise an error if multiple matching Vagrantfiles are found [GH-588]
This commit is contained in:
parent
89eb256f9d
commit
8c00d1d652
|
@ -350,24 +350,22 @@ module Vagrant
|
||||||
# with Vagrant.
|
# with Vagrant.
|
||||||
config_loader.set(:default, File.expand_path("config/default.rb", Vagrant.source_root))
|
config_loader.set(:default, File.expand_path("config/default.rb", Vagrant.source_root))
|
||||||
|
|
||||||
vagrantfile_name.each do |rootfile|
|
|
||||||
if box
|
if box
|
||||||
# We load the box Vagrantfile
|
# We load the box Vagrantfile
|
||||||
box_vagrantfile = box.directory.join(rootfile)
|
box_vagrantfile = find_vagrantfile(box.directory)
|
||||||
config_loader.set(:box, box_vagrantfile) if box_vagrantfile.exist?
|
config_loader.set(:box, box_vagrantfile) if box_vagrantfile
|
||||||
end
|
end
|
||||||
|
|
||||||
if home_path
|
if home_path
|
||||||
# Load the home Vagrantfile
|
# Load the home Vagrantfile
|
||||||
home_vagrantfile = home_path.join(rootfile)
|
home_vagrantfile = find_vagrantfile(home_path)
|
||||||
config_loader.set(:home, home_vagrantfile) if home_vagrantfile.exist?
|
config_loader.set(:home, home_vagrantfile) if home_vagrantfile
|
||||||
end
|
end
|
||||||
|
|
||||||
if root_path
|
if root_path
|
||||||
# Load the Vagrantfile in this directory
|
# Load the Vagrantfile in this directory
|
||||||
root_vagrantfile = root_path.join(rootfile)
|
root_vagrantfile = find_vagrantfile(root_path)
|
||||||
config_loader.set(:root, root_vagrantfile) if root_vagrantfile.exist?
|
config_loader.set(:root, root_vagrantfile) if root_vagrantfile
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if subvm
|
if subvm
|
||||||
|
@ -477,5 +475,35 @@ module Vagrant
|
||||||
@default_private_key_path.chmod(0600)
|
@default_private_key_path.chmod(0600)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Finds the Vagrantfile in the given directory.
|
||||||
|
#
|
||||||
|
# This will raise an error if multiple matching Vagrantfiles are found.
|
||||||
|
# This can only occur on case sensitive file systems, but if there is a
|
||||||
|
# `Vagrantfile` and a `vagrantfile` it is not clear which Vagrant will
|
||||||
|
# load, so an error must be raised.
|
||||||
|
#
|
||||||
|
# @param [Pathname] path Path to search in.
|
||||||
|
# @return [Pathname]
|
||||||
|
def find_vagrantfile(search_path)
|
||||||
|
path = nil
|
||||||
|
@vagrantfile_name.each do |vagrantfile|
|
||||||
|
current_path = search_path.join(vagrantfile)
|
||||||
|
|
||||||
|
# If the path exists, then we verify we haven't found a match before,
|
||||||
|
# then we set the path we've found.
|
||||||
|
if current_path.exist?
|
||||||
|
# We also test if current_path == path because on case insensitive
|
||||||
|
# file systems, it will look like multiple exist.
|
||||||
|
if path && current_path == path
|
||||||
|
raise Errors::MultiVagrantfileFound, :directory => search_path.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
path = current_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -193,6 +193,11 @@ module Vagrant
|
||||||
error_key(:port_collision_resume)
|
error_key(:port_collision_resume)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class MultiVagrantfileFound < VagrantError
|
||||||
|
status_code(67)
|
||||||
|
error_key(:multi_vagrantfile_found)
|
||||||
|
end
|
||||||
|
|
||||||
class MultiVMEnvironmentRequired < VagrantError
|
class MultiVMEnvironmentRequired < VagrantError
|
||||||
status_code(5)
|
status_code(5)
|
||||||
error_key(:multi_vm_required)
|
error_key(:multi_vm_required)
|
||||||
|
|
|
@ -65,7 +65,15 @@ en:
|
||||||
|
|
||||||
You specified: %{home_path}
|
You specified: %{home_path}
|
||||||
interrupted: "Vagrant exited after cleanup due to external interrupt."
|
interrupted: "Vagrant exited after cleanup due to external interrupt."
|
||||||
multi_vm_required: "A multi-vm environment is required for name specification to this command."
|
multi_vagrantfile_found: |-
|
||||||
|
Multiple Vagrantfiles were found in the following directory. This usually
|
||||||
|
occurs when multiple Vagrantfiles with different casing are found. For
|
||||||
|
example: Vagrantfile and vagrantfile. Because the behavior in this case
|
||||||
|
is undefined, please fix it so that there is only one matching Vagrantfile.
|
||||||
|
|
||||||
|
%{directory}
|
||||||
|
multi_vm_required: |-
|
||||||
|
A multi-vm environment is required for name specification to this command.
|
||||||
multi_vm_target_required: |-
|
multi_vm_target_required: |-
|
||||||
This command requires a specific VM name to target in a multi-VM environment.
|
This command requires a specific VM name to target in a multi-VM environment.
|
||||||
no_env: |-
|
no_env: |-
|
||||||
|
|
Loading…
Reference in New Issue