Commit c9dd6934 authored by Fabio Pelosin's avatar Fabio Pelosin

[Downloader] raise when importan commands fail.

parent 139e6e48
...@@ -25,7 +25,7 @@ module Pod ...@@ -25,7 +25,7 @@ module Pod
download_head download_head
end end
Dir.chdir(target_path) { git "submodule update --init" } if options[:submodules] Dir.chdir(target_path) { git! "submodule update --init" } if options[:submodules]
prune_cache prune_cache
end end
...@@ -33,7 +33,7 @@ module Pod ...@@ -33,7 +33,7 @@ module Pod
puts "-> Creating cache git repo (#{cache_path})" if config.verbose? puts "-> 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
git %Q|clone "#{url}" "#{cache_path}"| clone(url, cache_path)
end end
def prune_cache def prune_cache
...@@ -76,9 +76,9 @@ module Pod ...@@ -76,9 +76,9 @@ module Pod
def update_cache def update_cache
puts "-> Updating cache git repo (#{cache_path})" if config.verbose? puts "-> Updating cache git repo (#{cache_path})" if config.verbose?
Dir.chdir(cache_path) do Dir.chdir(cache_path) do
git "reset --hard HEAD" git! "reset --hard HEAD"
git "clean -d -x -f" git! "clean -d -x -f"
git "pull" git! "pull"
end end
end end
...@@ -106,38 +106,44 @@ module Pod ...@@ -106,38 +106,44 @@ module Pod
else else
create_cache create_cache
end end
git %Q|clone "#{clone_url}" "#{target_path}"|
clone(clone_url, target_path)
Dir.chdir(target_path) { git! "submodule update --init" } if options[:submodules]
end end
def download_tag def download_tag
ensure_ref_exists(options[: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}'"
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"
end end
end end
def download_commit def download_commit
ensure_ref_exists(options[:commit]) ensure_ref_exists(options[:commit])
git %Q|clone "#{clone_url}" "#{target_path}"| 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
end end
def download_branch def download_branch
ensure_remote_branch_exists(options[:branch]) ensure_remote_branch_exists(options[:branch])
git %Q|clone "#{clone_url}" "#{target_path}"| clone(clone_url, target_path)
Dir.chdir(target_path) do Dir.chdir(target_path) do
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
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
def clone(from, to)
git! %Q|clone "#{from}" "#{to}"|
end
end end
class GitHub < Git class GitHub < Git
......
...@@ -52,17 +52,17 @@ module Pod ...@@ -52,17 +52,17 @@ module Pod
end end
def download_file(full_filename) def download_file(full_filename)
curl "-L -o '#{full_filename}' '#{url}'" curl! "-L -o '#{full_filename}' '#{url}'"
end end
def extract_with_type(full_filename, type=:zip) def extract_with_type(full_filename, type=:zip)
case type case type
when :zip when :zip
unzip "'#{full_filename}' -d '#{target_path}'" unzip! "'#{full_filename}' -d '#{target_path}'"
when :tgz when :tgz
tar "xfz '#{full_filename}' -C '#{target_path}'" tar! "xfz '#{full_filename}' -C '#{target_path}'"
when :tar when :tar
tar "xf '#{full_filename}' -C '#{target_path}'" tar! "xf '#{full_filename}' -C '#{target_path}'"
else else
raise UnsupportedFileTypeError.new "Unsupported file type: #{type}" raise UnsupportedFileTypeError.new "Unsupported file type: #{type}"
end end
......
...@@ -12,11 +12,11 @@ module Pod ...@@ -12,11 +12,11 @@ module Pod
end end
def download_head def download_head
hg "clone \"#{url}\" \"#{target_path}\"" hg! "clone \"#{url}\" \"#{target_path}\""
end end
def download_revision def download_revision
hg "clone \"#{url}\" --rev '#{options[:revision]}' \"#{target_path}\"" hg! "clone \"#{url}\" --rev '#{options[:revision]}' \"#{target_path}\""
end end
end end
end end
......
...@@ -4,11 +4,11 @@ module Pod ...@@ -4,11 +4,11 @@ module Pod
executable :svn executable :svn
def download def download
svn %|checkout "#{reference_url}" "#{target_path}"| svn! %|checkout "#{reference_url}" "#{target_path}"|
end end
def download_head def download_head
svn %|checkout "#{trunk_url}" "#{target_path}"| svn! %|checkout "#{trunk_url}" "#{target_path}"|
end end
def reference_url def reference_url
......
...@@ -20,7 +20,7 @@ module Pod ...@@ -20,7 +20,7 @@ module Pod
def executable(name) def executable(name)
bin = `which #{name}`.strip bin = `which #{name}`.strip
define_method(name) do |command| define_method(name) do |command, should_raise = false|
if bin.empty? if bin.empty?
raise Informative, "Unable to locate the executable `#{name}'" raise Informative, "Unable to locate the executable `#{name}'"
end end
...@@ -33,9 +33,22 @@ module Pod ...@@ -33,9 +33,22 @@ module Pod
end end
status = Open4.spawn(full_command, :stdout => stdout, :stderr => stderr, :status => true) status = Open4.spawn(full_command, :stdout => stdout, :stderr => stderr, :status => true)
# TODO not sure that we should be silent in case of a failure. # TODO not sure that we should be silent in case of a failure.
puts (Config.instance.verbose? ? ' ' : '') << "[!] Failed: #{full_command}".red unless status.success? || Config.instance.silent?
stdout.join("\n") + stderr.join("\n") # TODO will this suffice? output = stdout.join("\n") + stderr.join("\n") # TODO will this suffice?
unless status.success?
if should_raise
raise Informative, "#{name} #{command}\n\n#{output}"
else
puts (Config.instance.verbose? ? ' ' : '') << "[!] Failed: #{full_command}".red unless Config.instance.silent?
end
end
output
end end
define_method(name.to_s + "!") do |command|
send(name, command, true)
end
private name private name
end end
end end
......
...@@ -108,7 +108,7 @@ module Pod ...@@ -108,7 +108,7 @@ module Pod
Downloader::Git::MAX_CACHE_SIZE = original_chace_size Downloader::Git::MAX_CACHE_SIZE = original_chace_size
end end
xit "raises if it can't find the url" do it "raises if it can't find the url" do
@pod.top_specification.stubs(:source).returns( @pod.top_specification.stubs(:source).returns(
:git => 'find_me_if_you_can' :git => 'find_me_if_you_can'
) )
...@@ -193,6 +193,7 @@ module Pod ...@@ -193,6 +193,7 @@ module Pod
) )
downloader = Downloader.for_pod(@pod) downloader = Downloader.for_pod(@pod)
downloader.download downloader.download
@pod.root.rmtree
downloader.expects(:update_cache).never downloader.expects(:update_cache).never
downloader.download downloader.download
end end
......
...@@ -15,6 +15,14 @@ module Pod ...@@ -15,6 +15,14 @@ module Pod
downloader.download downloader.download
(@pod.root + 'README').read.strip.should == 'first commit' (@pod.root + 'README').read.strip.should == 'first commit'
end end
it "raises if it fails to download" do
@pod.top_specification.stubs(:source).returns(
:hg => "find me if you can", :revision => '46198bb3af96'
)
downloader = Downloader.for_pod(@pod)
lambda { downloader.download }.should.raise Informative
end
end end
describe "for Subversion" do describe "for Subversion" do
...@@ -45,6 +53,14 @@ module Pod ...@@ -45,6 +53,14 @@ module Pod
downloader.download_head downloader.download_head
(@pod.root + 'README').read.strip.should == 'unintersting' (@pod.root + 'README').read.strip.should == 'unintersting'
end end
it "raises if it fails to download" do
@pod.top_specification.stubs(:source).returns(
:svn => "find me if you can", :revision => '1'
)
downloader = Downloader.for_pod(@pod)
lambda { downloader.download }.should.raise Informative
end
end end
...@@ -61,6 +77,14 @@ module Pod ...@@ -61,6 +77,14 @@ module Pod
(@pod.root + 'GoogleAdMobSearchAdsSDK/GADSearchRequest.h').should.exist (@pod.root + 'GoogleAdMobSearchAdsSDK/GADSearchRequest.h').should.exist
(@pod.root + 'GoogleAdMobSearchAdsSDK/GADSearchRequest.h').read.strip.should =~ /Google Search Ads iOS SDK/ (@pod.root + 'GoogleAdMobSearchAdsSDK/GADSearchRequest.h').read.strip.should =~ /Google Search Ads iOS SDK/
end end
it "raises if it fails to download" do
@pod.top_specification.stubs(:source).returns(
:http => 'find me if you can.zip'
)
downloader = Downloader.for_pod(@pod)
lambda { downloader.download }.should.raise Informative
end
end end
end end
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