From e104b9bd9d2396bdd1bd7e6d3e577a306162eeaf Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Fri, 6 Oct 2023 11:55:09 -0600 Subject: [PATCH] fix BUNDLE_LOCKFILE=Gemfile.lock (#11) --- Gemfile.lock | 2 +- lib/bundler/multilock.rb | 21 ++++++++------------- lib/bundler/multilock/version.rb | 2 +- spec/bundler/multilock_spec.rb | 12 ++++++++++++ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index dc6adf3..4bdd77e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - bundler-multilock (1.1.1) + bundler-multilock (1.1.2) bundler (~> 2.4.19) GEM diff --git a/lib/bundler/multilock.rb b/lib/bundler/multilock.rb index 6a79c28..3c00efe 100644 --- a/lib/bundler/multilock.rb +++ b/lib/bundler/multilock.rb @@ -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" @@ -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" diff --git a/lib/bundler/multilock/version.rb b/lib/bundler/multilock/version.rb index 11531c7..173d8b1 100644 --- a/lib/bundler/multilock/version.rb +++ b/lib/bundler/multilock/version.rb @@ -2,6 +2,6 @@ module Bundler module Multilock - VERSION = "1.1.1" + VERSION = "1.1.2" end end diff --git a/spec/bundler/multilock_spec.rb b/spec/bundler/multilock_spec.rb index c3c3818..e6cf753 100644 --- a/spec/bundler/multilock_spec.rb +++ b/spec/bundler/multilock_spec.rb @@ -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