summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Arko <mail@arko.net>2015-06-08 14:40:44 -0700
committerAndré Arko <mail@arko.net>2015-06-08 14:40:44 -0700
commitf9a5def6039587027770929974668a64b58117fd (patch)
tree7b9f21d98f9d315e21982b2261290cf14b59966d
parent00ca9ae0800b61316e973af46e03e8c7d3a0fd07 (diff)
parent14c22c74ddf22962c450a79058ec027e295f923e (diff)
downloadbundler-f9a5def6039587027770929974668a64b58117fd.tar.gz
Merge pull request #3722 from bundler/implicit_lock_preservation
Implicit lock preservation
-rw-r--r--lib/bundler/cli/check.rb2
-rw-r--r--lib/bundler/definition.rb15
-rw-r--r--lib/bundler/environment.rb4
-rw-r--r--lib/bundler/inline.rb2
-rw-r--r--lib/bundler/runtime.rb2
-rw-r--r--spec/commands/check_spec.rb57
-rw-r--r--spec/runtime/setup_spec.rb56
7 files changed, 131 insertions, 7 deletions
diff --git a/lib/bundler/cli/check.rb b/lib/bundler/cli/check.rb
index 071bcc3a42..0efdfa11af 100644
--- a/lib/bundler/cli/check.rb
+++ b/lib/bundler/cli/check.rb
@@ -26,7 +26,7 @@ module Bundler
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
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 0cd2010111..81401ff81a 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -1,3 +1,4 @@
+require "bundler/lockfile_parser"
require "digest/sha1"
require "set"
@@ -240,14 +241,14 @@ module Bundler
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."
@@ -658,5 +659,15 @@ module Bundler
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\n#{LockfileParser::BUNDLED}\n\s+#{Gem::Version::VERSION_PATTERN}\n/
+ current.sub(pattern, "\n") == proposed.sub(pattern, "\n")
+ else
+ current == proposed
+ end
+ end
+
end
end
diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb
index 76e263695f..4b006c9c84 100644
--- a/lib/bundler/environment.rb
+++ b/lib/bundler/environment.rb
@@ -30,8 +30,8 @@ module Bundler
@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)
diff --git a/lib/bundler/inline.rb b/lib/bundler/inline.rb
index e9f6eaa994..26dc6dff49 100644
--- a/lib/bundler/inline.rb
+++ b/lib/bundler/inline.rb
@@ -39,7 +39,7 @@ def gemfile(install = false, &gemfile)
builder.instance_eval(&gemfile)
definition = builder.to_definition(nil, true)
- def definition.lock(file); end
+ def definition.lock(*); end
definition.validate_ruby!
if install
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index be61c2b15b..8915bea64a 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -41,7 +41,7 @@ module Bundler
setup_manpath
- lock
+ lock(:preserve_bundled_with => true)
self
end
diff --git a/spec/commands/check_spec.rb b/spec/commands/check_spec.rb
index 6d047597d5..ae20fc35db 100644
--- a/spec/commands/check_spec.rb
+++ b/spec/commands/check_spec.rb
@@ -275,4 +275,61 @@ describe "bundle check" do
expect(out).to include("* rack (1.0")
end
end
+
+ describe "BUNDLED WITH" do
+ def lock_with(bundler_version = nil)
+ lock = <<-L
+ GEM
+ remote: file:#{gem_repo1}/
+ specs:
+ rack (1.0.0)
+
+ PLATFORMS
+ #{generic(Gem::Platform.local)}
+
+ DEPENDENCIES
+ rack
+ L
+
+ if bundler_version
+ lock << "\n BUNDLED WITH\n #{bundler_version}\n"
+ end
+
+ lock
+ end
+
+ before do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+ G
+ end
+
+ context "is not present" do
+ it "does not change the lock" do
+ lockfile lock_with(nil)
+ bundle :check
+ lockfile_should_be lock_with(nil)
+ end
+ end
+
+ context "is newer" do
+ it "does not change the lock but warns" do
+ lockfile lock_with(Bundler::VERSION.succ)
+ bundle :check
+ expect(out).to include("Bundler is older than the version that created the lockfile")
+ expect(err).to eq("")
+ lockfile_should_be lock_with(Bundler::VERSION.succ)
+ end
+ end
+
+ context "is older" do
+ it "does not change the lock" do
+ lockfile lock_with("1.10.1")
+ bundle :check
+ lockfile_should_be lock_with("1.10.1")
+ end
+ end
+ end
+
end
diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb
index cd9912dcff..a253d4e86e 100644
--- a/spec/runtime/setup_spec.rb
+++ b/spec/runtime/setup_spec.rb
@@ -899,4 +899,60 @@ describe "Bundler.setup" do
end
end
+ describe "when BUNDLED WITH" do
+ def lock_with(bundler_version = nil)
+ lock = <<-L
+ GEM
+ remote: file:#{gem_repo1}/
+ specs:
+ rack (1.0.0)
+
+ PLATFORMS
+ #{generic(Gem::Platform.local)}
+
+ DEPENDENCIES
+ rack
+ L
+
+ if bundler_version
+ lock << "\n BUNDLED WITH\n #{bundler_version}\n"
+ end
+
+ lock
+ end
+
+ before do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+ G
+ end
+
+ context "is not present" do
+ it "does not change the lock" do
+ lockfile lock_with(nil)
+ ruby "require 'bundler/setup'"
+ lockfile_should_be lock_with(nil)
+ end
+ end
+
+ context "is newer" do
+ it "does not change the lock or warn" do
+ lockfile lock_with(Bundler::VERSION.succ)
+ ruby "require 'bundler/setup'"
+ expect(out).to eq("")
+ expect(err).to eq("")
+ lockfile_should_be lock_with(Bundler::VERSION.succ)
+ end
+ end
+
+ context "is older" do
+ it "does not change the lock" do
+ lockfile lock_with("1.10.1")
+ ruby "require 'bundler/setup'"
+ lockfile_should_be lock_with("1.10.1")
+ end
+ end
+ end
+
end