Commit 39b687ee authored by Eloy Duran's avatar Eloy Duran

Add Mercurial downloader. Closes #82.

parent 44a60c51
...@@ -13,3 +13,4 @@ examples/**/Pods ...@@ -13,3 +13,4 @@ examples/**/Pods
spec/fixtures/banana-lib spec/fixtures/banana-lib
pod pod
/concatenated.* /concatenated.*
spec/fixtures/mercurial-repo/.hg/cache
\ No newline at end of file
module Pod module Pod
class Downloader class Downloader
autoload :Git, 'cocoapods/downloader/git'
autoload :Mercurial, 'cocoapods/downloader/mercurial'
extend Executable extend Executable
def self.for_source(pod_root, source) def self.for_source(pod_root, source)
...@@ -24,75 +27,5 @@ module Pod ...@@ -24,75 +27,5 @@ module Pod
path.rmtree path.rmtree
end if clean_paths end if clean_paths
end end
class Git < Downloader
executable :git
def download
@pod_root.dirname.mkpath
if @options[:tag]
download_tag
elsif @options[:commit]
download_commit
else
download_head
end
end
def download_head
git "clone '#{@url}' '#{@pod_root}'"
end
def download_tag
@pod_root.mkpath
Dir.chdir(@pod_root) do
git "init"
git "remote add origin '#{@url}'"
git "fetch origin tags/#{@options[:tag]}"
git "reset --hard FETCH_HEAD"
git "checkout -b activated-pod-commit"
end
end
def download_commit
git "clone '#{@url}' '#{@pod_root}'"
Dir.chdir(@pod_root) do
git "checkout -b activated-pod-commit #{@options[:commit]}"
end
end
def clean(clean_paths = [])
super
(@pod_root + '.git').rmtree
end
end
class Mercurial < Downloader
extend Executable
executable :hg
def download
@pod_root.dirname.mkpath
if @options[:revision]
download_revision
else
download_head
end
end
def download_head
hg "clone '#{@url}' '#{@pod_root}'"
end
def download_revision
hg "clone '#{@url}' --rev '#{@options[:revision]}' '#{@pod_root}'"
end
def clean(clean_paths = [])
super
#(@pod_root + '.git').rmtree
puts "TODO clean mercurial!"
end
end
end end
end end
module Pod
class Downloader
class Git < Downloader
executable :git
def download
@pod_root.dirname.mkpath
if @options[:tag]
download_tag
elsif @options[:commit]
download_commit
else
download_head
end
end
def download_head
git "clone '#{@url}' '#{@pod_root}'"
end
def download_tag
@pod_root.mkpath
Dir.chdir(@pod_root) do
git "init"
git "remote add origin '#{@url}'"
git "fetch origin tags/#{@options[:tag]}"
git "reset --hard FETCH_HEAD"
git "checkout -b activated-pod-commit"
end
end
def download_commit
git "clone '#{@url}' '#{@pod_root}'"
Dir.chdir(@pod_root) do
git "checkout -b activated-pod-commit #{@options[:commit]}"
end
end
def clean(clean_paths = [])
super
(@pod_root + '.git').rmtree
end
end
end
end
module Pod
class Downloader
class Mercurial < Downloader
executable :hg
def download
@pod_root.dirname.mkpath
if @options[:revision]
download_revision
else
download_head
end
end
def download_head
hg "clone '#{@url}' '#{@pod_root}'"
end
def download_revision
hg "clone '#{@url}' --rev '#{@options[:revision]}' '#{@pod_root}'"
end
def clean(clean_paths = [])
super
(@pod_root + '.hg').rmtree
end
end
end
end
require File.expand_path('../../spec_helper', __FILE__) require File.expand_path('../../spec_helper', __FILE__)
describe "Pod::Downloader" do describe "Pod::Downloader" do
extend SpecHelper::TemporaryDirectory
before do before do
@dir = temporary_directory + 'banana-lib' @dir = temporary_directory + 'banana-lib'
end end
it "check's out a specific commit" do describe "for Git" do
downloader = Pod::Downloader.for_source(@dir, extend SpecHelper::TemporaryDirectory
:git => fixture('banana-lib'), :commit => '02467b074d4dc9f6a75b8cd3ab80d9bf37887b01'
)
downloader.download
(@dir + 'README').read.strip.should == 'first commit'
end
it "check's out a specific tag" do it "check's out a specific commit" do
downloader = Pod::Downloader.for_source(@dir, downloader = Pod::Downloader.for_source(@dir,
:git => fixture('banana-lib'), :tag => 'v1.0' :git => fixture('banana-lib'), :commit => '02467b074d4dc9f6a75b8cd3ab80d9bf37887b01'
) )
downloader.download downloader.download
(@dir + 'README').read.strip.should == 'v1.0' (@dir + 'README').read.strip.should == 'first commit'
end end
it "check's out a specific tag" do
downloader = Pod::Downloader.for_source(@dir,
:git => fixture('banana-lib'), :tag => 'v1.0'
)
downloader.download
(@dir + 'README').read.strip.should == 'v1.0'
end
it "removes the .git directory" do
downloader = Pod::Downloader.for_source(@dir,
:git => fixture('banana-lib'), :tag => 'v1.0'
)
downloader.download
downloader.clean
(@dir + '.git').should.not.exist
end
it "removes the .git directory" do it "removes the clean_paths files and directories" do
downloader = Pod::Downloader.for_source(@dir, downloader = Pod::Downloader.for_source(@dir,
:git => fixture('banana-lib'), :tag => 'v1.0' :git => fixture('banana-lib'), :tag => 'v1.0'
) )
downloader.download downloader.download
downloader.clean downloader.clean([@dir + 'README'])
(@dir + '.git').should.not.exist (@dir + 'README').should.not.exist
end
end end
it "removes the clean_paths files and directories" do describe "for Mercurial" do
downloader = Pod::Downloader.for_source(@dir, extend SpecHelper::TemporaryDirectory
:git => fixture('banana-lib'), :tag => 'v1.0'
) it "check's out a specific revision" do
downloader.download downloader = Pod::Downloader.for_source(@dir,
downloader.clean([@dir + 'README']) :hg => fixture('mercurial-repo'), :revision => '46198bb3af96'
(@dir + 'README').should.not.exist )
downloader.download
(@dir + 'README').read.strip.should == 'first commit'
end
it "removes the .hg directory" do
downloader = Pod::Downloader.for_source(@dir,
:hg => fixture('mercurial-repo'), :revision => '46198bb3af96'
)
downloader.download
downloader.clean
(@dir + '.hg').should.not.exist
end
it "removes the clean_paths files and directories" do
downloader = Pod::Downloader.for_source(@dir,
:hg => fixture('mercurial-repo'), :revision => '46198bb3af96'
)
downloader.download
downloader.clean([@dir + 'README'])
(@dir + 'README').should.not.exist
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