Skip to content

Commit

Permalink
[rubygems/rubygems] Improve validation of bundle plugin install opt…
Browse files Browse the repository at this point in the history
…ions

Ensure only one source type is specified, and ensure options that
are only relevant to git sources are only specified with git.

rubygems/rubygems@58b043215e
  • Loading branch information
ccutrer authored and matzbot committed Mar 25, 2024
1 parent 65264b0 commit 5526471
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
13 changes: 13 additions & 0 deletions lib/bundler/plugin/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,24 @@ def check_sources_consistency!(options)
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)
Expand Down
14 changes: 8 additions & 6 deletions spec/bundler/plugins/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,18 @@
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
Expand Down

0 comments on commit 5526471

Please sign in to comment.