Permalink
Browse files

fixes #1390: Clean up cached git dirs in bundle clean

  • Loading branch information...
1 parent 9114465 commit 146aa06ffb48c7e48793540526466f2b74e66983 @hone hone committed Sep 14, 2011
Showing with 40 additions and 13 deletions.
  1. +5 −0 lib/bundler/runtime.rb
  2. +11 −12 lib/bundler/source.rb
  3. +24 −1 spec/other/clean_spec.rb
View
5 lib/bundler/runtime.rb
@@ -135,11 +135,13 @@ def clean
gem_bins = Dir["#{Gem.dir}/bin/*"]
git_dirs = Dir["#{Gem.dir}/bundler/gems/*"]
+ git_cache_dirs = Dir["#{Gem.dir}/cache/bundler/git/*"]
gem_dirs = Dir["#{Gem.dir}/gems/*"]
gem_files = Dir["#{Gem.dir}/cache/*.gem"]
gemspec_files = Dir["#{Gem.dir}/specifications/*.gemspec"]
spec_gem_paths = []
spec_git_paths = []
+ spec_git_cache_dirs = []
spec_gem_executables = []
spec_cache_paths = []
spec_gemspec_paths = []
@@ -153,12 +155,14 @@ def clean
end
spec_cache_paths << spec.cache_file
spec_gemspec_paths << spec.spec_file
+ spec_git_cache_dirs << spec.source.cache_path.to_s if spec.source.is_a?(Bundler::Source::Git)
end
spec_gem_paths.uniq!
spec_gem_executables.flatten!
stale_gem_bins = gem_bins - spec_gem_executables
stale_git_dirs = git_dirs - spec_git_paths
+ stale_git_cache_dirs = git_cache_dirs - spec_git_cache_dirs
stale_gem_dirs = gem_dirs - spec_gem_paths
stale_gem_files = gem_files - spec_cache_paths
stale_gemspec_files = gemspec_files - spec_gemspec_paths
@@ -195,6 +199,7 @@ def clean
stale_gem_files.each {|file| FileUtils.rm(file) if File.exists?(file) }
stale_gemspec_files.each {|file| FileUtils.rm(file) if File.exists?(file) }
+ stale_git_cache_dirs.each {|dir| FileUtils.rm_rf(dir) if File.exists?(dir) }
output
end
View
23 lib/bundler/source.rb
@@ -562,6 +562,17 @@ def load_spec_files
raise GitError, "#{to_s} is not checked out. Please run `bundle install`"
end
+ def cache_path
+ @cache_path ||= begin
+ git_scope = "#{base_name}-#{uri_hash}"
+
+ if Bundler.requires_sudo?
+ Bundler.user_bundle_path.join("cache/git", git_scope)
+ else
+ Bundler.cache.join("git", git_scope)
+ end
+ end
+ end
private
def git(command)
@@ -618,18 +629,6 @@ def uri_escaped
end
end
- def cache_path
- @cache_path ||= begin
- git_scope = "#{base_name}-#{uri_hash}"
-
- if Bundler.requires_sudo?
- Bundler.user_bundle_path.join("cache/git", git_scope)
- else
- Bundler.cache.join("git", git_scope)
- end
- end
- end
-
def cache
if cached?
return if has_revision_cached?
View
25 spec/other/clean_spec.rb
@@ -120,15 +120,37 @@ def should_not_have_gems(*gems)
vendored_gems("bin/rackup").should_not exist
end
+ it "does not remove cached git dir if it's being used" do
+ build_git "foo"
+ revision = revision_for(lib_path("foo-1.0"))
+ git_path = lib_path('foo-1.0')
+
+ gemfile = <<-G
+ source "file://#{gem_repo1}"
+
+ gem "rack", "1.0.0"
+ git "#{git_path}", :ref => "#{revision}" do
+ gem "foo"
+ end
+ G
+
+ install_gemfile(gemfile, :path => "vendor/bundle")
+
+ bundle :clean
+
+ vendored_gems("cache/bundler/git/foo-1.0-#{Digest::SHA1.hexdigest(git_path)}").should exist
+ end
+
it "removes unused git gems" do
build_git "foo"
revision = revision_for(lib_path("foo-1.0"))
+ git_path = lib_path('foo-1.0')
gemfile = <<-G
source "file://#{gem_repo1}"
gem "rack", "1.0.0"
- git "#{lib_path('foo-1.0')}", :ref => "#{revision}" do
+ git "#{git_path}", :ref => "#{revision}" do
gem "foo"
end
G
@@ -147,6 +169,7 @@ def should_not_have_gems(*gems)
vendored_gems("gems/rack-1.0.0").should exist
vendored_gems("bundler/gems/foo-1.0-#{revision[0..11]}").should_not exist
+ vendored_gems("cache/bundler/git/foo-1.0-#{Digest::SHA1.hexdigest(git_path)}").should_not exist
vendored_gems("specifications/rack-1.0.0.gemspec").should exist

0 comments on commit 146aa06

Please sign in to comment.