Commit a1286c7a authored by Fabio Pelosin's avatar Fabio Pelosin

Merge branch 'master' into spec-refactor

Get the cache for testing.

* master:
  Enable caching for specs and remove configurable git cache size.
  Save Git chaches in ~/Library/Caches/CocoaPods/Git.
  [Downloader::Git] Skip cache pull if ref is available.
  Restored Pod::Downloader::Git::GitHub.
  [Git] Fix for Travis errors.
  [Git] Increased default cache to 500Mb.
  [Downloader::Git] Completed cache support
  [Git<<Downloader] Fix for url hash
  [Downloader::Git] Cache repos
parents 0c5c43c1 9838d174
......@@ -14,6 +14,7 @@ module Pod
attr_accessor :clean, :verbose, :silent
attr_accessor :generate_docs, :doc_install, :force_doc
attr_accessor :integrate_targets
attr_accessor :git_cache_size
alias_method :clean?, :clean
alias_method :verbose?, :verbose
......
require 'open-uri'
require 'tempfile'
require 'zlib'
require 'digest/sha1'
module Pod
class Downloader
class Git < Downloader
include Config::Mixin
executable :git
MAX_CACHE_SIZE = 500
def download
prepare_cache
puts '->'.green << ' Cloning git repo' if config.verbose?
if options[:tag]
download_tag
elsif options[:commit]
......@@ -15,16 +21,83 @@ module Pod
else
download_head
end
removed_cached_repos_if_needed
end
def prepare_cache
unless cache_exist?
puts '->'.green << " Creating cache git repo (#{cache_path})" if config.verbose?
cache_path.rmtree if cache_path.exist?
cache_path.mkpath
git "clone '#{url}' #{cache_path}"
end
end
def removed_cached_repos_if_needed
return unless caches_dir.exist?
Dir.chdir(caches_dir) do
repos = Pathname.new(caches_dir).children.select { |c| c.directory? }.sort_by(&:ctime)
while caches_size >= MAX_CACHE_SIZE && !repos.empty?
dir = repos.shift
puts '->'.yellow << " Removing git cache for `#{origin_url(dir)}'" if config.verbose?
dir.rmtree
end
end
end
def cache_path
@cache_path ||= caches_dir + "#{Digest::SHA1.hexdigest(url.to_s)}"
end
def cache_exist?
cache_path.exist? && origin_url(cache_path) == url
end
def origin_url(dir)
Dir.chdir(dir) { `git config remote.origin.url`.chomp }
end
def caches_dir
Pathname.new(File.expand_path("~/Library/Caches/CocoaPods/Git"))
end
def clone_url
cache_path
end
def caches_size
# expressed in Mb
`du -cm`.split("\n").last.to_i
end
def update_cache
puts '->'.green << " Updating cache git repo (#{cache_path})" if config.verbose?
Dir.chdir(cache_path) do
git "reset --hard HEAD"
git "clean -d -x -f"
git "pull"
end
end
def ensure_ref_exists(ref)
Dir.chdir(cache_path) { git "rev-list --max-count=1 #{ref}" }
return if $? == 0
# Skip pull if not needed
update_cache
Dir.chdir(cache_path) { git "rev-list --max-count=1 #{ref}" }
raise Informative, "[!] Cache unable to find git reference `#{ref}' for `#{url}'.".red unless $? == 0
end
def download_head
git "clone '#{url}' '#{target_path}'"
update_cache
git "clone '#{clone_url}' '#{target_path}'"
end
def download_tag
ensure_ref_exists(options[:tag])
Dir.chdir(target_path) do
git "init"
git "remote add origin '#{url}'"
git "remote add origin '#{clone_url}'"
git "fetch origin tags/#{options[:tag]}"
git "reset --hard FETCH_HEAD"
git "checkout -b activated-pod-commit"
......@@ -32,8 +105,8 @@ module Pod
end
def download_commit
git "clone '#{url}' '#{target_path}'"
ensure_ref_exists(options[:commit])
git "clone '#{clone_url}' '#{target_path}'"
Dir.chdir(target_path) do
git "checkout -b activated-pod-commit #{options[:commit]}"
end
......@@ -71,7 +144,7 @@ module Pod
original_url, username, reponame = *(url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/).to_a)
"https://github.com/#{username}/#{reponame}/tarball/#{id}"
end
def tmp_path
target_path + "tarball.tar.gz"
end
......
......@@ -19,7 +19,7 @@ describe "Pod::Downloader" do
downloader.url.should == 'http://banana-corp.local/banana-lib.git'
downloader.options.should == { :tag => 'v1.0' }
end
it 'returns a github downloader when the :git URL is on github' do
pod = Pod::LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), temporary_sandbox, Pod::Platform.ios)
pod.specification.stubs(:source).returns(:git => "git://github.com/CocoaPods/CocoaPods")
......@@ -36,21 +36,21 @@ describe Pod::Downloader::GitHub do
))
downloader.tarball_url_for('master').should == "https://github.com/CocoaPods/CocoaPods/tarball/master"
end
it 'can convert private HTTP repository URLs to the tarball URL' do
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:git => "https://lukeredpath@github.com/CocoaPods/CocoaPods.git"
))
downloader.tarball_url_for('master').should == "https://github.com/CocoaPods/CocoaPods/tarball/master"
end
it 'can convert private SSH repository URLs to the tarball URL' do
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:git => "git@github.com:CocoaPods/CocoaPods.git"
))
downloader.tarball_url_for('master').should == "https://github.com/CocoaPods/CocoaPods/tarball/master"
end
it 'can convert public git protocol repository URLs to the tarball URL' do
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:git => "git://github.com/CocoaPods/CocoaPods.git"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment