Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
avoid altering BUNDLED WITH during implicit locks
Browse files Browse the repository at this point in the history
When either `bundle check` is run, or any application requires the 
`bundler/setup` file, Bundler will automatically check whether it is 
possible to lock the Bundle. During the lock process, Bundler updates 
the lock if the implicit locking changes the lock file.

Starting with the 1.10 release, Bundler includes a lockfile section 
named BUNDLED WITH that includes the version of Bundler that generated 
the lockfile. In order to minimize git churn, and guarantee that the 
lockfile will only be changed when the user runs an explicit Bundler 
command, Bundler will now only add or update the BUNDLED WITH section 
during commands where the user asks for changes to the lock. This 
includes, but is not limited to, `install`, `update`, `lock`, and 
`package`.

Running the `check` command or loading an application that uses Bundler 
will still now add or update the BUNDLED WITH section if, and only if,
the lockfile has also changed for a different reason (such as a gem 
being updated).

Simply using an application, by running  `bundle exec` commands or by 
running `bin/rails` and the like, will not change the lockfile. As a 
result, the intended workflow with the BUNDLED WITH section is now 
slightly different than it was before:

1. When running `bundle install`, Bundler will update the version in 
   the lockfile if newer than the version present.
2. Then, check in the lockfile change, exactly as you would after 
   running install to change any other gem version.
3. Older versions of Bundler will not change the number in the lock, 
   but will warn the user that they are out of date.

refs rubygems/bundler-features#80
refs #3697
  • Loading branch information
indirect committed Jun 6, 2015
1 parent e291376 commit ae2e5c4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/bundler/cli/check.rb
Expand Up @@ -26,7 +26,7 @@ def run
Bundler.ui.error "This bundle has been frozen, but there is no Gemfile.lock present"
exit 1
else
Bundler.load.lock unless options[:"dry-run"]
Bundler.load.lock(:preserve_bundled_with => true) unless options[:"dry-run"]
Bundler.ui.info "The Gemfile's dependencies are satisfied"
end
end
Expand Down
14 changes: 12 additions & 2 deletions lib/bundler/definition.rb
Expand Up @@ -240,14 +240,14 @@ def groups
dependencies.map { |d| d.groups }.flatten.uniq
end

def lock(file)
def lock(file, preserve_bundled_with = false)
contents = to_lock

# Convert to \r\n if the existing lock has them
# i.e., Windows with `git config core.autocrlf=true`
contents.gsub!(/\n/, "\r\n") if @lockfile_contents.match("\r\n")

return if @lockfile_contents == contents
return if lockfiles_equal?(@lockfile_contents, contents, preserve_bundled_with)

if Bundler.settings[:frozen]
Bundler.ui.error "Cannot write a changed lockfile while frozen."
Expand Down Expand Up @@ -658,5 +658,15 @@ def pinned_spec_names(specs)
def requested_groups
self.groups - Bundler.settings.without - @optional_groups + Bundler.settings.with
end

def lockfiles_equal?(current, proposed, preserve_bundled_with)
if preserve_bundled_with
pattern = /\n\nBUNDLED WITH\n.*\n/
current.sub(pattern, "\n") == proposed.sub(pattern, "\n")
else
current == proposed
end
end

end
end
4 changes: 2 additions & 2 deletions lib/bundler/environment.rb
Expand Up @@ -30,8 +30,8 @@ def current_dependencies
@definition.current_dependencies
end

def lock
@definition.lock(Bundler.default_lockfile)
def lock(opts = {})
@definition.lock(Bundler.default_lockfile, opts[:preserve_bundled_with])
end

def update(*gems)
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/runtime.rb
Expand Up @@ -41,7 +41,7 @@ def setup(*groups)

setup_manpath

lock
lock(:preserve_bundled_with => true)

self
end
Expand Down

0 comments on commit ae2e5c4

Please sign in to comment.