Skip to content

Commit

Permalink
[Downloader::Git] Skip cache pull if ref is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed May 9, 2012
1 parent 0d4dd44 commit b7baee9
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions lib/cocoapods/downloader/git.rb
Expand Up @@ -23,15 +23,7 @@ def download
end

def prepare_cache
return if config.git_cache_size == 0
if is_cache_valid?
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
else
unless cache_exist? || config.git_cache_size == 0
puts '->'.green << " Creating cache git repo (#{cache_path})" if config.verbose?
cache_path.rmtree if cache_path.exist?
cache_path.mkpath
Expand All @@ -55,7 +47,7 @@ def cache_path
@cache_path ||= caches_dir + "#{Digest::SHA1.hexdigest(url.to_s)}"
end

def is_cache_valid?
def cache_exist?
cache_path.exist? && origin_url(cache_path) == url
end

Expand All @@ -77,11 +69,33 @@ def caches_size
`du -cm`.split("\n").last.to_i
end

def update_cache
return if config.git_cache_size == 0
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)
return if config.git_cache_size == 0
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
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 '#{clone_url}'"
Expand All @@ -92,8 +106,8 @@ def download_tag
end

def download_commit
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
Expand Down

0 comments on commit b7baee9

Please sign in to comment.