Skip to content

Commit

Permalink
Migrate existing repos when running setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ianyh committed Aug 1, 2013
1 parent 43d71e2 commit 0478e8b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/cocoapods/command/setup.rb
@@ -1,3 +1,5 @@
require 'fileutils'

module Pod
class Command
class Setup < Command
Expand Down Expand Up @@ -30,6 +32,8 @@ def run
set_master_repo_url
set_master_repo_branch
update_master_repo
elsif old_master_repo_dir.exist?
migrate_repos
else
add_master_repo
end
Expand All @@ -43,6 +47,21 @@ def run

# @!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 config.old_repos_dir do |repo_dir|
source_repo_dir = config.old_repos_dir + 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]
Expand Down Expand Up @@ -129,6 +148,12 @@ def master_repo_is_push?
def master_repo_dir
SourcesManager.master_repo_dir
end

# @return [Pathname] the directory of the old master repo.
#
def old_master_repo_dir
SourcesManager.old_master_repo_dir
end
end
end
end
4 changes: 4 additions & 0 deletions lib/cocoapods/config.rb
Expand Up @@ -146,6 +146,10 @@ def repos_dir

attr_writer :repos_dir

def old_repos_dir
@old_repos_dir ||= Pathname.new('~/.cocoapods').expand_path
end

# @return [Pathname] the root of the CocoaPods installation where the
# Podfile is located.
#
Expand Down
5 changes: 5 additions & 0 deletions lib/cocoapods/sources_manager.rb
Expand Up @@ -259,6 +259,11 @@ def master_repo_dir
config.repos_dir + 'master'
end

# @return [Pathname] The path of the old master repo.
def old_master_repo_dir
config.old_repos_dir + 'master'
end

# @return [Bool] Checks if the master repo is usable.
#
# @note Note this is used to automatically setup the master repo if
Expand Down

0 comments on commit 0478e8b

Please sign in to comment.