Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions bundler/lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@ def initialize(*args)

current_cmd = args.last[:current_command].name

Bundler.configure_custom_gemfile(options[:gemfile])

# lock --lockfile works differently than install --lockfile
unless current_cmd == "lock"
custom_lockfile = options[:lockfile] || ENV["BUNDLE_LOCKFILE"] || Bundler.settings[:lockfile]
if custom_lockfile && !custom_lockfile.empty?
Bundler::SharedHelpers.set_env "BUNDLE_LOCKFILE", File.expand_path(custom_lockfile)
reset_settings = true
# `bundle config` manages stored settings, so avoid promoting settings
# like `gemfile` or `lockfile` to environment variables before it runs.
unless current_cmd == "config"
Bundler.configure_custom_gemfile(options[:gemfile])

# lock --lockfile works differently than install --lockfile
unless current_cmd == "lock"
custom_lockfile = options[:lockfile] || ENV["BUNDLE_LOCKFILE"] || Bundler.settings[:lockfile]
if custom_lockfile && !custom_lockfile.empty?
Bundler::SharedHelpers.set_env "BUNDLE_LOCKFILE", File.expand_path(custom_lockfile)
reset_settings = true
end
end
end

Expand Down
30 changes: 30 additions & 0 deletions spec/commands/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,36 @@
end

RSpec.describe "setting gemfile via config" do
context "when a default Gemfile exists" do
before do
gemfile <<-G
source "https://gem.repo1"
G

gemfile bundled_app("foo/bar_gemfile"), <<-G
source "https://gem.repo1"
G
end

it "reports the local gemfile setting without promoting it to the environment" do
bundle "config set gemfile foo/bar_gemfile"

bundle "config list"
expect(out).to include("Set for your local app (#{bundled_app(".bundle/config")}): \"foo/bar_gemfile\"")
expect(out).not_to include("Set via BUNDLE_GEMFILE")
end

it "unsets the local gemfile setting from the app config" do
bundle "config set gemfile foo/bar_gemfile"

bundle "config unset gemfile"
bundle "config get gemfile"

expect(out).to include("You have not configured a value for `gemfile`")
expect(File.read(bundled_app(".bundle/config"))).not_to include("BUNDLE_GEMFILE")
end
end

context "when only the non-default Gemfile exists" do
it "persists the gemfile location to .bundle/config" do
gemfile bundled_app("NotGemfile"), <<-G
Expand Down