Commit 79fa28ac authored by Eloy Duran's avatar Eloy Duran

Clean up after downloading. In the case of git that means removing the .git dir from the clone.

parent 99819b9f
......@@ -3,7 +3,7 @@ module Pod
class Install < Command
def run
if spec = Specification.from_podfile(podfile)
spec.install_dependent_specifications!(pods_root)
spec.install_dependent_specifications!(pods_root, true)
else
$stderr.puts "No Podfile found in current working directory."
end
......
module Pod
class Downloader
def self.for_source(source)
def self.for_source(source, pod_root)
options = source.dup
if url = options.delete(:git)
Git.new(url, options)
Git.new(pod_root, url, options)
else
raise "Unsupported download strategy `#{source.inspect}'."
end
end
def initialize(url, options)
@url, @options = url, options
def initialize(pod_root, url, options)
@pod_root, @url, @options = pod_root, url, options
end
class Git < Downloader
......@@ -22,11 +22,14 @@ module Pod
# * sync output
executable :git
def download_to(pod_root)
checkout = pod_root + 'source'
def source_dir
@pod_root + 'source'
end
def download
if tag = @options[:tag]
checkout.mkdir
Dir.chdir(checkout) do
source_dir.mkdir
Dir.chdir(source_dir) do
git "init"
git "remote add origin '#{@url}'"
git "fetch origin tags/#{tag} 2>&1"
......@@ -34,14 +37,18 @@ module Pod
git "checkout -b activated-pod-commit 2>&1"
end
elsif commit = @options[:commit]
git "clone '#{@url}' '#{checkout}'"
Dir.chdir(checkout) do
git "clone '#{@url}' '#{source_dir}'"
Dir.chdir(source_dir) 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
def clean
(source_dir + '.git').rmtree
end
end
end
end
......@@ -87,7 +87,7 @@ module Pod
@resolved_dependent_specifications ||= Resolver.new(self).resolve
end
def install_dependent_specifications!(root)
def install_dependent_specifications!(root, clean)
resolved_dependent_specifications.each do |spec|
install_spec = spec
if part_of_spec_dep = spec.read(:part_of)
......@@ -96,12 +96,12 @@ module Pod
else
puts "-- Installing: #{install_spec}"
end
install_spec.install!(root)
install_spec.install!(root, clean)
end
end
# User can override this for custom installation
def install!(pods_root)
def install!(pods_root, clean)
require 'fileutils'
pods_root.mkpath
pod_root = pods_root + "#{@name}-#{@version}"
......@@ -110,13 +110,15 @@ module Pod
else
pod_root.mkdir
FileUtils.cp(@defined_in_file, pod_root)
download_to(pod_root)
download_to(pod_root, clean)
end
end
# User can override this for custom downloading
def download_to(pod_root)
Downloader.for_source(@source).download_to(pod_root)
def download_to(pod_root, clean)
downloader = Downloader.for_source(@source, pod_root)
downloader.download
downloader.clean if clean
end
def from_podfile?
......
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