diff --git a/CHANGELOG.md b/CHANGELOG.md index 692c64787..11d732745 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ BUG FIXES: - core: Better error message when adding a box with a malformed version. [GH-3332] - core: Fix a rare issue where vagrant up would complain it couldn't check version of a box that doesn't exist. [GH-3326] + - core: Box version constraint can't be specified with old-style box. [GH-3260] - commands/box: Show versions when listing. [GH-3316] - commands/box: Outdated check can list local boxes that are newer. [GH-3321] - commands/status: Machine readable output contains the target. [GH-3218] diff --git a/lib/vagrant/action/builtin/box_add.rb b/lib/vagrant/action/builtin/box_add.rb index 5b199f78a..81cf19744 100644 --- a/lib/vagrant/action/builtin/box_add.rb +++ b/lib/vagrant/action/builtin/box_add.rb @@ -119,6 +119,10 @@ module Vagrant raise Errors::BoxAddNameRequired end + if env[:box_version] + raise Errors::BoxAddDirectVersion + end + provider = env[:box_provider] provider = Array(provider) if provider diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index a886560ca..d89b61fa2 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -120,6 +120,10 @@ module Vagrant error_key(:batch_multi_error) end + class BoxAddDirectVersion < VagrantError + error_key(:box_add_direct_version) + end + class BoxAddMetadataMultiURL < VagrantError error_key(:box_add_metadata_multi_url) end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index b4017f3b3..e73ce8b0c 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -336,6 +336,11 @@ en: Name: %{name} Provider: %{provider} Version: %{version} + box_add_direct_version: |- + You specified a box version constraint with a direct box file + path. Box version constraints only work with boxes from Vagrant + Cloud or a custom box host. Please remove the version constraint + and try again. box_add_metadata_multi_url: |- Multiple URLs for a box can't be specified when adding versioned boxes. Please specify a single URL to the box diff --git a/test/unit/vagrant/action/builtin/box_add_test.rb b/test/unit/vagrant/action/builtin/box_add_test.rb index e59682fae..44cf1b9b6 100644 --- a/test/unit/vagrant/action/builtin/box_add_test.rb +++ b/test/unit/vagrant/action/builtin/box_add_test.rb @@ -177,6 +177,21 @@ describe Vagrant::Action::Builtin::BoxAdd do to raise_error(Vagrant::Errors::DownloaderError) end + it "raises an error if a version was specified" do + box_path = iso_env.box2_file(:virtualbox) + + env[:box_name] = "foo" + env[:box_url] = box_path.to_s + env[:box_version] = "1" + + expect(box_collection).to receive(:add).never + + expect(app).to receive(:call).never + + expect { subject.call(env) }. + to raise_error(Vagrant::Errors::BoxAddDirectVersion) + end + it "force adds if exists and specified" do box_path = iso_env.box2_file(:virtualbox)