Commit cfbdef54 authored by Fabio Pelosin's avatar Fabio Pelosin

Restored Pod::Downloader::Git::GitHub.

parent ac233ae8
...@@ -3,6 +3,7 @@ require 'uri' ...@@ -3,6 +3,7 @@ require 'uri'
module Pod module Pod
class Downloader class Downloader
autoload :Git, 'cocoapods/downloader/git' autoload :Git, 'cocoapods/downloader/git'
autoload :GitHub, 'cocoapods/downloader/git'
autoload :Mercurial, 'cocoapods/downloader/mercurial' autoload :Mercurial, 'cocoapods/downloader/mercurial'
autoload :Subversion, 'cocoapods/downloader/subversion' autoload :Subversion, 'cocoapods/downloader/subversion'
autoload :Http, 'cocoapods/downloader/http' autoload :Http, 'cocoapods/downloader/http'
...@@ -31,7 +32,11 @@ module Pod ...@@ -31,7 +32,11 @@ module Pod
def self.for_target(target_path, options) def self.for_target(target_path, options)
options = options.dup options = options.dup
if url = options.delete(:git) if url = options.delete(:git)
if url.to_s =~ /github.com/
GitHub.new(target_path, url, options)
else
Git.new(target_path, url, options) Git.new(target_path, url, options)
end
elsif url = options.delete(:hg) elsif url = options.delete(:hg)
Mercurial.new(target_path, url, options) Mercurial.new(target_path, url, options)
elsif url = options.delete(:svn) elsif url = options.delete(:svn)
......
...@@ -103,5 +103,54 @@ module Pod ...@@ -103,5 +103,54 @@ module Pod
(target_path + '.git').rmtree (target_path + '.git').rmtree
end end
end end
class GitHub < Git
def download_head
download_only? ? download_and_extract_tarball('master') : super
end
def download_tag
super unless download_only?
download_only? ? download_and_extract_tarball(options[:tag]) : super
end
def download_commit
super unless download_only?
download_only? ? download_and_extract_tarball(options[:commit]) : super
end
def clean
if download_only?
FileUtils.rm_f(tmp_path)
else
super
end
end
def tarball_url_for(id)
original_url, username, reponame = *(url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/).to_a)
"https://github.com/#{username}/#{reponame}/tarball/#{id}"
end
def tmp_path
target_path + "tarball.tar.gz"
end
private
def download_only?
@options[:download_only]
end
def download_and_extract_tarball(id)
File.open(tmp_path, "w+") do |tmpfile|
open tarball_url_for(id) do |archive|
tmpfile.write Zlib::GzipReader.new(archive).read
end
system "tar xf #{tmpfile.path} -C #{target_path} --strip-components 1"
end
end
end
end end
end end
...@@ -19,4 +19,43 @@ describe "Pod::Downloader" do ...@@ -19,4 +19,43 @@ describe "Pod::Downloader" do
downloader.url.should == 'http://banana-corp.local/banana-lib.git' downloader.url.should == 'http://banana-corp.local/banana-lib.git'
downloader.options.should == { :tag => 'v1.0' } downloader.options.should == { :tag => 'v1.0' }
end end
it 'returns a github downloader when the :git URL is on github' do
pod = Pod::LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), temporary_sandbox, Pod::Platform.ios)
pod.specification.stubs(:source).returns(:git => "git://github.com/CocoaPods/CocoaPods")
downloader = Pod::Downloader.for_pod(pod)
downloader.should.be.instance_of Pod::Downloader::GitHub
end
end
describe Pod::Downloader::GitHub do
it 'can convert public HTTP repository URLs to the tarball URL' do
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:git => "https://github.com/CocoaPods/CocoaPods.git"
))
downloader.tarball_url_for('master').should == "https://github.com/CocoaPods/CocoaPods/tarball/master"
end
it 'can convert private HTTP repository URLs to the tarball URL' do
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:git => "https://lukeredpath@github.com/CocoaPods/CocoaPods.git"
))
downloader.tarball_url_for('master').should == "https://github.com/CocoaPods/CocoaPods/tarball/master"
end
it 'can convert private SSH repository URLs to the tarball URL' do
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:git => "git@github.com:CocoaPods/CocoaPods.git"
))
downloader.tarball_url_for('master').should == "https://github.com/CocoaPods/CocoaPods/tarball/master"
end
it 'can convert public git protocol repository URLs to the tarball URL' do
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:git => "git://github.com/CocoaPods/CocoaPods.git"
))
downloader.tarball_url_for('master').should == "https://github.com/CocoaPods/CocoaPods/tarball/master"
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