From 418998cab819b230352e1595d0fcfb318375f7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 8 Sep 2020 15:07:14 +0200 Subject: [PATCH] Prioritize `path.system` over `path` when it makes sense If `path.system` is configured locally, and `path` is configured globally, gems should be installed to `path.system`. --- bundler/lib/bundler/settings.rb | 14 ++++++++------ bundler/spec/install/path_spec.rb | 8 ++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/bundler/lib/bundler/settings.rb b/bundler/lib/bundler/settings.rb index c658d89e7561..6ce81b5006ec 100644 --- a/bundler/lib/bundler/settings.rb +++ b/bundler/lib/bundler/settings.rb @@ -195,14 +195,16 @@ def pretty_values_for(exposed_key) # for legacy reasons, in Bundler 2, we do not respect :disable_shared_gems def path - key = key_for(:path) - path = ENV[key] || @global_config[key] - if path && !@temporary.key?(key) && !@local_config.key?(key) - return Path.new(path, false) + configs.each do |_level, settings| + path = value_for("path", settings) + path_system = value_for("path.system", settings) + disabled_shared_gems = value_for("disable_shared_gems", settings) + next if path.nil? && path_system.nil? && disabled_shared_gems.nil? + system_path = path_system || (disabled_shared_gems == false) + return Path.new(path, system_path) end - system_path = self["path.system"] || (self[:disable_shared_gems] == false) - Path.new(self[:path], system_path) + Path.new(nil, false) end Path = Struct.new(:explicit_path, :system_path) do diff --git a/bundler/spec/install/path_spec.rb b/bundler/spec/install/path_spec.rb index 04cf01dceaea..a05467db123f 100644 --- a/bundler/spec/install/path_spec.rb +++ b/bundler/spec/install/path_spec.rb @@ -19,6 +19,14 @@ expect(the_bundle).to include_gems "rack 1.0.0" end + it "uses system gems with `path.system` configured with more priority than `path`" do + bundle "config --local path.system true" + bundle "config --global path vendor/bundle" + bundle :install + run "require 'rack'", :raise_on_error => false + expect(out).to include("FAIL") + end + it "handles paths with regex characters in them" do dir = bundled_app("bun++dle") dir.mkpath