Commit b7baee96 authored by Fabio Pelosin's avatar Fabio Pelosin

[Downloader::Git] Skip cache pull if ref is available.

parent 0d4dd44b
...@@ -23,15 +23,7 @@ module Pod ...@@ -23,15 +23,7 @@ module Pod
end end
def prepare_cache def prepare_cache
return if config.git_cache_size == 0 unless cache_exist? || 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
puts '->'.green << " Creating cache git repo (#{cache_path})" if config.verbose? puts '->'.green << " Creating cache git repo (#{cache_path})" if config.verbose?
cache_path.rmtree if cache_path.exist? cache_path.rmtree if cache_path.exist?
cache_path.mkpath cache_path.mkpath
...@@ -55,7 +47,7 @@ module Pod ...@@ -55,7 +47,7 @@ module Pod
@cache_path ||= caches_dir + "#{Digest::SHA1.hexdigest(url.to_s)}" @cache_path ||= caches_dir + "#{Digest::SHA1.hexdigest(url.to_s)}"
end end
def is_cache_valid? def cache_exist?
cache_path.exist? && origin_url(cache_path) == url cache_path.exist? && origin_url(cache_path) == url
end end
...@@ -77,11 +69,33 @@ module Pod ...@@ -77,11 +69,33 @@ module Pod
`du -cm`.split("\n").last.to_i `du -cm`.split("\n").last.to_i
end 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 def download_head
update_cache
git "clone '#{clone_url}' '#{target_path}'" git "clone '#{clone_url}' '#{target_path}'"
end end
def download_tag def download_tag
ensure_ref_exists(options[:tag])
Dir.chdir(target_path) do Dir.chdir(target_path) do
git "init" git "init"
git "remote add origin '#{clone_url}'" git "remote add origin '#{clone_url}'"
...@@ -92,8 +106,8 @@ module Pod ...@@ -92,8 +106,8 @@ module Pod
end end
def download_commit def download_commit
ensure_ref_exists(options[:commit])
git "clone '#{clone_url}' '#{target_path}'" git "clone '#{clone_url}' '#{target_path}'"
Dir.chdir(target_path) do Dir.chdir(target_path) do
git "checkout -b activated-pod-commit #{options[:commit]}" git "checkout -b activated-pod-commit #{options[:commit]}"
end end
......
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