Skip to content
Open
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ a nice looking [Changelog](http://keepachangelog.com).

## Version [HEAD] <sub><sup>now</sub></sup>

* Adds ability to pristine original Gemfile.lock

## Version [2.0.0] <sub><sup>2021-05-01</sub></sup>

* **BREAKING**: Drops support for bundler below 2.0
Expand Down
31 changes: 29 additions & 2 deletions lib/bundler/inject/dsl_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,29 @@ def ensure_gem(name, *args)
end

def to_definition(lockfile, unlock)
return super if ENV['BUNDLER_INJECT__DISABLE_OVERRIDE']

original_unlock = unlock.dup
original_lockfile = lockfile
lockfile = Pathname.new("#{lockfile}.local") if enable_pristine?(lockfile)

calling_loc = caller_locations(1, 1).first
if calling_loc.path.include?("bundler/dsl.rb") && calling_loc.base_label == "evaluate"
load_global_bundler_d

# @gemfiles doesn't exist on Bundler <= 1.15, and we can't get at @gemfile
# by this point, but there's a high probability it's just "Gemfile",
# or slightly more accurately, the lockfile name without the ".lock" bit.
targets = defined?(@gemfiles) ? @gemfiles : [Pathname.new(lockfile.to_s.chomp(".lock"))]
targets = defined?(@gemfiles) ? @gemfiles : [Pathname.new(original_lockfile.to_s.chomp(".lock"))]

targets.reverse_each do |gemfile|
load_local_bundler_d(File.dirname(gemfile))
end
end
super

super(lockfile, unlock).tap do |definition|
add_pristine_lock(definition, original_unlock) if enable_pristine?(original_lockfile)
end
end

private
Expand Down Expand Up @@ -97,6 +106,24 @@ def load_bundler_d(dir)
eval_gemfile(f)
end
end

def add_pristine_lock(definition, original_unlock)
definition.define_singleton_method(:lock) do |file, *args|
original_disable = ENV['BUNDLER_INJECT__DISABLE_OVERRIDE']
ENV['BUNDLER_INJECT__DISABLE_OVERRIDE'] = 'true'

pristine_definition = Bundler::Dsl.evaluate(@gemfiles.first, Bundler.default_lockfile, original_unlock)
pristine_definition.resolve_remotely! if pristine_definition.missing_specs?
pristine_definition.lock(Bundler.default_lockfile, *args)

ENV['BUNDLER_INJECT__DISABLE_OVERRIDE'] = original_disable
super(Pathname.new("#{file}.local"), *args)
end
end

def enable_pristine?(lockfile)
lockfile == Bundler.default_lockfile && Bundler.settings["bundler_inject.enable_pristine"]
end
end
end
end
3 changes: 2 additions & 1 deletion spec/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def write_gemfile(contents)
end

def lockfile
file = app_dir.join("Gemfile.lock")
lock_name = Bundler.settings["bundler_inject.enable_pristine"] ? "Gemfile.lock.local" : "Gemfile.lock"
file = app_dir.join(lock_name)
Bundler::LockfileParser.new(file.read) if file.exist?
end

Expand Down