Skip to content

Commit

Permalink
bundle update --bundler
Browse files Browse the repository at this point in the history
had to fix command detection, since with 2.5.10, CLI::Install is
_always_ required for the new auto-install feature
  • Loading branch information
ccutrer committed May 18, 2024
1 parent ab8671a commit 40fabbf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
fail-fast: false
matrix:
ruby-version: [2.6, 2.7, "3.0", 3.1, 3.2]
bundler-version: [2.4.19, 2.4.22, 2.5.9]
bundler-version: [2.4.19, 2.4.22, 2.5.10]
exclude:
- ruby-version: 2.6
bundler-version: 2.5.9
bundler-version: 2.5.10
- ruby-version: 2.7
bundler-version: 2.5.9
bundler-version: 2.5.10
env:
BUNDLER_VERSION: ${{ matrix.bundler-version }}
BUNDLE_LOCKFILE: active
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ DEPENDENCIES
stringio (~> 3.1)

BUNDLED WITH
2.5.9
2.5.10
2 changes: 1 addition & 1 deletion Gemfile.ruby-2.6.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ DEPENDENCIES
stringio (= 3.0.6)

BUNDLED WITH
2.5.9
2.5.10
52 changes: 26 additions & 26 deletions lib/bundler/multilock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,13 @@ def add_lockfile(lockfile = nil,
enforce_pinned_additional_dependencies: enforce_pinned_additional_dependencies
})

if (defined?(CLI::Check) ||
defined?(CLI::Install) ||
defined?(CLI::Lock) ||
defined?(CLI::Update)) &&
!defined?(CLI::Cache) && !env_lockfile
# If they're using BUNDLE_LOCKFILE, then they really do want to
# use a particular lockfile, and it overrides whatever they
# dynamically set in their gemfile
if !env_lockfile && defined?(CLI) &&
%i[check install lock update].include?(CLI.instance&.current_command_chain&.first)
# always use Gemfile.lock for `bundle check`, `bundle install`,
# `bundle lock`, and `bundle update`. `bundle cache` delegates to
# `bundle install`, but we want that to run as normal.
# If they're using BUNDLE_LOCKFILE, then they really do want to
# use a particular lockfile, and it overrides whatever they
# dynamically set in their gemfile
# `bundle lock`, and `bundle update`.
active = lockfile == Bundler.default_lockfile(force_original: true)
end

Expand Down Expand Up @@ -577,25 +573,29 @@ def write_lockfile(lockfile_definition,
Bundler::LazySpecification.include(Bundler::MatchMetadata) if defined?(Bundler::MatchMetadata)
Bundler::Multilock.inject_preamble unless Bundler::Multilock.loaded?

# this is terrible, but we can't prepend into these modules because we only load
# _inside_ of the CLI commands already running
if defined?(Bundler::CLI::Check)
require_relative "multilock/check"
at_exit do
next unless $!.nil?
next if $!.is_a?(SystemExit) && !$!.success?
if defined?(Bundler::CLI)
require_relative "multilock/ext/cli"

next if Bundler::Multilock::Check.run
# this is terrible, but we can't prepend into these modules because we only load
# _inside_ of the CLI commands already running
if Bundler::CLI.instance&.current_command_chain&.first == :check
require_relative "multilock/check"
at_exit do
next unless $!.nil?
next if $!.is_a?(SystemExit) && !$!.success?

Bundler.ui.warn("You can attempt to fix by running `bundle install`")
exit 1
next if Bundler::Multilock::Check.run

Bundler.ui.warn("You can attempt to fix by running `bundle install`")
exit 1
end
end
end
if defined?(Bundler::CLI::Lock)
at_exit do
next unless $!.nil?
next if $!.is_a?(SystemExit) && !$!.success?
if Bundler::CLI.instance&.current_command_chain&.first == :lock
at_exit do
next unless $!.nil?
next if $!.is_a?(SystemExit) && !$!.success?

Bundler::Multilock.after_install_all(install: false)
Bundler::Multilock.after_install_all(install: false)
end
end
end
20 changes: 20 additions & 0 deletions lib/bundler/multilock/ext/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Bundler
module Multilock
module Ext
module CLI
module ClassMethods
def instance
return @instance if instance_variable_defined?(:@instance)

# this is a little icky, but there's no other way to determine which command was run
@instance = ObjectSpace.each_object(::Bundler::CLI).first
end
end

::Bundler::CLI.extend(ClassMethods)
end
end
end
end

0 comments on commit 40fabbf

Please sign in to comment.