Commit 139e6e48 authored by Fabio Pelosin's avatar Fabio Pelosin

[Git] Init submodules only if requested.

parent e698a1c1
...@@ -14,6 +14,7 @@ module Pod ...@@ -14,6 +14,7 @@ module Pod
def download def download
create_cache unless cache_exist? create_cache unless cache_exist?
puts '-> Cloning git repo' if config.verbose? puts '-> Cloning git repo' if config.verbose?
if options[:tag] if options[:tag]
download_tag download_tag
elsif options[:branch] elsif options[:branch]
...@@ -23,6 +24,8 @@ module Pod ...@@ -23,6 +24,8 @@ module Pod
else else
download_head download_head
end end
Dir.chdir(target_path) { git "submodule update --init" } if options[:submodules]
prune_cache prune_cache
end end
...@@ -76,7 +79,6 @@ module Pod ...@@ -76,7 +79,6 @@ module Pod
git "reset --hard HEAD" git "reset --hard HEAD"
git "clean -d -x -f" git "clean -d -x -f"
git "pull" git "pull"
git "submodule update"
end end
end end
...@@ -105,7 +107,6 @@ module Pod ...@@ -105,7 +107,6 @@ module Pod
create_cache create_cache
end end
git %Q|clone "#{clone_url}" "#{target_path}"| git %Q|clone "#{clone_url}" "#{target_path}"|
Dir.chdir(target_path) { git "submodule update --init" }
end end
def download_tag def download_tag
...@@ -116,7 +117,6 @@ module Pod ...@@ -116,7 +117,6 @@ module Pod
git "fetch origin tags/#{options[:tag]}" git "fetch origin tags/#{options[:tag]}"
git "reset --hard FETCH_HEAD" git "reset --hard FETCH_HEAD"
git "checkout -b activated-pod-commit" git "checkout -b activated-pod-commit"
git "submodule update --init"
end end
end end
...@@ -125,7 +125,6 @@ module Pod ...@@ -125,7 +125,6 @@ module Pod
git %Q|clone "#{clone_url}" "#{target_path}"| git %Q|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]}"
git "submodule update --init"
end end
end end
...@@ -136,7 +135,6 @@ module Pod ...@@ -136,7 +135,6 @@ module Pod
git "remote add upstream '#{@url}'" # we need to add the original url, not the cache url git "remote add upstream '#{@url}'" # we need to add the original url, not the cache url
git "fetch -q upstream" # refresh the branches git "fetch -q upstream" # refresh the branches
git "checkout --track -b activated-pod-commit upstream/#{options[:branch]}" # create a new tracking branch git "checkout --track -b activated-pod-commit upstream/#{options[:branch]}" # create a new tracking branch
git "submodule update --init"
puts "Just downloaded and checked out branch: #{options[:branch]} from upstream #{clone_url}" if config.verbose? puts "Just downloaded and checked out branch: #{options[:branch]} from upstream #{clone_url}" if config.verbose?
end end
end end
......
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Downloader::Git do
extend SpecHelper::TemporaryDirectory
before do
@pod = LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), temporary_sandbox, Platform.ios)
end
it "check's out a specific commit" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'fd56054'
)
downloader = Downloader.for_pod(@pod)
downloader.download
(@pod.root + 'README').read.strip.should == 'first commit'
end
it "check's out a specific branch" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :branch => 'topicbranch'
)
downloader = Downloader.for_pod(@pod)
downloader.download
(@pod.root + 'README').read.strip.should == 'topicbranch'
end
it "check's out a specific tag" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :tag => 'v1.0'
)
downloader = Downloader.for_pod(@pod)
downloader.download
(@pod.root + 'README').read.strip.should == 'v1.0'
end
it "doesn't updates submodules by default" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => '6cc9afc'
)
downloader = Downloader.for_pod(@pod)
downloader.download
(@pod.root + 'README').read.strip.should == 'post v1.0'
(@pod.root + 'libPusher/README.md').should.not.exist?
end
it "initializes submodules when checking out a specific commit" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => '6cc9afc', :submodules => true
)
downloader = Downloader.for_pod(@pod)
downloader.download
(@pod.root + 'README').read.strip.should == 'post v1.0'
(@pod.root + 'libPusher/README.md').read.strip.should.match /^libPusher/
end
it "initializes submodules when checking out a specific tag" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :tag => 'v1.1', :submodules => true
)
downloader = Downloader.for_pod(@pod)
downloader.download
(@pod.root + 'README').read.strip.should == 'post v1.0'
(@pod.root + 'libPusher/README.md').read.strip.should.match /^libPusher/
end
it "prepares the cache if it does not exist" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'fd56054'
)
downloader = Downloader.for_pod(@pod)
downloader.cache_path.rmtree if downloader.cache_path.exist?
downloader.expects(:create_cache).once
downloader.stubs(:download_commit)
downloader.download
end
it "prepares the cache if it does not exist when the HEAD is requested explicitly" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib')
)
downloader = Downloader.for_pod(@pod)
downloader.cache_path.rmtree if downloader.cache_path.exist?
downloader.expects(:create_cache).once
downloader.stubs(:clone)
downloader.download_head
end
it "removes the oldest repo if the caches is too big" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'fd56054'
)
original_chace_size = Downloader::Git::MAX_CACHE_SIZE
Downloader::Git.__send__(:remove_const,'MAX_CACHE_SIZE')
Downloader::Git::MAX_CACHE_SIZE = 0
downloader = Downloader.for_pod(@pod)
downloader.stubs(:cache_dir).returns(temporary_directory)
downloader.download
downloader.cache_path.should.not.exist?
Downloader::Git.__send__(:remove_const,'MAX_CACHE_SIZE')
Downloader::Git::MAX_CACHE_SIZE = original_chace_size
end
xit "raises if it can't find the url" do
@pod.top_specification.stubs(:source).returns(
:git => 'find_me_if_you_can'
)
downloader = Downloader.for_pod(@pod)
lambda { downloader.download }.should.raise Informative
end
it "raises if it can't find a commit" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'aaaaaa'
)
downloader = Downloader.for_pod(@pod)
lambda { downloader.download }.should.raise Informative
end
it "raises if it can't find a tag" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :tag => 'aaaaaa'
)
downloader = Downloader.for_pod(@pod)
lambda { downloader.download }.should.raise Informative
end
it "does not raise if it can find the reference" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'fd56054'
)
downloader = Downloader.for_pod(@pod)
lambda { downloader.download }.should.not.raise
end
it "returns the cache directory as the clone url" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'fd56054'
)
downloader = Downloader.for_pod(@pod)
downloader.clone_url.to_s.should.match /Library\/Caches\/CocoaPods\/Git/
end
it "updates the cache if the HEAD is requested" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib')
)
downloader = Downloader.for_pod(@pod)
downloader.expects(:update_cache).once
downloader.download
end
it "updates the cache if the ref is not available" do
# create the origin repo and the cache
tmp_repo_path = temporary_directory + 'banana-lib-source'
`git clone #{fixture('banana-lib')} #{tmp_repo_path}`
@pod.top_specification.stubs(:source).returns(
:git => tmp_repo_path, :commit => 'fd56054'
)
downloader = Downloader.for_pod(@pod)
downloader.download
# make a new commit in the origin
commit = ''
Dir.chdir(tmp_repo_path) do
`touch test.txt`
`git add test.txt`
`git commit -m 'test'`
commit = `git rev-parse HEAD`.chomp
end
# require the new commit
pod = LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), temporary_sandbox, Platform.ios)
pod.top_specification.stubs(:source).returns(
:git => tmp_repo_path, :commit => commit
)
downloader = Downloader.for_pod(pod)
downloader.download
(pod.root + 'test.txt').should.exist?
end
it "doesn't update the cache if the ref is available" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'fd56054'
)
downloader = Downloader.for_pod(@pod)
downloader.download
downloader.expects(:update_cache).never
downloader.download
end
end
describe "for GitHub repositories, with :download_only set to true" do
extend SpecHelper::TemporaryDirectory
before do
@pod = LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), temporary_sandbox, Platform.ios)
end
it "downloads HEAD with no other options specified" do
@pod.top_specification.stubs(:source).returns(
:git => "git://github.com/lukeredpath/libPusher.git", :download_only => true
)
downloader = Downloader.for_pod(@pod)
VCR.use_cassette('tarballs', :record => :new_episodes) { downloader.download }
# deliberately keep this assertion as loose as possible for now
(@pod.root + 'README.md').readlines[0].should =~ /libPusher/
end
it "downloads a specific tag when specified" do
@pod.top_specification.stubs(:source).returns(
:git => "git://github.com/lukeredpath/libPusher.git", :tag => 'v1.1', :download_only => true
)
downloader = Downloader.for_pod(@pod)
VCR.use_cassette('tarballs', :record => :new_episodes) { downloader.download }
# deliberately keep this assertion as loose as possible for now
(@pod.root + 'libPusher.podspec').readlines.grep(/1.1/).should.not.be.empty
end
it "downloads a specific branch when specified" do
@pod.top_specification.stubs(:source).returns(
:git => "git://github.com/lukeredpath/libPusher.git", :branch => 'gh-pages', :download_only => true
)
downloader = Downloader.for_pod(@pod)
VCR.use_cassette('tarballs', :record => :new_episodes) { downloader.download }
# deliberately keep this assertion as loose as possible for now
(@pod.root + 'index.html').readlines.grep(/libPusher Documentation/).should.not.be.empty
end
it "downloads a specific commit when specified" do
@pod.top_specification.stubs(:source).returns(
:git => "git://github.com/lukeredpath/libPusher.git", :commit => 'eca89998d5', :download_only => true
)
downloader = Downloader.for_pod(@pod)
VCR.use_cassette('tarballs', :record => :new_episodes) { downloader.download }
# deliberately keep this assertion as loose as possible for now
(@pod.root + 'README.md').readlines[0].should =~ /PusherTouch/
end
end
end
...@@ -6,241 +6,6 @@ module Pod ...@@ -6,241 +6,6 @@ module Pod
@pod = LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), temporary_sandbox, Platform.ios) @pod = LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), temporary_sandbox, Platform.ios)
end end
describe "for Git" do
extend SpecHelper::TemporaryDirectory
it "check's out a specific commit" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'fd56054'
)
downloader = Downloader.for_pod(@pod)
downloader.download
(@pod.root + 'README').read.strip.should == 'first commit'
end
it "check's out a specific branch" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :branch => 'topicbranch'
)
downloader = Downloader.for_pod(@pod)
downloader.download
(@pod.root + 'README').read.strip.should == 'topicbranch'
end
it "check's out a specific tag" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :tag => 'v1.0'
)
downloader = Downloader.for_pod(@pod)
downloader.download
(@pod.root + 'README').read.strip.should == 'v1.0'
end
it "initializes submodules when checking out a specific commit" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => '6cc9afc'
)
downloader = Downloader.for_pod(@pod)
downloader.download
(@pod.root + 'README').read.strip.should == 'post v1.0'
(@pod.root + 'libPusher/README.md').read.strip.should.match /^libPusher/
end
it "initializes submodules when checking out a specific tag" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :tag => 'v1.1'
)
downloader = Downloader.for_pod(@pod)
downloader.download
(@pod.root + 'README').read.strip.should == 'post v1.0'
(@pod.root + 'libPusher/README.md').read.strip.should.match /^libPusher/
end
it "prepares the cache if it does not exist" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'fd56054'
)
downloader = Downloader.for_pod(@pod)
downloader.cache_path.rmtree if downloader.cache_path.exist?
downloader.expects(:create_cache).once
downloader.stubs(:download_commit)
downloader.download
end
it "prepares the cache if it does not exist when the HEAD is requested explicitly" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib')
)
downloader = Downloader.for_pod(@pod)
downloader.cache_path.rmtree if downloader.cache_path.exist?
downloader.expects(:create_cache).once
downloader.stubs(:clone)
downloader.download_head
end
it "removes the oldest repo if the caches is too big" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'fd56054'
)
original_chace_size = Downloader::Git::MAX_CACHE_SIZE
Downloader::Git.__send__(:remove_const,'MAX_CACHE_SIZE')
Downloader::Git::MAX_CACHE_SIZE = 0
downloader = Downloader.for_pod(@pod)
downloader.stubs(:cache_dir).returns(temporary_directory)
downloader.download
downloader.cache_path.should.not.exist?
Downloader::Git.__send__(:remove_const,'MAX_CACHE_SIZE')
Downloader::Git::MAX_CACHE_SIZE = original_chace_size
end
xit "raises if it can't find the url" do
@pod.top_specification.stubs(:source).returns(
:git => 'find_me_if_you_can'
)
downloader = Downloader.for_pod(@pod)
lambda { downloader.download }.should.raise Informative
end
it "raises if it can't find a commit" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'aaaaaa'
)
downloader = Downloader.for_pod(@pod)
lambda { downloader.download }.should.raise Informative
end
it "raises if it can't find a tag" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :tag => 'aaaaaa'
)
downloader = Downloader.for_pod(@pod)
lambda { downloader.download }.should.raise Informative
end
it "does not raise if it can find the reference" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'fd56054'
)
downloader = Downloader.for_pod(@pod)
lambda { downloader.download }.should.not.raise
end
it "returns the cache directory as the clone url" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'fd56054'
)
downloader = Downloader.for_pod(@pod)
downloader.clone_url.to_s.should.match /Library\/Caches\/CocoaPods\/Git/
end
it "updates the cache if the HEAD is requested" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib')
)
downloader = Downloader.for_pod(@pod)
downloader.expects(:update_cache).once
downloader.download
end
it "updates the cache if the ref is not available" do
# create the origin repo and the cache
tmp_repo_path = temporary_directory + 'banana-lib-source'
`git clone #{fixture('banana-lib')} #{tmp_repo_path}`
@pod.top_specification.stubs(:source).returns(
:git => tmp_repo_path, :commit => 'fd56054'
)
downloader = Downloader.for_pod(@pod)
downloader.download
# make a new commit in the origin
commit = ''
Dir.chdir(tmp_repo_path) do
`touch test.txt`
`git add test.txt`
`git commit -m 'test'`
commit = `git rev-parse HEAD`.chomp
end
# require the new commit
pod = LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), temporary_sandbox, Platform.ios)
pod.top_specification.stubs(:source).returns(
:git => tmp_repo_path, :commit => commit
)
downloader = Downloader.for_pod(pod)
downloader.download
(pod.root + 'test.txt').should.exist?
end
it "doesn't update the cache if the ref is available" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :commit => 'fd56054'
)
downloader = Downloader.for_pod(@pod)
downloader.download
downloader.expects(:update_cache).never
downloader.download
end
end
describe "for GitHub repositories, with :download_only set to true" do
extend SpecHelper::TemporaryDirectory
it "downloads HEAD with no other options specified" do
@pod.top_specification.stubs(:source).returns(
:git => "git://github.com/lukeredpath/libPusher.git", :download_only => true
)
downloader = Downloader.for_pod(@pod)
VCR.use_cassette('tarballs', :record => :new_episodes) { downloader.download }
# deliberately keep this assertion as loose as possible for now
(@pod.root + 'README.md').readlines[0].should =~ /libPusher/
end
it "downloads a specific tag when specified" do
@pod.top_specification.stubs(:source).returns(
:git => "git://github.com/lukeredpath/libPusher.git", :tag => 'v1.1', :download_only => true
)
downloader = Downloader.for_pod(@pod)
VCR.use_cassette('tarballs', :record => :new_episodes) { downloader.download }
# deliberately keep this assertion as loose as possible for now
(@pod.root + 'libPusher.podspec').readlines.grep(/1.1/).should.not.be.empty
end
it "downloads a specific branch when specified" do
@pod.top_specification.stubs(:source).returns(
:git => "git://github.com/lukeredpath/libPusher.git", :branch => 'gh-pages', :download_only => true
)
downloader = Downloader.for_pod(@pod)
VCR.use_cassette('tarballs', :record => :new_episodes) { downloader.download }
# deliberately keep this assertion as loose as possible for now
(@pod.root + 'index.html').readlines.grep(/libPusher Documentation/).should.not.be.empty
end
it "downloads a specific commit when specified" do
@pod.top_specification.stubs(:source).returns(
:git => "git://github.com/lukeredpath/libPusher.git", :commit => 'eca89998d5', :download_only => true
)
downloader = Downloader.for_pod(@pod)
VCR.use_cassette('tarballs', :record => :new_episodes) { downloader.download }
# deliberately keep this assertion as loose as possible for now
(@pod.root + 'README.md').readlines[0].should =~ /PusherTouch/
end
end
describe "for Mercurial" do describe "for Mercurial" do
it "check's out a specific revision" do it "check's out a specific revision" do
@pod.top_specification.stubs(:source).returns( @pod.top_specification.stubs(:source).returns(
......
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