Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
fixes #1390: Clean up cached git dirs in bundle clean
Browse files Browse the repository at this point in the history
  • Loading branch information
hone committed Sep 14, 2011
1 parent 9114465 commit 146aa06
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
5 changes: 5 additions & 0 deletions lib/bundler/runtime.rb
Expand Up @@ -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 = []
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions lib/bundler/source.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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?
Expand Down
25 changes: 24 additions & 1 deletion spec/other/clean_spec.rb
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 146aa06

Please sign in to comment.