Permalink
Browse files

Add Mercurial downloader. Closes #82.

  • Loading branch information...
1 parent 44a60c5 commit 39b687ee9d500c62545047662860b3bfed6d1346 @alloy alloy committed Nov 18, 2011
View
@@ -13,3 +13,4 @@ examples/**/Pods
spec/fixtures/banana-lib
pod
/concatenated.*
+spec/fixtures/mercurial-repo/.hg/cache
@@ -1,5 +1,8 @@
module Pod
class Downloader
+ autoload :Git, 'cocoapods/downloader/git'
+ autoload :Mercurial, 'cocoapods/downloader/mercurial'
+
extend Executable
def self.for_source(pod_root, source)
@@ -24,75 +27,5 @@ def clean(clean_paths = [])
path.rmtree
end if clean_paths
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
@@ -0,0 +1,46 @@
+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
+
@@ -0,0 +1,30 @@
+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
+
@@ -1,44 +1,78 @@
require File.expand_path('../../spec_helper', __FILE__)
describe "Pod::Downloader" do
- extend SpecHelper::TemporaryDirectory
-
before do
@dir = temporary_directory + 'banana-lib'
end
- it "check's out a specific commit" do
- downloader = Pod::Downloader.for_source(@dir,
- :git => fixture('banana-lib'), :commit => '02467b074d4dc9f6a75b8cd3ab80d9bf37887b01'
- )
- downloader.download
- (@dir + 'README').read.strip.should == 'first commit'
- end
+ describe "for Git" do
+ extend SpecHelper::TemporaryDirectory
- 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 "check's out a specific commit" do
+ downloader = Pod::Downloader.for_source(@dir,
+ :git => fixture('banana-lib'), :commit => '02467b074d4dc9f6a75b8cd3ab80d9bf37887b01'
+ )
+ downloader.download
+ (@dir + 'README').read.strip.should == 'first commit'
+ 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
- downloader = Pod::Downloader.for_source(@dir,
- :git => fixture('banana-lib'), :tag => 'v1.0'
- )
- downloader.download
- downloader.clean
- (@dir + '.git').should.not.exist
+ it "removes the clean_paths files and directories" do
+ downloader = Pod::Downloader.for_source(@dir,
+ :git => fixture('banana-lib'), :tag => 'v1.0'
+ )
+ downloader.download
+ downloader.clean([@dir + 'README'])
+ (@dir + 'README').should.not.exist
+ end
end
- it "removes the clean_paths files and directories" do
- downloader = Pod::Downloader.for_source(@dir,
- :git => fixture('banana-lib'), :tag => 'v1.0'
- )
- downloader.download
- downloader.clean([@dir + 'README'])
- (@dir + 'README').should.not.exist
+ describe "for Mercurial" do
+ extend SpecHelper::TemporaryDirectory
+
+ it "check's out a specific revision" do
+ downloader = Pod::Downloader.for_source(@dir,
+ :hg => fixture('mercurial-repo'), :revision => '46198bb3af96'
+ )
+ 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

0 comments on commit 39b687e

Please sign in to comment.