Permalink
Browse files

Ensure packaged git repos can be updated.

  • Loading branch information...
1 parent 5d1b0ab commit c8a738bd6c01b00abacd30fef86facd034602f48 @josevalim josevalim committed Mar 22, 2012
Showing with 72 additions and 21 deletions.
  1. +17 −10 lib/bundler/source.rb
  2. +55 −11 spec/cache/git_spec.rb
View
27 lib/bundler/source.rb
@@ -642,11 +642,6 @@ def initialize(options)
@update = false
@installed = nil
@local = false
-
- if has_app_cache?
- @local = true
- @install_path = @cache_path = app_cache_path
- end
end
def self.from_lock(options)
@@ -725,10 +720,11 @@ def local_override!(path)
"does not exist. Check `bundle config --delete` to remove the local override"
end
- @local = true
- @local_specs = nil
- @git_proxy = GitProxy.new(path, uri, ref)
- @cache_path = @install_path = path
+ set_local!(path)
+
+ # Create a new git proxy without the cached revision
+ # so the Gemfile.lock always picks up the new revision.
+ @git_proxy = GitProxy.new(path, uri, ref)
if git_proxy.branch != options["branch"]
raise GitError, "Local override for #{name} at #{path} is using branch " \
@@ -748,11 +744,16 @@ def local_override!(path)
# TODO: actually cache git specs
def specs(*)
+ if has_app_cache? && !local?
+ set_local!(app_cache_path)
+ end
+
if requires_checkout? && !@update
git_proxy.checkout
git_proxy.copy_to(install_path, submodules)
@update = true
end
+
local_specs
end
@@ -771,7 +772,7 @@ def cache(spec)
return if path.expand_path(Bundler.root).to_s.index(Bundler.root.to_s) == 0
cached!
FileUtils.rm_rf(app_cache_path)
- git_proxy.checkout
+ git_proxy.checkout if requires_checkout?
git_proxy.copy_to(app_cache_path, @submodules)
FileUtils.rm_rf(app_cache_path.join(".git"))
end
@@ -796,6 +797,12 @@ def cache_path
private
+ def set_local!(path)
+ @local = true
+ @local_specs = @git_proxy = nil
+ @cache_path = @install_path = path
+ end
+
def has_app_cache?
cached_revision && super
end
View
66 spec/cache/git_spec.rb
@@ -14,7 +14,7 @@
%w(cache package).each do |cmd|
describe "bundle #{cmd} with git" do
- it "copies repository to vendor cache" do
+ it "copies repository to vendor cache and uses it" do
git = build_git "foo"
ref = git.ref_for("master", 11)
@@ -30,25 +30,69 @@
should_be_installed "foo 1.0"
end
- it "ignores local repository in favor of the cache" do
+ it "runs twice without exploding" do
+ build_git "foo"
+
+ install_gemfile <<-G
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+
+ bundle "#{cmd} --all"
+ bundle "#{cmd} --all"
+
+ err.should == ""
+ FileUtils.rm_rf lib_path("foo-1.0")
+ should_be_installed "foo 1.0"
+ end
+
+ it "tracks updates" do
git = build_git "foo"
- ref = git.ref_for("master", 11)
+ old_ref = git.ref_for("master", 11)
- build_git "foo", :path => lib_path('local-foo') do |s|
- s.write "lib/foo.rb", "raise :FAIL"
+ install_gemfile <<-G
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+
+ bundle "#{cmd} --all"
+
+ update_git "foo" do |s|
+ s.write "lib/foo.rb", "puts :CACHE"
end
- install_gemfile <<-G
- gem "foo", :git => '#{lib_path("foo-1.0")}', :branch => :master
+ ref = git.ref_for("master", 11)
+ ref.should_not == old_ref
+
+ bundle "update"
+ bundle "#{cmd} --all"
+
+ bundled_app("vendor/cache/foo-1.0-#{ref}").should exist
+
+ FileUtils.rm_rf lib_path("foo-1.0")
+ run "require 'foo'"
+ out.should == "CACHE"
+ end
+
+ it "uses the local repository to generate the cache" do
+ git = build_git "foo"
+ ref = git.ref_for("master", 11)
+
+ gemfile <<-G
+ gem "foo", :git => '#{lib_path("foo-invalid")}', :branch => :master
G
+ bundle %|config local.foo #{lib_path('foo-1.0')}|
+ bundle "install"
bundle "#{cmd} --all"
- bundle %|config local.foo #{lib_path('local-foo')}|
- bundle :install
- out.should =~ /at #{bundled_app("vendor/cache/foo-1.0-#{ref}")}/
+ bundled_app("vendor/cache/foo-invalid-#{ref}").should exist
- should_be_installed "foo 1.0"
+ # Updating the local still uses the local.
+ update_git "foo" do |s|
+ s.write "lib/foo.rb", "puts :LOCAL"
+ end
+
+ run "require 'foo'"
+ out.should == "LOCAL"
end
it "copies repository to vendor cache, including submodules" do

0 comments on commit c8a738b

Please sign in to comment.