Skip to content

Commit

Permalink
Ensure packaged git repos can be updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Mar 22, 2012
1 parent 5d1b0ab commit c8a738b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 21 deletions.
27 changes: 17 additions & 10 deletions lib/bundler/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 " \
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
66 changes: 55 additions & 11 deletions spec/cache/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit c8a738b

Please sign in to comment.