[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:
David Rodríguez 2024-05-24 19:47:22 +02:00 коммит произвёл git
Родитель 15501e13d7
Коммит 4f160ad9cf
4 изменённых файлов: 21 добавлений и 6 удалений

Просмотреть файл

@ -358,7 +358,7 @@ module Bundler
def settings
@settings ||= Settings.new(app_config_path)
rescue GemfileNotFound
@settings = Settings.new(Pathname.new(".bundle").expand_path)
@settings = Settings.new
end
# @return [Hash] Environment present before Bundler was activated

Просмотреть файл

@ -103,6 +103,7 @@ module Bundler
def initialize(root = nil)
@root = root
@local_config = load_config(local_config_file)
@local_root = root || Pathname.new(".bundle").expand_path
@env_config = ENV.to_h
@env_config.select! {|key, _value| key.start_with?("BUNDLE_") }
@ -142,7 +143,7 @@ module Bundler
end
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)
end

Просмотреть файл

@ -6,12 +6,18 @@ RSpec.describe Bundler::Settings do
subject(:settings) { described_class.new(bundled_app) }
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) }
it "raises a GemfileNotFound error with explanation" do
expect { subject.set_local("foo", "bar") }.
to raise_error(Bundler::GemfileNotFound, "Could not locate Gemfile")
before do
allow(Pathname).to receive(:new).and_call_original
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

Просмотреть файл

@ -79,6 +79,14 @@ RSpec.describe ".bundle/config" do
expect(home(".bundle/config")).to exist
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
ENV["BUNDLE_APP_CONFIG"] = tmp("foo/bar").to_s
bundle "config set --local path vendor/bundle"