Skip to content

Commit

Permalink
Add tests for Gemfile hashing, fix hashing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Arko and Terence Lee committed Mar 16, 2011
1 parent 48758f9 commit 3d88ab9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
20 changes: 10 additions & 10 deletions lib/bundler/definition.rb
Expand Up @@ -137,7 +137,7 @@ def specs_for(groups)

def resolve
@resolve ||= begin
if Bundler.settings[:frozen]
if Bundler.settings[:frozen] || lock_current?
@locked_specs
else
last_resolve = converge_locked_specs
Expand All @@ -151,24 +151,24 @@ def resolve
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
Expand Down
31 changes: 30 additions & 1 deletion spec/install/gems/resolving_spec.rb
Expand Up @@ -69,4 +69,33 @@
end
end
end
end

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

0 comments on commit 3d88ab9

Please sign in to comment.