diff options
author | Agrim Mittal <agrimmittal97@gmail.com> | 2018-05-20 01:11:04 +0530 |
---|---|---|
committer | Agrim Mittal <agrimmittal97@gmail.com> | 2018-06-28 15:35:16 +0530 |
commit | 208b47c9777f111610764fa745199633bf08c0e9 (patch) | |
tree | ebebdc914e4d82a2806a15569737c10f217eb52d /lib | |
parent | d4bd77c32502945374d0de33e6442acb15f0bbb0 (diff) | |
download | bundler-208b47c9777f111610764fa745199633bf08c0e9.tar.gz |
Save extra work when no gems are there to be removed
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/injector.rb | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index 5c96884201..005d41b07a 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -67,9 +67,15 @@ module Bundler definition = builder.to_definition(lockfile_path, {}) - definition.gemfiles.each do |g| + definition.gemfiles.each do |path| # print success for removed gems - evaluate_gemfile(g).each {|dep| Bundler.ui.confirm "#{SharedHelpers.pretty_dependency(dep, false, true)} was removed." } + removed_deps = evaluate_gemfile(path) + + if removed_deps.empty? + Bundler.ui.warn "No gems were removed." + else + removed_deps.each {|dep| Bundler.ui.confirm "#{SharedHelpers.pretty_dependency(dep, false, true)} was removed." } + end end end @@ -132,11 +138,15 @@ module Bundler # evaluate the Gemfile we have builder = Dsl.new - builder.eval_gemfile(Bundler.default_gemfile) + builder.eval_gemfile(gemfile_path) # remove gems from dependencies removed_deps = remove_gems_from_dependencies(builder, @deps) + # abort the opertion if no gems were removed + # no need to operate on gemfile furthur + return [] if removed_deps.empty? + # gemfile after removing requested gems cleaned_gemfile = remove_gems_from_gemfile(@deps, gemfile_path) @@ -160,6 +170,9 @@ module Bundler deleted_dep = builder.dependencies.find {|d| d.name == gem_name } if deleted_dep.nil? + # TODO: keeping this here yet needs to be discussed + # Bundler.ui.warn "`#{gem_name}` is not specified in Gemfile so not removed." + # return [] raise GemfileError, "You cannot remove a gem which not specified in Gemfile.\n" \ "`#{gem_name}` is not specified in Gemfile so not removed." end @@ -232,7 +245,7 @@ module Bundler def cross_check_for_errors(gemfile_path, original_deps, removed_deps, initial_gemfile) # evalute the new gemfile to look for any failure cases builder = Dsl.new - builder.eval_gemfile(Bundler.default_gemfile) + builder.eval_gemfile(gemfile_path) # record gems which were removed but not requested extra_removed_gems = original_deps - builder.dependencies |