summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-08-20 17:28:22 -0400
committerSamuel Giddins <segiddins@segiddins.me>2017-08-28 16:21:49 -0500
commit468993fbc4993f90ba780a2161c63c0bc3862255 (patch)
tree663e6d6642277fcb273f31e51d5e65ad40bda045
parent6ce61e7c6060d1d7a45a131031be472aa25e1d7e (diff)
downloadbundler-468993fbc4993f90ba780a2161c63c0bc3862255.tar.gz
Automatically bundle clean without a path set on 2.0
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/cli/add.rb2
-rw-r--r--lib/bundler/cli/binstubs.rb2
-rw-r--r--lib/bundler/cli/common.rb8
-rw-r--r--lib/bundler/cli/info.rb2
-rw-r--r--lib/bundler/cli/install.rb4
-rw-r--r--lib/bundler/cli/lock.rb2
-rw-r--r--lib/bundler/cli/open.rb1
-rw-r--r--lib/bundler/cli/outdated.rb2
-rw-r--r--lib/bundler/cli/pristine.rb2
-rw-r--r--lib/bundler/cli/show.rb2
-rw-r--r--lib/bundler/cli/update.rb4
-rw-r--r--lib/bundler/feature_flag.rb5
-rw-r--r--lib/bundler/settings.rb1
-rw-r--r--man/bundle-config.ronn5
-rw-r--r--spec/commands/clean_spec.rb24
-rw-r--r--spec/commands/exec_spec.rb2
-rw-r--r--spec/commands/outdated_spec.rb2
-rw-r--r--spec/commands/update_spec.rb1
-rw-r--r--spec/install/allow_offline_install_spec.rb1
-rw-r--r--spec/plugins/source/example_spec.rb8
-rw-r--r--spec/update/git_spec.rb18
22 files changed, 69 insertions, 31 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 69bb5f0ac3..771cc09149 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -5,6 +5,8 @@ require "bundler/vendored_thor"
module Bundler
class CLI < Thor
+ require "bundler/cli/common"
+
AUTO_INSTALL_CMDS = %w[show binstubs outdated exec open console licenses clean].freeze
PARSEABLE_COMMANDS = %w[
check config help exec platform show version
diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb
index 3a10371994..1fcbd22f28 100644
--- a/lib/bundler/cli/add.rb
+++ b/lib/bundler/cli/add.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require "bundler/cli/common"
-
module Bundler
class CLI::Add
def initialize(options, gem_name)
diff --git a/lib/bundler/cli/binstubs.rb b/lib/bundler/cli/binstubs.rb
index 1869eee628..449204d821 100644
--- a/lib/bundler/cli/binstubs.rb
+++ b/lib/bundler/cli/binstubs.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require "bundler/cli/common"
-
module Bundler
class CLI::Binstubs
attr_reader :options, :gems
diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb
index 018f7bfdc9..9d40ee9dfd 100644
--- a/lib/bundler/cli/common.rb
+++ b/lib/bundler/cli/common.rb
@@ -90,5 +90,13 @@ module Bundler
def self.patch_level_options(options)
[:major, :minor, :patch].select {|v| options.keys.include?(v.to_s) }
end
+
+ def self.clean_after_install?
+ clean = Bundler.settings[:clean]
+ return clean unless clean.nil?
+ clean ||= Bundler.feature_flag.auto_clean_without_path? && Bundler.settings[:path].nil?
+ clean &&= !Bundler.use_system_gems?
+ clean
+ end
end
end
diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb
index 68670f29f4..958b525067 100644
--- a/lib/bundler/cli/info.rb
+++ b/lib/bundler/cli/info.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require "bundler/cli/common"
-
module Bundler
class CLI::Info
attr_reader :gem_name, :options
diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb
index 5b852dd88c..f0b821ed84 100644
--- a/lib/bundler/cli/install.rb
+++ b/lib/bundler/cli/install.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require "bundler/cli/common"
-
module Bundler
class CLI::Install
attr_reader :options
@@ -82,7 +80,7 @@ module Bundler
warn_ambiguous_gems
- if Bundler.settings[:clean] && !Bundler.use_system_gems?
+ if CLI::Common.clean_after_install?
require "bundler/cli/clean"
Bundler::CLI::Clean.new(options).run
end
diff --git a/lib/bundler/cli/lock.rb b/lib/bundler/cli/lock.rb
index 2ac0537e39..7dd078b1ef 100644
--- a/lib/bundler/cli/lock.rb
+++ b/lib/bundler/cli/lock.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require "bundler/cli/common"
-
module Bundler
class CLI::Lock
attr_reader :options
diff --git a/lib/bundler/cli/open.rb b/lib/bundler/cli/open.rb
index fb18b0aacc..552fe6f128 100644
--- a/lib/bundler/cli/open.rb
+++ b/lib/bundler/cli/open.rb
@@ -1,6 +1,5 @@
# frozen_string_literal: true
-require "bundler/cli/common"
require "shellwords"
module Bundler
diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb
index 3fb0feaddd..5125cc710b 100644
--- a/lib/bundler/cli/outdated.rb
+++ b/lib/bundler/cli/outdated.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require "bundler/cli/common"
-
module Bundler
class CLI::Outdated
attr_reader :options, :gems
diff --git a/lib/bundler/cli/pristine.rb b/lib/bundler/cli/pristine.rb
index 7dca77050f..9b9cdaa9b3 100644
--- a/lib/bundler/cli/pristine.rb
+++ b/lib/bundler/cli/pristine.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require "bundler/cli/common"
-
module Bundler
class CLI::Pristine
def initialize(gems)
diff --git a/lib/bundler/cli/show.rb b/lib/bundler/cli/show.rb
index 2424e301ff..61756801b2 100644
--- a/lib/bundler/cli/show.rb
+++ b/lib/bundler/cli/show.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require "bundler/cli/common"
-
module Bundler
class CLI::Show
attr_reader :options, :gem_name, :latest_specs
diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb
index b57b82ecc1..5de11e84e4 100644
--- a/lib/bundler/cli/update.rb
+++ b/lib/bundler/cli/update.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require "bundler/cli/common"
-
module Bundler
class CLI::Update
attr_reader :options, :gems
@@ -63,7 +61,7 @@ module Bundler
installer = Installer.install Bundler.root, Bundler.definition, opts
Bundler.load.cache if Bundler.app_cache.exist?
- if Bundler.settings[:clean] && !Bundler.use_system_gems?
+ if CLI::Common.clean_after_install?
require "bundler/cli/clean"
Bundler::CLI::Clean.new(options).run
end
diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb
index 05f28059d7..6a1809cd40 100644
--- a/lib/bundler/feature_flag.rb
+++ b/lib/bundler/feature_flag.rb
@@ -29,15 +29,18 @@ module Bundler
settings_flag(:allow_bundler_dependency_conflicts) { bundler_2_mode? }
settings_flag(:allow_offline_install) { bundler_2_mode? }
+ settings_flag(:auto_clean_without_path) { bundler_2_mode? }
settings_flag(:cache_all) { bundler_2_mode? }
settings_flag(:cache_command_is_package) { bundler_2_mode? }
settings_flag(:console_command) { !bundler_2_mode? }
+ settings_flag(:default_install_uses_path) { bundler_2_mode? }
settings_flag(:deployment_means_frozen) { bundler_2_mode? }
settings_flag(:disable_multisource) { bundler_2_mode? }
settings_flag(:error_on_stderr) { bundler_2_mode? }
settings_flag(:forget_cli_options) { bundler_2_mode? }
settings_flag(:global_gem_cache) { bundler_2_mode? }
settings_flag(:init_gems_rb) { bundler_2_mode? }
+ settings_flag(:list_command) { bundler_2_mode? }
settings_flag(:lockfile_uses_separate_rubygems_sources) { bundler_2_mode? }
settings_flag(:only_update_to_newer_versions) { bundler_2_mode? }
settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") }
@@ -49,8 +52,6 @@ module Bundler
settings_flag(:suppress_install_using_messages) { bundler_2_mode? }
settings_flag(:unlock_source_unlocks_spec) { !bundler_2_mode? }
settings_flag(:update_requires_all_flag) { bundler_2_mode? }
- settings_flag(:default_install_uses_path) { bundler_2_mode? }
- settings_flag(:list_command) { bundler_2_mode? }
settings_option(:default_cli_command) { bundler_2_mode? ? :cli_help : :install }
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index 8d4276159b..dee7c14ca1 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -12,6 +12,7 @@ module Bundler
allow_bundler_dependency_conflicts
allow_deployment_source_credential_changes
allow_offline_install
+ auto_clean_without_path
auto_install
cache_all
cache_all_platforms
diff --git a/man/bundle-config.ronn b/man/bundle-config.ronn
index 32cc640f60..f1f3062aea 100644
--- a/man/bundle-config.ronn
+++ b/man/bundle-config.ronn
@@ -126,6 +126,9 @@ learn more about their operation in [bundle install(1)][bundle-install].
Ex: `https://some.host.com/gems/path/` -> `https://user_name:password@some.host.com/gems/path`
* `allow_offline_install` (`BUNDLE_ALLOW_OFFLINE_INSTALL`):
Allow Bundler to use cached data when installing without network access.
+* `auto_clean_without_path` (`BUNDLE_AUTO_CLEAN_WITHOUT_PATH`):
+ Automatically run `bundle clean` after installing when an explicit `path`
+ has not been set and Bundler is not installing into the system gems.
* `auto_install` (`BUNDLE_AUTO_INSTALL`):
Automatically run `bundle install` when gems are missing.
* `bin` (`BUNDLE_BIN`):
@@ -168,7 +171,7 @@ learn more about their operation in [bundle install(1)][bundle-install].
* `disable_version_check` (`BUNDLE_DISABLE_VERSION_CHECK`):
Stop Bundler from checking if a newer Bundler version is available on
rubygems.org.
-* `error_on_stderr` (`BUNDLE_ERROR_ON_STDERR`)
+* `error_on_stderr` (`BUNDLE_ERROR_ON_STDERR`):
Print Bundler errors to stderr.
* `force_ruby_platform` (`BUNDLE_FORCE_RUBY_PLATFORM`):
Ignore the current machine's platform and install only `ruby` platform gems.
diff --git a/spec/commands/clean_spec.rb b/spec/commands/clean_spec.rb
index be8f80065c..8113ae8c25 100644
--- a/spec/commands/clean_spec.rb
+++ b/spec/commands/clean_spec.rb
@@ -383,6 +383,30 @@ RSpec.describe "bundle clean" do
should_not_have_gems "foo-1.0"
end
+ it "automatically cleans when path has not been set", :bundler => "2" do
+ build_repo2
+
+ install_gemfile! <<-G
+ source "file://#{gem_repo2}"
+
+ gem "foo"
+ G
+
+ update_repo2 do
+ build_gem "foo", "1.0.1"
+ end
+
+ bundle! "update", :all => true
+
+ files = Pathname.glob(bundled_app(".bundle", Bundler.ruby_scope, "*", "*"))
+ files.map! {|f| f.to_s.sub(bundled_app(".bundle", Bundler.ruby_scope).to_s, "") }
+ expect(files.sort).to eq %w[
+ /cache/foo-1.0.1.gem
+ /gems/foo-1.0.1
+ /specifications/foo-1.0.1.gemspec
+ ]
+ end
+
it "does not clean automatically on --path" do
gemfile <<-G
source "file://#{gem_repo1}"
diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb
index bcc436d39b..61c58e3025 100644
--- a/spec/commands/exec_spec.rb
+++ b/spec/commands/exec_spec.rb
@@ -617,7 +617,7 @@ RSpec.describe "bundle exec" do
let(:exit_code) { Bundler::GemNotFound.new.status_code }
let(:expected) { <<-EOS.strip }
\e[31mCould not find gem 'rack (= 2)' in locally installed gems.
-The source contains 'rack' at: 0.9.1, 1.0.0\e[0m
+The source contains 'rack' at: 1.0.0\e[0m
\e[33mRun `bundle install` to install missing gems.\e[0m
EOS
diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb
index c7964365a6..f0ad136c98 100644
--- a/spec/commands/outdated_spec.rb
+++ b/spec/commands/outdated_spec.rb
@@ -191,6 +191,8 @@ RSpec.describe "bundle outdated" do
build_gem "activesupport", "2.3.4"
end
+ bundle! "config clean false"
+
install_gemfile <<-G
source "file://#{gem_repo2}"
gem "activesupport", "2.3.4"
diff --git a/spec/commands/update_spec.rb b/spec/commands/update_spec.rb
index a488be536f..a8283cf593 100644
--- a/spec/commands/update_spec.rb
+++ b/spec/commands/update_spec.rb
@@ -498,6 +498,7 @@ RSpec.describe "bundle update" do
end
bundle! "update", :all => bundle_update_requires_all?
+ out.sub!("Removing foo (1.0)\n", "")
out.gsub!(/RubyGems [\d\.]+ is not threadsafe.*\n?/, "")
expect(out).to include strip_whitespace(<<-EOS).strip
Resolving dependencies...
diff --git a/spec/install/allow_offline_install_spec.rb b/spec/install/allow_offline_install_spec.rb
index 6b335e23d5..d4bb595771 100644
--- a/spec/install/allow_offline_install_spec.rb
+++ b/spec/install/allow_offline_install_spec.rb
@@ -28,6 +28,7 @@ RSpec.describe "bundle install with :allow_offline_install" do
it "will install from the compact index" do
system_gems ["rack-1.0.0"], :path => :bundle_path
+ bundle! "config clean false"
install_gemfile! <<-G, :artifice => "compact_index"
source "http://testgemserver.local"
gem "rack-obama"
diff --git a/spec/plugins/source/example_spec.rb b/spec/plugins/source/example_spec.rb
index 4f5e5f3fdb..fdeec0b634 100644
--- a/spec/plugins/source/example_spec.rb
+++ b/spec/plugins/source/example_spec.rb
@@ -36,6 +36,10 @@ RSpec.describe "real source plugins" do
mkdir_p(install_path.parent)
FileUtils.cp_r(path, install_path)
+ spec_path = install_path.join("\#{spec.full_name}.gemspec")
+ spec_path.open("wb") {|f| f.write spec.to_ruby }
+ spec.loaded_from = spec_path.to_s
+
post_install(spec)
nil
@@ -252,6 +256,10 @@ RSpec.describe "real source plugins" do
`git reset --hard \#{revision}`
end
+ spec_path = install_path.join("\#{spec.full_name}.gemspec")
+ spec_path.open("wb") {|f| f.write spec.to_ruby }
+ spec.loaded_from = spec_path.to_s
+
post_install(spec)
nil
diff --git a/spec/update/git_spec.rb b/spec/update/git_spec.rb
index 95b0a95976..52c4fc0957 100644
--- a/spec/update/git_spec.rb
+++ b/spec/update/git_spec.rb
@@ -117,8 +117,10 @@ RSpec.describe "bundle update" do
describe "with submodules" do
before :each do
- build_gem "submodule", :to_bundle => true do |s|
- s.write "lib/submodule.rb", "puts 'GEM'"
+ build_repo4 do
+ build_gem "submodule" do |s|
+ s.write "lib/submodule.rb", "puts 'GEM'"
+ end
end
build_git "submodule", "1.0" do |s|
@@ -137,6 +139,7 @@ RSpec.describe "bundle update" do
it "it unlocks the source when submodules are added to a git source" do
install_gemfile <<-G
+ source "file:#{gem_repo4}"
git "#{lib_path("has_submodule-1.0")}" do
gem "has_submodule"
end
@@ -146,6 +149,7 @@ RSpec.describe "bundle update" do
expect(out).to eq("GEM")
install_gemfile <<-G
+ source "file:#{gem_repo4}"
git "#{lib_path("has_submodule-1.0")}", :submodules => true do
gem "has_submodule"
end
@@ -156,22 +160,24 @@ RSpec.describe "bundle update" do
end
it "unlocks the source when submodules are removed from git source", :git => ">= 2.9.0" do
- install_gemfile <<-G
+ install_gemfile! <<-G
+ source "file:#{gem_repo4}"
git "#{lib_path("has_submodule-1.0")}", :submodules => true do
gem "has_submodule"
end
G
- run "require 'submodule'"
+ run! "require 'submodule'"
expect(out).to eq("GIT")
- install_gemfile <<-G
+ install_gemfile! <<-G
+ source "file:#{gem_repo4}"
git "#{lib_path("has_submodule-1.0")}" do
gem "has_submodule"
end
G
- run "require 'submodule'"
+ run! "require 'submodule'"
expect(out).to eq("GEM")
end
end