Class: Pod::Command::Setup

Inherits:
Pod::Command show all
Extended by:
Executable
Defined in:
lib/cocoapods/command/setup.rb

Setup steps collapse

Private helpers collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Executable

executable, execute_command, which

Methods inherited from Pod::Command

#ensure_master_spec_repo_exists!, report_error, run

Methods included from Pod::Config::Mixin

#config

Constructor Details

#initialize(argv) ⇒ Setup

Returns a new instance of Setup.



26
27
28
29
# File 'lib/cocoapods/command/setup.rb', line 26

def initialize(argv)
  @shallow = argv.flag?('shallow', true)
  super
end

Class Method Details

.optionsObject



17
18
19
20
21
# File 'lib/cocoapods/command/setup.rb', line 17

def self.options
  [
    ['--no-shallow', 'Clone full history so push will work'],
  ].concat(super)
end

.read_only_urlString

Returns the read only url of the master repo.

Returns:

  • (String)

    the read only url of the master repo.



121
122
123
# File 'lib/cocoapods/command/setup.rb', line 121

def self.read_only_url
  'https://github.com/CocoaPods/Specs.git'
end

Instance Method Details

#add_master_repovoid

This method returns an undefined value.

Adds the master repo from the remote.



81
82
83
84
85
# File 'lib/cocoapods/command/setup.rb', line 81

def add_master_repo
  cmd = ['master', url, 'master']
  cmd << '--shallow' if @shallow
  Repo::Add.parse(cmd).run
end

#master_repo_dirPathname

Returns the directory of the master repo.

Returns:

  • (Pathname)

    the directory of the master repo.



127
128
129
# File 'lib/cocoapods/command/setup.rb', line 127

def master_repo_dir
  SourcesManager.master_repo_dir
end

#migrate_reposObject

Migrates any repos from the old directory structure to the new directory structure.

@todo: Remove by 1.0



56
57
58
59
60
61
62
63
64
65
# File 'lib/cocoapods/command/setup.rb', line 56

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 repo_dir !~ /\.+/ && source_repo_dir != config.repos_dir
      FileUtils.mv source_repo_dir, target_repo_dir
    end
  end
end

#old_master_repo_dirPathname

Returns the directory of the old master repo.

Returns:

  • (Pathname)

    the directory of the old master repo.



133
134
135
# File 'lib/cocoapods/command/setup.rb', line 133

def old_master_repo_dir
  Pathname.new('~/.cocoapods/master').expand_path
end

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cocoapods/command/setup.rb', line 31

def run
  UI.section 'Setting up CocoaPods master repo' do
    if master_repo_dir.exist?
      set_master_repo_url
      set_master_repo_branch
      update_master_repo
    elsif old_master_repo_dir.exist?
      migrate_repos
    else
      add_master_repo
    end
  end

  UI.puts 'Setup completed'.green
end

#set_master_repo_branchvoid

Note:

This is not needed anymore as it was used for CocoaPods 0.6 release candidates.

This method returns an undefined value.

Sets the repo to the master branch.



102
103
104
105
106
# File 'lib/cocoapods/command/setup.rb', line 102

def set_master_repo_branch
  Dir.chdir(master_repo_dir) do
    git %w(checkout master)
  end
end

#set_master_repo_urlvoid

This method returns an undefined value.

Sets the url of the master repo according to whether it is push.



71
72
73
74
75
# File 'lib/cocoapods/command/setup.rb', line 71

def set_master_repo_url
  Dir.chdir(master_repo_dir) do
    git('remote', 'set-url', 'origin', url)
  end
end

#update_master_repovoid

This method returns an undefined value.

Updates the master repo against the remote.



91
92
93
# File 'lib/cocoapods/command/setup.rb', line 91

def update_master_repo
  SourcesManager.update('master', true)
end

#urlString

Returns the url to use according to whether push mode should be enabled.

Returns:

  • (String)

    the url to use according to whether push mode should be enabled.



115
116
117
# File 'lib/cocoapods/command/setup.rb', line 115

def url
  self.class.read_only_url
end