diff options
author | Colby Swandale <colby@taplaboratories.com> | 2017-04-03 23:09:34 +1000 |
---|---|---|
committer | Colby Swandale <colby@taplaboratories.com> | 2017-04-03 23:15:54 +1000 |
commit | 10e6f73bf230bb4478184b6e539c5f25417c6563 (patch) | |
tree | c9a9746730b68a6d6d0daa0064195be23ced7a95 | |
parent | fa61ff501492b74cb11cff1fef82aa9038784511 (diff) | |
download | bundler-10e6f73bf230bb4478184b6e539c5f25417c6563.tar.gz |
print an error message when a non-git gem is given a `branch` option
-rw-r--r-- | lib/bundler/dsl.rb | 4 | ||||
-rw-r--r-- | spec/bundler/dsl_spec.rb | 5 |
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index cdbae076f0..ec434bf622 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -321,6 +321,10 @@ module Bundler normalize_hash(opts) + if opts["branch"] && !(opts["git"] || opts["github"]) + raise GemfileError, %(The `branch` option for `gem "#{name}"` is not allowed. Only gems with a git source can specify a branch) + end + git_names = @git_sources.keys.map(&:to_s) validate_keys("gem '#{name}'", opts, valid_keys + git_names) diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb index 0561cb7ddc..7e43f76d76 100644 --- a/spec/bundler/dsl_spec.rb +++ b/spec/bundler/dsl_spec.rb @@ -144,6 +144,11 @@ RSpec.describe Bundler::Dsl do expect { subject.gem(:foo) }. to raise_error(Bundler::GemfileError, /You need to specify gem names as Strings. Use 'gem "foo"' instead/) end + + it "rejects branch option on non-git gems" do + expect { subject.gem("foo", :branch => "test") }. + to raise_error(Bundler::GemfileError, /The `branch` option for `gem "foo"` is not allowed. Only gems with a git source can specify a branch/) + end end describe "#gemspec" do |