[rubygems/rubygems] Don't let bundle config
report a path without a Gemfile as "local app"
https://github.com/rubygems/rubygems/commit/6aa2ac337f
This commit is contained in:
parent
15501e13d7
commit
4f160ad9cf
@ -358,7 +358,7 @@ module Bundler
|
|||||||
def settings
|
def settings
|
||||||
@settings ||= Settings.new(app_config_path)
|
@settings ||= Settings.new(app_config_path)
|
||||||
rescue GemfileNotFound
|
rescue GemfileNotFound
|
||||||
@settings = Settings.new(Pathname.new(".bundle").expand_path)
|
@settings = Settings.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Hash] Environment present before Bundler was activated
|
# @return [Hash] Environment present before Bundler was activated
|
||||||
|
@ -103,6 +103,7 @@ module Bundler
|
|||||||
def initialize(root = nil)
|
def initialize(root = nil)
|
||||||
@root = root
|
@root = root
|
||||||
@local_config = load_config(local_config_file)
|
@local_config = load_config(local_config_file)
|
||||||
|
@local_root = root || Pathname.new(".bundle").expand_path
|
||||||
|
|
||||||
@env_config = ENV.to_h
|
@env_config = ENV.to_h
|
||||||
@env_config.select! {|key, _value| key.start_with?("BUNDLE_") }
|
@env_config.select! {|key, _value| key.start_with?("BUNDLE_") }
|
||||||
@ -142,7 +143,7 @@ module Bundler
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_local(key, value)
|
def set_local(key, value)
|
||||||
local_config_file || raise(GemfileNotFound, "Could not locate Gemfile")
|
local_config_file = @local_root.join("config")
|
||||||
|
|
||||||
set_key(key, value, @local_config, local_config_file)
|
set_key(key, value, @local_config, local_config_file)
|
||||||
end
|
end
|
||||||
|
@ -6,12 +6,18 @@ RSpec.describe Bundler::Settings do
|
|||||||
subject(:settings) { described_class.new(bundled_app) }
|
subject(:settings) { described_class.new(bundled_app) }
|
||||||
|
|
||||||
describe "#set_local" do
|
describe "#set_local" do
|
||||||
context "when the local config file is not found" do
|
context "root is nil" do
|
||||||
subject(:settings) { described_class.new(nil) }
|
subject(:settings) { described_class.new(nil) }
|
||||||
|
|
||||||
it "raises a GemfileNotFound error with explanation" do
|
before do
|
||||||
expect { subject.set_local("foo", "bar") }.
|
allow(Pathname).to receive(:new).and_call_original
|
||||||
to raise_error(Bundler::GemfileNotFound, "Could not locate Gemfile")
|
allow(Pathname).to receive(:new).with(".bundle").and_return home(".bundle")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "works" do
|
||||||
|
subject.set_local("foo", "bar")
|
||||||
|
|
||||||
|
expect(subject["foo"]).to eq("bar")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -79,6 +79,14 @@ RSpec.describe ".bundle/config" do
|
|||||||
expect(home(".bundle/config")).to exist
|
expect(home(".bundle/config")).to exist
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not list global settings as local" do
|
||||||
|
bundle "config set --global foo bar"
|
||||||
|
bundle "config list", dir: home
|
||||||
|
|
||||||
|
expect(out).to include("for the current user")
|
||||||
|
expect(out).not_to include("for your local app")
|
||||||
|
end
|
||||||
|
|
||||||
it "works with an absolute path" do
|
it "works with an absolute path" do
|
||||||
ENV["BUNDLE_APP_CONFIG"] = tmp("foo/bar").to_s
|
ENV["BUNDLE_APP_CONFIG"] = tmp("foo/bar").to_s
|
||||||
bundle "config set --local path vendor/bundle"
|
bundle "config set --local path vendor/bundle"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user