summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Arko and Terence Lee <andre.arko+terence.lee@gmail.com>2011-03-15 17:45:30 -0700
committerAndre Arko and Terence Lee <andre.arko+terence.lee@gmail.com>2011-03-15 17:46:59 -0700
commit3d88ab9e3dab9c524c0f1b5561af2cbb92ac791a (patch)
tree821d0446d749c76d8754a5561da91e237bd2287a
parent48758f945d19628ce4b480080f120449395d9e5f (diff)
downloadbundler-gemfile_hashing.tar.gz
Add tests for Gemfile hashing, fix hashing logicgemfile_hashing
-rw-r--r--lib/bundler/definition.rb20
-rw-r--r--spec/install/gems/resolving_spec.rb31
2 files changed, 40 insertions, 11 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 674534ba63..bf610dbc24 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -137,7 +137,7 @@ module Bundler
def resolve
@resolve ||= begin
- if Bundler.settings[:frozen]
+ if Bundler.settings[:frozen] || lock_current?
@locked_specs
else
last_resolve = converge_locked_specs
@@ -151,24 +151,24 @@ module Bundler
source_requirements[dep.name] = dep.source.specs
end
- # Only run a resolve against the locally available gems if Gemfile has changed
- # since the last resolve
- return last_resolve unless gemfile_changed?
-
- # If it's changed, update hash and rerun resolve
Bundler.settings[:gemfile_hash] = gemfile_hash
- last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve) end
+ last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve)
+ end
end
end
- def gemfile_changed?
- Digest::MD5.hexdigest(File.read(Bundler.default_gemfile)) == Bundler.settings[:gemfile_hash]
+ def gemfile_hash
+ Digest::MD5.hexdigest(Bundler.default_gemfile.read)
+ end
+
+ def lock_current?
+ Bundler.settings[:gemfile_hash] == gemfile_hash && Bundler.default_lockfile.exist?
end
def index
@index ||= Index.build do |idx|
@sources.each do |s|
- idx.use s.specs
+ idx.use s.specs(@dependencies)
end
end
end
diff --git a/spec/install/gems/resolving_spec.rb b/spec/install/gems/resolving_spec.rb
index 67b9b2f928..ee512a979c 100644
--- a/spec/install/gems/resolving_spec.rb
+++ b/spec/install/gems/resolving_spec.rb
@@ -69,4 +69,33 @@ describe "bundle install with gem sources" do
end
end
end
-end \ No newline at end of file
+
+ context "Gemfile hashing" do
+ before do
+ build_lib('foo')
+ install_gemfile <<-G, :expect_err => true
+ source "file://#{gem_repo1}"
+ gem "foo", :path => "#{lib_path('foo-1.0')}"
+ G
+ end
+
+ it "when Gemfile changes it reruns the resolver" do
+ install_gemfile <<-G, :expect_err => true, :env => {"DEBUG_RESOLVER" => true }
+ gem "foo", :path => "#{lib_path('foo-1.0')}"
+ G
+ err.should_not == ""
+ end
+
+ it "if the Gemfile has not changed don't rerun the resolver" do
+ bundle :install, :env => {"DEBUG_RESOLVER" => true }
+ err.should == ""
+ end
+
+ it "if the Gemfile.lock does not exist, generate one" do
+ bundled_app('Gemfile.lock').rmtree
+
+ bundle :install, :expect_err => true, :env => {"DEBUG_RESOLVER" => true }
+ err.should_not == ""
+ end
+ end
+end