Permalink
Browse files

Just cache git and path is --all is given.

  • Loading branch information...
1 parent 6ef6e75 commit d351e68fa0a5df6de7aff587effce0801297848a @josevalim josevalim committed Mar 20, 2012
Showing with 134 additions and 59 deletions.
  1. +14 −0 lib/bundler/cli.rb
  2. +1 −1 lib/bundler/runtime.rb
  3. +3 −0 lib/bundler/source.rb
  4. +10 −1 spec/cache/gems_spec.rb
  5. +51 −49 spec/cache/git_spec.rb
  6. +55 −8 spec/cache/path_spec.rb
View
14 lib/bundler/cli.rb
@@ -365,8 +365,10 @@ def outdated(*gems)
desc "cache", "Cache all the gems to vendor/cache", :hide => true
method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
+ method_option "all", :type => :boolean, :banner => "Include all sources (including path and git)."
def cache
Bundler.definition.resolve_with_cache!
+ setup_cache_all
Bundler.load.cache
Bundler.settings[:no_prune] = true if options["no-prune"]
Bundler.load.lock
@@ -378,13 +380,15 @@ def cache
desc "package", "Locks and then caches all of the gems into vendor/cache"
method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
+ method_option "all", :type => :boolean, :banner => "Include all sources (including path and git)."
long_desc <<-D
The package command will copy the .gem files for every gem in the bundle into the
directory ./vendor/cache. If you then check that directory into your source
control repository, others who check out your source will be able to install the
bundle without having to download any additional gems.
D
def package
+ setup_cache_all
install
# TODO: move cache contents here now that all bundles are locked
Bundler.load.cache
@@ -611,6 +615,16 @@ def clean
private
+ def setup_cache_all
+ if options.key?("all")
+ Bundler.settings[:cache_all] = options[:all] || nil
+ elsif Bundler.definition.sources.any? { |s| !s.is_a?(Source::Rubygems) }
+ Bundler.ui.warn "Your Gemfile contains path and git dependencies. If you want " \
+ "to package them as well, please pass the --all flag. This will be the default " \
+ "on Bundler 2.0."
+ end
+ end
+
def have_groff?
!(`which groff` rescue '').empty?
end
View
2 lib/bundler/runtime.rb
@@ -97,7 +97,7 @@ def dependencies_for(*groups)
def cache
FileUtils.mkdir_p(cache_path) unless File.exists?(cache_path)
- Bundler.ui.info "Updating .gem files in vendor/cache"
+ Bundler.ui.info "Updating files in vendor/cache"
specs.each do |spec|
next if spec.name == 'bundler'
spec.source.cache(spec) if spec.source.respond_to?(:cache)
View
3 lib/bundler/source.rb
@@ -367,6 +367,7 @@ def install(spec)
end
def cache(spec)
+ return unless Bundler.settings[:cache_all]
return if path.expand_path(Bundler.root).to_s.index(Bundler.root.to_s) == 0
FileUtils.rm_rf(app_cache_path)
FileUtils.cp_r("#{path}/.", app_cache_path)
@@ -766,7 +767,9 @@ def install(spec)
end
def cache(spec)
+ return unless Bundler.settings[:cache_all]
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.copy_to(app_cache_path, @submodules)
View
11 spec/cache/gems_spec.rb
@@ -123,7 +123,7 @@
it "re-caches during install" do
cached_gem("rack-1.0.0").rmtree
bundle :install
- out.should include("Updating .gem files in vendor/cache")
+ out.should include("Updating files in vendor/cache")
cached_gem("rack-1.0.0").should exist
end
@@ -215,6 +215,15 @@
out.should_not =~ /removing/i
end
+ it "does not warn about all if it doesn't have any git/path dependency" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+ G
+ bundle "cache"
+ out.should_not =~ /\-\-all/
+ end
+
it "should install gems with the name bundler in them (that aren't bundler)" do
build_gem "foo-bundler", "1.0",
:path => bundled_app('vendor/cache')
View
100 spec/cache/git_spec.rb
@@ -1,6 +1,6 @@
require "spec_helper"
-describe "bundle cache with git" do
+describe "git base name" do
it "base_name should strip private repo uris" do
source = Bundler::Source::Git.new("uri" => "git@github.com:bundler.git")
source.send(:base_name).should == "bundler"
@@ -10,69 +10,71 @@
source = Bundler::Source::Git.new("uri" => "//MachineName/ShareFolder")
source.send(:base_name).should == "ShareFolder"
end
+end
- it "copies repository to vendor cache" do
- git = build_git "foo"
- ref = git.ref_for("master", 11)
-
- install_gemfile <<-G
- gem "foo", :git => '#{lib_path("foo-1.0")}'
- G
-
- bundle "cache"
- bundled_app("vendor/cache/foo-1.0-#{ref}").should exist
- bundled_app("vendor/cache/foo-1.0-#{ref}/.git").should_not exist
+%w(cache package).each do |cmd|
+ describe "bundle #{cmd} with git" do
+ it "copies repository to vendor cache" do
+ git = build_git "foo"
+ ref = git.ref_for("master", 11)
- FileUtils.rm_rf lib_path("foo-1.0")
- out.should == "Updating .gem files in vendor/cache"
- should_be_installed "foo 1.0"
- end
+ install_gemfile <<-G
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
- it "ignores local repository in favor of the cache" do
- git = build_git "foo"
- ref = git.ref_for("master", 11)
+ bundle "#{cmd} --all"
+ bundled_app("vendor/cache/foo-1.0-#{ref}").should exist
+ bundled_app("vendor/cache/foo-1.0-#{ref}/.git").should_not exist
- build_git "foo", :path => lib_path('local-foo') do |s|
- s.write "lib/foo.rb", "raise :FAIL"
+ FileUtils.rm_rf lib_path("foo-1.0")
+ should_be_installed "foo 1.0"
end
- install_gemfile <<-G
- gem "foo", :git => '#{lib_path("foo-1.0")}', :branch => :master
- G
+ it "ignores local repository in favor of the cache" do
+ git = build_git "foo"
+ ref = git.ref_for("master", 11)
- bundle "cache"
- bundle %|config local.foo #{lib_path('local-foo')}|
+ build_git "foo", :path => lib_path('local-foo') do |s|
+ s.write "lib/foo.rb", "raise :FAIL"
+ end
- bundle :install
- out.should =~ /at #{bundled_app("vendor/cache/foo-1.0-#{ref}")}/
+ install_gemfile <<-G
+ gem "foo", :git => '#{lib_path("foo-1.0")}', :branch => :master
+ G
- should_be_installed "foo 1.0"
- end
+ bundle "#{cmd} --all"
+ bundle %|config local.foo #{lib_path('local-foo')}|
- it "copies repository to vendor cache, including submodules" do
- build_git "submodule", "1.0"
+ bundle :install
+ out.should =~ /at #{bundled_app("vendor/cache/foo-1.0-#{ref}")}/
- git = build_git "has_submodule", "1.0" do |s|
- s.add_dependency "submodule"
+ should_be_installed "foo 1.0"
end
- Dir.chdir(lib_path('has_submodule-1.0')) do
- `git submodule add #{lib_path('submodule-1.0')} submodule-1.0`
- `git commit -m "submodulator"`
- end
+ it "copies repository to vendor cache, including submodules" do
+ build_git "submodule", "1.0"
+
+ git = build_git "has_submodule", "1.0" do |s|
+ s.add_dependency "submodule"
+ end
- install_gemfile <<-G
- git "#{lib_path('has_submodule-1.0')}", :submodules => true do
- gem "has_submodule"
+ Dir.chdir(lib_path('has_submodule-1.0')) do
+ `git submodule add #{lib_path('submodule-1.0')} submodule-1.0`
+ `git commit -m "submodulator"`
end
- G
- ref = git.ref_for("master", 11)
- bundle "cache"
+ install_gemfile <<-G
+ git "#{lib_path('has_submodule-1.0')}", :submodules => true do
+ gem "has_submodule"
+ end
+ G
- bundled_app("vendor/cache/has_submodule-1.0-#{ref}").should exist
- bundled_app("vendor/cache/has_submodule-1.0-#{ref}/submodule-1.0").should exist
- out.should == "Updating .gem files in vendor/cache"
- should_be_installed "has_submodule 1.0"
+ ref = git.ref_for("master", 11)
+ bundle "#{cmd} --all"
+
+ bundled_app("vendor/cache/has_submodule-1.0-#{ref}").should exist
+ bundled_app("vendor/cache/has_submodule-1.0-#{ref}/submodule-1.0").should exist
+ should_be_installed "has_submodule 1.0"
+ end
end
-end
+end
View
63 spec/cache/path_spec.rb
@@ -1,18 +1,16 @@
require "spec_helper"
-describe "bundle cache" do
- describe "with path sources" do
+%w(cache package).each do |cmd|
+ describe "bundle #{cmd} with path" do
it "is no-op when the path is within the bundle" do
build_lib "foo", :path => bundled_app("lib/foo")
install_gemfile <<-G
gem "foo", :path => '#{bundled_app("lib/foo")}'
G
- bundle "cache"
+ bundle "#{cmd} --all"
bundled_app("vendor/cache/foo-1.0").should_not exist
-
- out.should == "Updating .gem files in vendor/cache"
should_be_installed "foo 1.0"
end
@@ -23,12 +21,61 @@
gem "foo", :path => '#{lib_path("foo-1.0")}'
G
- bundle "cache"
+ bundle "#{cmd} --all"
bundled_app("vendor/cache/foo-1.0").should exist
FileUtils.rm_rf lib_path("foo-1.0")
- out.should == "Updating .gem files in vendor/cache"
should_be_installed "foo 1.0"
end
+
+ it "raises a warning without --all" do
+ build_lib "foo"
+
+ install_gemfile <<-G
+ gem "foo", :path => '#{lib_path("foo-1.0")}'
+ G
+
+ bundle cmd
+ out.should =~ /please pass the \-\-all flag/
+ bundled_app("vendor/cache/foo-1.0").should_not exist
+ end
+
+ it "stores the given flag" do
+ build_lib "foo"
+
+ install_gemfile <<-G
+ gem "foo", :path => '#{lib_path("foo-1.0")}'
+ G
+
+ bundle "#{cmd} --all"
+ build_lib "bar"
+
+ install_gemfile <<-G
+ gem "foo", :path => '#{lib_path("foo-1.0")}'
+ gem "bar", :path => '#{lib_path("bar-1.0")}'
+ G
+
+ bundle cmd
+ bundled_app("vendor/cache/bar-1.0").should exist
+ end
+
+ it "can rewind chosen configuration" do
+ build_lib "foo"
+
+ install_gemfile <<-G
+ gem "foo", :path => '#{lib_path("foo-1.0")}'
+ G
+
+ bundle "#{cmd} --all"
+ build_lib "baz"
+
+ gemfile <<-G
+ gem "foo", :path => '#{lib_path("foo-1.0")}'
+ gem "baz", :path => '#{lib_path("baz-1.0")}'
+ G
+
+ bundle "#{cmd} --no-all"
+ bundled_app("vendor/cache/baz-1.0").should_not exist
+ end
end
-end
+end

0 comments on commit d351e68

Please sign in to comment.