Commit 99819b9f authored by Eloy Duran's avatar Eloy Duran

Fetch a pod's source with git.

parent 30d8b91e
...@@ -2,6 +2,7 @@ module Pod ...@@ -2,6 +2,7 @@ module Pod
autoload :Command, 'cocoa_pods/command' autoload :Command, 'cocoa_pods/command'
autoload :Config, 'cocoa_pods/config' autoload :Config, 'cocoa_pods/config'
autoload :Dependency, 'cocoa_pods/dependency' autoload :Dependency, 'cocoa_pods/dependency'
autoload :Downloader, 'cocoa_pods/downloader'
autoload :Resolver, 'cocoa_pods/resolver' autoload :Resolver, 'cocoa_pods/resolver'
autoload :Source, 'cocoa_pods/source' autoload :Source, 'cocoa_pods/source'
autoload :Spec, 'cocoa_pods/specification' autoload :Spec, 'cocoa_pods/specification'
......
...@@ -3,13 +3,16 @@ module Pod ...@@ -3,13 +3,16 @@ module Pod
class Install < Command class Install < Command
def run def run
if spec = Specification.from_podfile(podfile) if spec = Specification.from_podfile(podfile)
p spec spec.install_dependent_specifications!(pods_root)
Resolver.new(spec).resolve
else else
$stderr.puts "No Podfile found in current working directory." $stderr.puts "No Podfile found in current working directory."
end end
end end
def pods_root
Pathname.new(Dir.pwd) + 'Pods'
end
def podfile def podfile
File.join(Dir.pwd, 'Podfile') File.join(Dir.pwd, 'Podfile')
end end
......
module Pod
class Downloader
def self.for_source(source)
options = source.dup
if url = options.delete(:git)
Git.new(url, options)
else
raise "Unsupported download strategy `#{source.inspect}'."
end
end
def initialize(url, options)
@url, @options = url, options
end
class Git < Downloader
require 'rubygems'
require 'executioner'
include Executioner
# TODO make Executioner:
# * not raise when there's output to either stdout/stderr, but check exit status
# * sync output
executable :git
def download_to(pod_root)
checkout = pod_root + 'source'
if tag = @options[:tag]
checkout.mkdir
Dir.chdir(checkout) do
git "init"
git "remote add origin '#{@url}'"
git "fetch origin tags/#{tag} 2>&1"
git "reset --hard FETCH_HEAD"
git "checkout -b activated-pod-commit 2>&1"
end
elsif commit = @options[:commit]
git "clone '#{@url}' '#{checkout}'"
Dir.chdir(checkout) do
git "checkout -b activated-pod-commit #{commit} 2>&1"
end
else
raise "Either a tag or a commit has to be specified."
end
end
end
end
end
...@@ -7,8 +7,7 @@ module Pod ...@@ -7,8 +7,7 @@ module Pod
def resolve def resolve
@sets = [] @sets = []
find_dependency_sets(@specification) find_dependency_sets(@specification)
specs = @sets.map(&:podspec) @sets.map(&:podspec)
p specs
end end
def find_dependency_sets(specification) def find_dependency_sets(specification)
......
...@@ -63,7 +63,7 @@ module Pod ...@@ -63,7 +63,7 @@ module Pod
def part_of(name, *version_requirements) def part_of(name, *version_requirements)
#@part_of = Dependency.new(name, *version_requirements) #@part_of = Dependency.new(name, *version_requirements)
dependency(name, *version_requirements) @part_of = dependency(name, *version_requirements)
end end
def source_files(*patterns) def source_files(*patterns)
...@@ -76,11 +76,49 @@ module Pod ...@@ -76,11 +76,49 @@ module Pod
attr_reader :dependencies attr_reader :dependencies
def dependency(name, *version_requirements) def dependency(name, *version_requirements)
@dependencies << Dependency.new(name, *version_requirements) dep = Dependency.new(name, *version_requirements)
@dependencies << dep
dep
end end
# Not attributes # Not attributes
def resolved_dependent_specifications
@resolved_dependent_specifications ||= Resolver.new(self).resolve
end
def install_dependent_specifications!(root)
resolved_dependent_specifications.each do |spec|
install_spec = spec
if part_of_spec_dep = spec.read(:part_of)
install_spec = resolved_dependent_specifications.find { |s| s.read(:name) == part_of_spec_dep.name }
puts "-- Installing: #{install_spec} for #{spec}"
else
puts "-- Installing: #{install_spec}"
end
install_spec.install!(root)
end
end
# User can override this for custom installation
def install!(pods_root)
require 'fileutils'
pods_root.mkpath
pod_root = pods_root + "#{@name}-#{@version}"
if pod_root.exist?
puts " Skipping, the pod already exists: #{pod_root}"
else
pod_root.mkdir
FileUtils.cp(@defined_in_file, pod_root)
download_to(pod_root)
end
end
# User can override this for custom downloading
def download_to(pod_root)
Downloader.for_source(@source).download_to(pod_root)
end
def from_podfile? def from_podfile?
@name.nil? && @version.nil? @name.nil? && @version.nil?
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