diff options
-rw-r--r-- | lib/bundler.rb | 6 | ||||
-rw-r--r-- | lib/bundler/shared_helpers.rb | 6 | ||||
-rw-r--r-- | spec/commands/config_spec.rb | 32 |
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 |