Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Downloader] raise when importan commands fail.

  • Loading branch information...
commit c9dd6934c43acbb91fd8869d93767dc76e831199 1 parent 139e6e4
@fabiopelosin fabiopelosin authored
View
40 lib/cocoapods/downloader/git.rb
@@ -25,7 +25,7 @@ def download
download_head
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
end
@@ -33,7 +33,7 @@ def create_cache
puts "-> Creating cache git repo (#{cache_path})" if config.verbose?
cache_path.rmtree if cache_path.exist?
cache_path.mkpath
- git %Q|clone "#{url}" "#{cache_path}"|
+ clone(url, cache_path)
end
def prune_cache
@@ -76,9 +76,9 @@ def caches_size
def update_cache
puts "-> 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"
+ git! "reset --hard HEAD"
+ git! "clean -d -x -f"
+ git! "pull"
end
end
@@ -106,38 +106,44 @@ def download_head
else
create_cache
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
def download_tag
ensure_ref_exists(options[:tag])
Dir.chdir(target_path) do
- git "init"
- git "remote add origin '#{clone_url}'"
- git "fetch origin tags/#{options[:tag]}"
- git "reset --hard FETCH_HEAD"
- git "checkout -b activated-pod-commit"
+ git! "init"
+ git! "remote add origin '#{clone_url}'"
+ git! "fetch origin tags/#{options[:tag]}"
+ git! "reset --hard FETCH_HEAD"
+ git! "checkout -b activated-pod-commit"
end
end
def download_commit
ensure_ref_exists(options[:commit])
- git %Q|clone "#{clone_url}" "#{target_path}"|
+ clone(clone_url, target_path)
Dir.chdir(target_path) do
- git "checkout -b activated-pod-commit #{options[:commit]}"
+ git! "checkout -b activated-pod-commit #{options[:commit]}"
end
end
def download_branch
ensure_remote_branch_exists(options[:branch])
- git %Q|clone "#{clone_url}" "#{target_path}"|
+ clone(clone_url, target_path)
Dir.chdir(target_path) do
- git "remote add upstream '#{@url}'" # we need to add the original url, not the cache url
- git "fetch -q upstream" # refresh the branches
- git "checkout --track -b activated-pod-commit upstream/#{options[:branch]}" # create a new tracking branch
+ git! "remote add upstream '#{@url}'" # we need to add the original url, not the cache url
+ git! "fetch -q upstream" # refresh the branches
+ 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?
end
end
+
+ def clone(from, to)
+ git! %Q|clone "#{from}" "#{to}"|
+ end
end
class GitHub < Git
View
8 lib/cocoapods/downloader/http.rb
@@ -52,17 +52,17 @@ def filename_with_type(type=:zip)
end
def download_file(full_filename)
- curl "-L -o '#{full_filename}' '#{url}'"
+ curl! "-L -o '#{full_filename}' '#{url}'"
end
def extract_with_type(full_filename, type=:zip)
case type
when :zip
- unzip "'#{full_filename}' -d '#{target_path}'"
+ unzip! "'#{full_filename}' -d '#{target_path}'"
when :tgz
- tar "xfz '#{full_filename}' -C '#{target_path}'"
+ tar! "xfz '#{full_filename}' -C '#{target_path}'"
when :tar
- tar "xf '#{full_filename}' -C '#{target_path}'"
+ tar! "xf '#{full_filename}' -C '#{target_path}'"
else
raise UnsupportedFileTypeError.new "Unsupported file type: #{type}"
end
View
4 lib/cocoapods/downloader/mercurial.rb
@@ -12,11 +12,11 @@ def download
end
def download_head
- hg "clone \"#{url}\" \"#{target_path}\""
+ hg! "clone \"#{url}\" \"#{target_path}\""
end
def download_revision
- hg "clone \"#{url}\" --rev '#{options[:revision]}' \"#{target_path}\""
+ hg! "clone \"#{url}\" --rev '#{options[:revision]}' \"#{target_path}\""
end
end
end
View
4 lib/cocoapods/downloader/subversion.rb
@@ -4,11 +4,11 @@ class Subversion < Downloader
executable :svn
def download
- svn %|checkout "#{reference_url}" "#{target_path}"|
+ svn! %|checkout "#{reference_url}" "#{target_path}"|
end
def download_head
- svn %|checkout "#{trunk_url}" "#{target_path}"|
+ svn! %|checkout "#{trunk_url}" "#{target_path}"|
end
def reference_url
View
19 lib/cocoapods/executable.rb
@@ -20,7 +20,7 @@ def <<(value)
def executable(name)
bin = `which #{name}`.strip
- define_method(name) do |command|
+ define_method(name) do |command, should_raise = false|
if bin.empty?
raise Informative, "Unable to locate the executable `#{name}'"
end
@@ -33,9 +33,22 @@ def executable(name)
end
status = Open4.spawn(full_command, :stdout => stdout, :stderr => stderr, :status => true)
# 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
+
+ define_method(name.to_s + "!") do |command|
+ send(name, command, true)
+ end
+
private name
end
end
View
3  spec/functional/downloader/git_spec.rb
@@ -108,7 +108,7 @@ module Pod
Downloader::Git::MAX_CACHE_SIZE = original_chace_size
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(
:git => 'find_me_if_you_can'
)
@@ -193,6 +193,7 @@ module Pod
)
downloader = Downloader.for_pod(@pod)
downloader.download
+ @pod.root.rmtree
downloader.expects(:update_cache).never
downloader.download
end
View
24 spec/functional/downloader_spec.rb
@@ -15,6 +15,14 @@ module Pod
downloader.download
(@pod.root + 'README').read.strip.should == 'first commit'
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
describe "for Subversion" do
@@ -45,6 +53,14 @@ module Pod
downloader.download_head
(@pod.root + 'README').read.strip.should == 'unintersting'
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
@@ -61,6 +77,14 @@ module Pod
(@pod.root + 'GoogleAdMobSearchAdsSDK/GADSearchRequest.h').should.exist
(@pod.root + 'GoogleAdMobSearchAdsSDK/GADSearchRequest.h').read.strip.should =~ /Google Search Ads iOS SDK/
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
Please sign in to comment.
Something went wrong with that request. Please try again.