summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bundler/plugin/installer.rb13
-rw-r--r--spec/bundler/plugins/install_spec.rb14
2 files changed, 21 insertions, 6 deletions
diff --git a/lib/bundler/plugin/installer.rb b/lib/bundler/plugin/installer.rb
index 7ae56440fb..7267f58f5d 100644
--- a/lib/bundler/plugin/installer.rb
+++ b/lib/bundler/plugin/installer.rb
@@ -43,11 +43,24 @@ module Bundler
if options.key?(:git) && options.key?(:local_git)
raise InvalidOption, "Remote and local plugin git sources can't be both specified"
end
+
# back-compat; local_git is an alias for git
if options.key?(:local_git)
Bundler::SharedHelpers.major_deprecation(2, "--local_git is deprecated, use --git")
options[:git] = options.delete(:local_git)
end
+
+ if (options.keys & [:source, :git]).length > 1
+ raise InvalidOption, "Only one of --source, or --git may be specified"
+ end
+
+ if (options.key?(:branch) || options.key?(:ref)) && !options.key?(:git)
+ raise InvalidOption, "--#{options.key?(:branch) ? "branch" : "ref"} can only be used with git sources"
+ end
+
+ if options.key?(:branch) && options.key?(:ref)
+ raise InvalidOption, "--branch and --ref can't be both specified"
+ end
end
def install_git(names, version, options)
diff --git a/spec/bundler/plugins/install_spec.rb b/spec/bundler/plugins/install_spec.rb
index d4776bbed7..86eb4e584c 100644
--- a/spec/bundler/plugins/install_spec.rb
+++ b/spec/bundler/plugins/install_spec.rb
@@ -92,16 +92,18 @@ RSpec.describe "bundler plugin install" do
expect(out).to include("Using foo 1.1")
end
- it "installs when --branch specified" do
- bundle "plugin install foo --branch main --source #{file_uri_for(gem_repo2)}"
+ it "raises an error when when --branch specified" do
+ bundle "plugin install foo --branch main --source #{file_uri_for(gem_repo2)}", raise_on_error: false
- expect(out).to include("Installed plugin foo")
+ expect(out).not_to include("Installed plugin foo")
+
+ expect(err).to include("--branch can only be used with git sources")
end
- it "installs when --ref specified" do
- bundle "plugin install foo --ref v1.2.3 --source #{file_uri_for(gem_repo2)}"
+ it "raises an error when --ref specified" do
+ bundle "plugin install foo --ref v1.2.3 --source #{file_uri_for(gem_repo2)}", raise_on_error: false
- expect(out).to include("Installed plugin foo")
+ expect(err).to include("--ref can only be used with git sources")
end
it "raises error when both --branch and --ref options are specified" do