Commit 6ef994b5 authored by Fabio Pelosin's avatar Fabio Pelosin

Merge pull request #1233 from ianyh/cocoapods-directory

Restructure .cocoapods directory to contain repos as a subdirectory.
parents 81d75616 539bc533
......@@ -8,6 +8,9 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
* Added license information to `podfile-info` subcommand.
[#1219](https://github.com/CocoaPods/CocoaPods/issues/1219)
* Restructured .cocoapods folder to contain repos in a subdirectory.
[#1150](https://github.com/CocoaPods/CocoaPods/issues/1150)
###### Bug Fixes
......
......@@ -214,7 +214,7 @@ namespace :spec do
title 'Running the specs'
sh "bundle exec bacon #{specs('**')}"
unless Pathname.new(ENV['HOME']+'/.cocoapods/master').exist?
unless Pathname.new(ENV['HOME']+'/.cocoapods/repos/master').exist?
title 'Ensuring specs repo is up to date'
sh "./bin/pod setup"
end
......
......@@ -9,8 +9,8 @@ module Pod
self.description = <<-DESC
Validates NAME.podspec or `*.podspec' in the current working dir, creates
a directory and version folder for the pod in the local copy of
REPO (~/.cocoapods/[REPO]), copies the podspec file into the version directory,
and finally it pushes REPO to its remote.
REPO (~/.cocoapods/repos/[REPO]), copies the podspec file into the version
directory, and finally it pushes REPO to its remote.
DESC
self.arguments = 'REPO [NAME.podspec]'
......
......@@ -13,7 +13,7 @@ module Pod
self.summary = 'Add a spec repo.'
self.description = <<-DESC
Clones `URL` in the local spec-repos directory at `~/.cocoapods`. The
Clones `URL` in the local spec-repos directory at `~/.cocoapods/repos/`. The
remote can later be referred to by `NAME`.
DESC
......@@ -48,7 +48,7 @@ module Pod
self.description = <<-DESC
Updates the local clone of the spec-repo `NAME`. If `NAME` is omitted
this will update all spec-repos in `~/.cocoapods`.
this will update all spec-repos in `~/.cocoapods/repos`.
DESC
self.arguments = '[NAME]'
......
require 'fileutils'
module Pod
class Command
class Setup < Command
......@@ -30,6 +32,8 @@ module Pod
set_master_repo_url
set_master_repo_branch
update_master_repo
elsif old_master_repo_dir.exist?
migrate_repos
else
add_master_repo
end
......@@ -43,6 +47,21 @@ module Pod
# @!group Setup steps
# Migrates any repos from the old directory structure to the new directory
# structure.
#
# @return [void]
def migrate_repos
config.repos_dir.mkpath
Dir.foreach old_master_repo_dir.parent do |repo_dir|
source_repo_dir = old_master_repo_dir.parent + repo_dir
target_repo_dir = config.repos_dir + repo_dir
if not repo_dir =~ /\.+/ and source_repo_dir != config.repos_dir
FileUtils.mv source_repo_dir, target_repo_dir
end
end
end
# Sets the url of the master repo according to whether it is push.
#
# @return [void]
......@@ -129,6 +148,12 @@ module Pod
def master_repo_dir
SourcesManager.master_repo_dir
end
# @return [Pathname] the directory of the old master repo.
#
def old_master_repo_dir
Pathname.new('~/.cocoapods/master').expand_path
end
end
end
end
......@@ -132,10 +132,17 @@ module Pod
# @!group Paths
# @return [Pathname] the directory where repos, templates and configuration
# files are stored.
#
def home_dir
@home_dir ||= Pathname.new(ENV['CP_HOME_DIR'] || "~/.cocoapods").expand_path
end
# @return [Pathname] the directory where the CocoaPods sources are stored.
#
def repos_dir
@repos_dir ||= Pathname.new(ENV['CP_REPOS_DIR'] || "~/.cocoapods").expand_path
@repos_dir ||= Pathname.new(ENV['CP_REPOS_DIR'] || "~/.cocoapods/repos").expand_path
end
attr_writer :repos_dir
......@@ -261,7 +268,7 @@ module Pod
# @return [Pathname] The path of the file which contains the user settings.
#
def user_settings_file
repos_dir + "config.yaml"
home_dir + "config.yaml"
end
# Sets the values of the attributes with the given hash.
......
......@@ -45,5 +45,26 @@ module Pod
Dir.chdir(config.repos_dir + 'master') { `git remote set-url origin git@github.com:CocoaPods/Specs.git` }
command('setup').url.should == 'git@github.com:CocoaPods/Specs.git'
end
before do
FileUtils.rm_rf(test_repo_path)
set_up_old_test_repo
config.repos_dir = SpecHelper.temporary_directory + 'cocoapods/repos'
Command::Setup.any_instance.stubs(:old_master_repo_dir).returns(SpecHelper.temporary_directory + 'cocoapods/master')
end
it "migrates repos from the old directory structure to the new one" do
source = SpecHelper.temporary_directory + 'cocoapods/master'
target = config.repos_dir + 'master'
source.should.exist?
target.should.not.exist?
output = run_command('setup')
source.should.not.exist?
target.should.exist?
end
end
end
......@@ -45,7 +45,7 @@ module SpecHelper
repo_path('master')
end
# Sets up a lighweight master repo in `tmp/cocoapods/master` with the
# Sets up a lighweight master repo in `tmp/cocoapods/repos/master` with the
# contents of `spec/fixtures/spec-repos/test_repo`.
#
def set_up_test_repo
......@@ -57,10 +57,26 @@ module SpecHelper
repo_make('master')
end
def test_old_repo_path
repo_path('../master')
end
# Sets up a lighweight master repo in `tmp/cocoapods/master` with the
# contents of `spec/fixtures/spec-repos/test_repo`.
#
def set_up_old_test_repo
require 'fileutils'
test_old_repo_path.mkpath
origin = ROOT + 'spec/fixtures/spec-repos/test_repo/.'
destination = tmp_repos_path + '../master'
FileUtils.cp_r(origin, destination)
repo_make('../master')
end
#--------------------------------------#
def tmp_repos_path
SpecHelper.temporary_directory + 'cocoapods'
SpecHelper.temporary_directory + 'cocoapods/repos'
end
module_function :tmp_repos_path
......
......@@ -15,12 +15,12 @@ module Pod
@sut.should.be.instance_of Config
end
it "returns the path to the spec-repos dir" do
@sut.repos_dir.should == Pathname.new("~/.cocoapods").expand_path
it "returns the path to the home dir" do
@sut.home_dir.should == Pathname.new("~/.cocoapods").expand_path
end
it "returns the path to the spec-repos dir" do
@sut.repos_dir.should == Pathname.new("~/.cocoapods").expand_path
@sut.repos_dir.should == Pathname.new("~/.cocoapods/repos").expand_path
end
it "allows to specify whether the aggressive cache should be used with an environment variable" do
......@@ -30,6 +30,12 @@ module Pod
ENV.delete('CP_AGGRESSIVE_CACHE')
end
it "allows to specify the home dir with an environment variable" do
ENV['CP_HOME_DIR'] = '~/custom_home_dir'
@sut.home_dir.should == Pathname.new("~/custom_home_dir").expand_path
ENV.delete('CP_HOME_DIR')
end
it "allows to specify the repos dir with an environment variable" do
ENV['CP_REPOS_DIR'] = '~/custom_repos_dir'
@sut.repos_dir.should == Pathname.new("~/custom_repos_dir").expand_path
......
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