Skip to content

Commit

Permalink
Show an error when trying to update bundler in frozen mode
Browse files Browse the repository at this point in the history
Previously `bundle update --bundler` would succeed but fail to update
the lockfile.
  • Loading branch information
deivid-rodriguez committed May 24, 2023
1 parent b0aeb6f commit ef27cac
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bundler/lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,8 @@ def lockfiles_equal?(current, proposed, preserve_unknown_sections)
if preserve_unknown_sections
sections_to_ignore = LockfileParser.sections_to_ignore(@locked_bundler_version)
sections_to_ignore += LockfileParser.unknown_sections_in_lockfile(current)
sections_to_ignore += LockfileParser::ENVIRONMENT_VERSION_SECTIONS
sections_to_ignore << LockfileParser::RUBY
sections_to_ignore << LockfileParser::BUNDLED unless @unlocking_bundler
pattern = /#{Regexp.union(sections_to_ignore)}\n(\s{2,}.*\n)+/
whitespace_cleanup = /\n{2,}/
current = current.gsub(pattern, "\n").gsub(whitespace_cleanup, "\n\n").strip
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def run(options)

Gem::Specification.reset # invalidate gem specification cache so that installed gems are immediately available

lock unless Bundler.frozen_bundle?
lock
Standalone.new(options[:standalone], @definition).generate if options[:standalone]
end
end
Expand Down
1 change: 1 addition & 0 deletions bundler/lib/bundler/lockfile_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class LockfileParser
KNOWN_SECTIONS = SECTIONS_BY_VERSION_INTRODUCED.values.flatten.freeze

ENVIRONMENT_VERSION_SECTIONS = [BUNDLED, RUBY].freeze
deprecate_constant(:ENVIRONMENT_VERSION_SECTIONS)

def self.sections_in_lockfile(lockfile_contents)
lockfile_contents.scan(/^\w[\w ]*$/).uniq
Expand Down
25 changes: 25 additions & 0 deletions bundler/spec/commands/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,31 @@
expect(out).to include("Using bundler 2.3.9")
end
end

it "prints an error when trying to update bundler in frozen mode" do
system_gems "bundler-2.3.9"

gemfile <<~G
source "#{file_uri_for(gem_repo2)}"
G

lockfile <<-L
GEM
remote: #{file_uri_for(gem_repo2)}/
specs:
PLATFORMS
ruby
DEPENDENCIES
BUNDLED WITH
2.1.4
L

bundle "update --bundler=2.3.9", :env => { "BUNDLE_FROZEN" => "true" }
expect(err).to include("Cannot write a changed lockfile while frozen")
end
end

# these specs are slow and focus on integration and therefore are not exhaustive. unit specs elsewhere handle that.
Expand Down

0 comments on commit ef27cac

Please sign in to comment.