summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2018-09-25 16:38:09 -0300
committerDavid Rodríguez <deivid.rodriguez@riseup.net>2020-03-09 18:25:09 +0100
commite7b9ff14dd3f790b03342e02770f8cf411abc705 (patch)
tree8e3415cba7ebca89cc2c854624bb19d28069b0ca
parentd5bd9fd4ee84f7623e270e9b243983e6d5845be0 (diff)
downloadbundler-e7b9ff14dd3f790b03342e02770f8cf411abc705.tar.gz
New criteria to find config folder
Now the directory hierarchy is searched up for a ".bundle" dir and if not foun, current folder is used. This is more intuitive than choosing the configuration location than using the folder of the Gemfile being used, but also it will allow us to respect the Gemfile configured via settings since the new algorithm does not need a Gemfile.
-rw-r--r--lib/bundler.rb6
-rw-r--r--lib/bundler/shared_helpers.rb6
-rw-r--r--spec/commands/config_spec.rb32
3 files changed, 42 insertions, 2 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 93093f2e32..9cf6924bda 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -286,7 +286,7 @@ module Bundler
end
end
- app_config_root.join(app_config || ".bundle")
+ current_config_root.join(app_config || ".bundle")
end
def app_cache(custom_path = nil)
@@ -685,5 +685,9 @@ EOF
rescue GemfileNotFound
Pathname.new(".").expand_path
end
+
+ def current_config_root
+ SharedHelpers.config_root
+ end
end
end
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index 94e6875f00..529379ba44 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -20,6 +20,12 @@ module Bundler
bundle_dir.parent
end
+ def config_root
+ bundle_dir = default_bundle_dir
+
+ bundle_dir ? bundle_dir.parent : Pathname.pwd
+ end
+
def default_gemfile
gemfile = find_gemfile
raise GemfileNotFound, "Could not locate Gemfile" unless gemfile
diff --git a/spec/commands/config_spec.rb b/spec/commands/config_spec.rb
index 2a25799f79..e58a266212 100644
--- a/spec/commands/config_spec.rb
+++ b/spec/commands/config_spec.rb
@@ -61,9 +61,39 @@ RSpec.describe ".bundle/config" do
bundle "install", :dir => bundled_app("omg")
expect(bundled_app(".bundle")).not_to exist
- expect(bundled_app("../foo/config")).to exist
+ expect(bundled_app("omg/../foo/config")).to exist
expect(the_bundle).to include_gems "rack 1.0.0", :dir => bundled_app("omg")
end
+
+ it "is relative to the pwd and not to the gemfile" do
+ FileUtils.mkdir_p bundled_app("omg/gmo")
+
+ gemfile bundled_app("omg/gmo/AnotherGemfile"), <<-G
+ source "#{file_uri_for(gem_repo1)}"
+ G
+
+ bundle "config set --local foo bar", :env => { "BUNDLE_GEMFILE" => bundled_app("omg/gmo/AnotherGemfile").to_s }, :dir => bundled_app("omg")
+
+ expect(bundled_app("omg/gmo/.bundle")).not_to exist
+ expect(bundled_app("omg/.bundle")).to exist
+ end
+
+ it "uses the first existing local config from the pwd and not from the gemfile" do
+ bundle "install"
+
+ FileUtils.mkdir_p bundled_app("omg/gmo")
+
+ bundle "config set --local foo bar", :dir => bundled_app("omg/gmo")
+
+ gemfile bundled_app("omg/gmo/AnotherGemfile"), <<-G
+ source "#{file_uri_for(gem_repo1)}"
+ G
+
+ bundle "config set --local foo baz", :dir => bundled_app("omg")
+ run "puts Bundler.settings[:foo]", :env => { "BUNDLE_GEMFILE" => bundled_app("omg/gmo/AnotherGemfile").to_s }, :dir => bundled_app("omg")
+
+ expect(out).to eq("baz")
+ end
end
describe "location without a gemfile" do