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
autoload :Command, 'cocoa_pods/command'
autoload :Config, 'cocoa_pods/config'
autoload :Dependency, 'cocoa_pods/dependency'
autoload :Downloader, 'cocoa_pods/downloader'
autoload :Resolver, 'cocoa_pods/resolver'
autoload :Source, 'cocoa_pods/source'
autoload :Spec, 'cocoa_pods/specification'
......
......@@ -3,13 +3,16 @@ module Pod
class Install < Command
def run
if spec = Specification.from_podfile(podfile)
p spec
Resolver.new(spec).resolve
spec.install_dependent_specifications!(pods_root)
else
$stderr.puts "No Podfile found in current working directory."
end
end
def pods_root
Pathname.new(Dir.pwd) + 'Pods'
end
def podfile
File.join(Dir.pwd, 'Podfile')
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
def resolve
@sets = []
find_dependency_sets(@specification)
specs = @sets.map(&:podspec)
p specs
@sets.map(&:podspec)
end
def find_dependency_sets(specification)
......
......@@ -63,7 +63,7 @@ module Pod
def part_of(name, *version_requirements)
#@part_of = Dependency.new(name, *version_requirements)
dependency(name, *version_requirements)
@part_of = dependency(name, *version_requirements)
end
def source_files(*patterns)
......@@ -76,11 +76,49 @@ module Pod
attr_reader :dependencies
def dependency(name, *version_requirements)
@dependencies << Dependency.new(name, *version_requirements)
dep = Dependency.new(name, *version_requirements)
@dependencies << dep
dep
end
# 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?
@name.nil? && @version.nil?
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