Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix BUNDLE_LOCKFILE=Gemfile.lock #11

Merged
merged 1 commit into from
Oct 6, 2023
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
bundler-multilock (1.1.1)
bundler-multilock (1.1.2)
bundler (~> 2.4.19)

GEM
Expand Down
21 changes: 8 additions & 13 deletions lib/bundler/multilock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,8 @@ def add_lockfile(lockfile = nil,
raise ArgumentError, "Lockfile #{lockfile} is already defined"
end

env_lockfile = ENV["BUNDLE_LOCKFILE"]
if env_lockfile
unless env_lockfile.include?("/") || env_lockfile.end_with?(".lock")
env_lockfile = "Gemfile.#{env_lockfile}.lock"
end
env_lockfile = Bundler.root.join(env_lockfile).expand_path
active = env_lockfile == lockfile
end
env_lockfile = ENV["BUNDLE_LOCKFILE"]&.then { |l| expand_lockfile(l) }
active = env_lockfile == lockfile if env_lockfile

if active && (old_active = lockfile_definitions.find { |definition| definition[:active] })
raise ArgumentError, "Only one lockfile (#{old_active[:lockfile]}) can be flagged as the default"
Expand Down Expand Up @@ -310,16 +304,17 @@ def loaded!

return unless lockfile_definitions.none? { |definition| definition[:active] }

# Gemfile.lock isn't explicitly specified, otherwise it would be active
default_lockfile_definition = lockfile_definitions.find do |definition|
definition[:lockfile] == Bundler.default_lockfile(force_original: true)
end
if ENV["BUNDLE_LOCKFILE"] == Bundler.default_lockfile(force_original: true) && default_lockfile_definition
if ENV["BUNDLE_LOCKFILE"]&.then { |l| expand_lockfile(l) } ==
Bundler.default_lockfile(force_original: true)
return
end

raise GemfileNotFound, "Could not locate lockfile #{ENV["BUNDLE_LOCKFILE"].inspect}" if ENV["BUNDLE_LOCKFILE"]

# Gemfile.lock isn't explicitly specified, otherwise it would be active
default_lockfile_definition = lockfile_definitions.find do |definition|
definition[:lockfile] == Bundler.default_lockfile(force_original: true)
end
return unless default_lockfile_definition && default_lockfile_definition[:active] == false

raise GemfileEvalError, "No lockfiles marked as default"
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/multilock/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Bundler
module Multilock
VERSION = "1.1.1"
VERSION = "1.1.2"
end
end
12 changes: 12 additions & 0 deletions spec/bundler/multilock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,18 @@
end
end

it "allows explicitly specifying the default lockfile" do
with_gemfile(<<~RUBY) do
gem "rake"

lockfile("alt1") do
gem "concurrent-ruby", "1.2.1"
end
RUBY
invoke_bundler("install", env: { "BUNDLE_LOCKFILE" => "Gemfile.lock" })
end
end

# so that it won't downgrade if that's all you have available
it "installs missing deps from alternate lockfiles before syncing" do
Bundler.with_unbundled_env do
Expand Down