Skip to content

Commit

Permalink
[Git] Refine tag downloads optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Jul 31, 2013
1 parent eaca4aa commit ce03a14
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
22 changes: 12 additions & 10 deletions Gemfile.lock
@@ -1,36 +1,38 @@
GEM
remote: http://rubygems.org/
specs:
addressable (2.3.3)
addressable (2.3.5)
bacon (1.2.0)
colorize (0.5.8)
coveralls (0.6.2)
coveralls (0.6.7)
colorize
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
thor
crack (0.3.2)
crack (0.4.1)
safe_yaml (~> 0.9.0)
metaclass (0.0.1)
mime-types (1.21)
mocha (0.13.3)
mime-types (1.23)
mocha (0.14.0)
metaclass (~> 0.0.1)
mocha-on-bacon (0.2.2)
mocha (>= 0.13.0)
multi_json (1.7.0)
rake (10.0.3)
multi_json (1.7.7)
rake (10.1.0)
rest-client (1.6.7)
mime-types (>= 1.16)
safe_yaml (0.9.4)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
thor (0.17.0)
vcr (2.4.0)
thor (0.18.1)
vcr (2.5.0)
webmock (1.8.11)
addressable (>= 2.2.7)
crack (>= 0.1.7)
yard (0.8.5.2)
yard (0.8.7)

PLATFORMS
ruby
Expand Down
10 changes: 7 additions & 3 deletions lib/cocoapods-downloader/git.rb
Expand Up @@ -77,22 +77,26 @@ def clone(from, to)
# @note Git fetch and checkout output to standard error and thus they
# are redirected to stdout.
#
# @note For performance if the cache is used the repo is inialized with
# git clone (see CocoaPods/CocoaPods#1077).
#
def download_tag
if use_cache?
if aggressive_cache?
ensure_ref_exists(options[:tag])
else
update_cache
end

git! "clone '#{clone_url}' '#{target_path}'"
end

Dir.chdir(target_path) do
if !use_cache?
if use_cache?
git! "clone '#{clone_url}' '#{target_path}'"
else
git! "init"
git! "remote add origin '#{clone_url}'"
end

git! "fetch origin tags/#{options[:tag]} 2>&1"
git! "reset --hard FETCH_HEAD"
git! "checkout -b activated-pod-commit 2>&1"
Expand Down
13 changes: 13 additions & 0 deletions spec/cocoapods-downloaders/git_spec.rb
Expand Up @@ -29,6 +29,19 @@ module Downloader
tmp_folder('README').read.strip.should == 'v1.0'
end

it "checks out a specific tag using git clone when a cache is available for performance" do
options = { :git => fixture('git-repo'), :tag => 'v1.0' }
downloader = Downloader.for_target(tmp_folder('destination'), options)
downloader.cache_root = tmp_folder('cache')
def downloader.execute_command(executable, command, raise_on_failure = false)
@spec_commands_log ||= []
@spec_commands_log << command
end
downloader.download
commands = downloader.instance_variable_get("@spec_commands_log").join("\n")
commands.should.not.include("init")
end

it "doesn't updates submodules by default" do
options = { :git => fixture('git-repo'), :commit => 'd7f4104' }
downloader = Downloader.for_target(tmp_folder, options)
Expand Down

0 comments on commit ce03a14

Please sign in to comment.