Commit 613db0bc authored by Fabio Pelosin's avatar Fabio Pelosin

Merge branch 'setup-push'

* setup-push:
  [#112] Introduced --push option for setup command
parents 194de448 a4036386
...@@ -8,6 +8,8 @@ module Pod ...@@ -8,6 +8,8 @@ module Pod
autoload :Setup, 'cocoapods/command/setup' autoload :Setup, 'cocoapods/command/setup'
autoload :Spec, 'cocoapods/command/spec' autoload :Spec, 'cocoapods/command/spec'
attr_accessor :output
class Help < Informative class Help < Informative
def initialize(command_class, argv) def initialize(command_class, argv)
@command_class, @argv = command_class, argv @command_class, @argv = command_class, argv
......
...@@ -30,7 +30,7 @@ module Pod ...@@ -30,7 +30,7 @@ module Pod
unless (@name = argv.arguments[1]) && (@url = argv.arguments[2]) unless (@name = argv.arguments[1]) && (@url = argv.arguments[2])
raise Informative, "#{@action == 'add' ? 'Adding' : 'Updating the remote of'} a repo needs a `name' and a `url'." raise Informative, "#{@action == 'add' ? 'Adding' : 'Updating the remote of'} a repo needs a `name' and a `url'."
end end
when 'update' when 'update', 'read-url'
@name = argv.arguments[1] @name = argv.arguments[1]
else else
super super
...@@ -64,6 +64,13 @@ module Pod ...@@ -64,6 +64,13 @@ module Pod
git("remote set-url origin '#{@url}'") git("remote set-url origin '#{@url}'")
end end
end end
def read_url
Dir.chdir(dir) do
@output = git("remote -v")
end
end
end end
end end
end end
......
...@@ -14,20 +14,52 @@ module Pod ...@@ -14,20 +14,52 @@ module Pod
If the clone already exists, it will ensure that it is up-to-date.} If the clone already exists, it will ensure that it is up-to-date.}
end end
def self.options
" --push Use this option to enable push access once granted\n" +
super
end
def initialize(argv) def initialize(argv)
@push_access = argv.option('--push') || already_push?
puts "Setup with push access" if @push_access && !config.silent
super unless argv.empty? super unless argv.empty?
end end
def already_push?
if master_repo_exists?
read_master_repo_remote_command.run
read_master_repo_remote_command.output.include? master_repo_url_with_push
else
false
end
end
def master_repo_exists?
(config.repos_dir + 'master').exist?
end
def master_repo_url def master_repo_url
'git://github.com/CocoaPods/Specs.git' 'git://github.com/CocoaPods/Specs.git'
end end
def master_repo_url_with_push
'git@github.com:CocoaPods/Specs.git'
end
def repo_url
@push_access ? master_repo_url_with_push : master_repo_url
end
def add_master_repo_command def add_master_repo_command
@command ||= Repo.new(ARGV.new(['add', 'master', master_repo_url])) @command ||= Repo.new(ARGV.new(['add', 'master', repo_url]))
end
def read_master_repo_remote_command
@read_command ||= Repo.new(ARGV.new(['read-url', 'master']))
end end
def update_master_repo_remote_command def update_master_repo_remote_command
Repo.new(ARGV.new(['set-url', 'master', master_repo_url])) Repo.new(ARGV.new(['set-url', 'master', repo_url]))
end end
def update_master_repo_command def update_master_repo_command
...@@ -35,7 +67,7 @@ module Pod ...@@ -35,7 +67,7 @@ module Pod
end end
def run def run
if (config.repos_dir + 'master').exist? if master_repo_exists?
update_master_repo_remote_command.run update_master_repo_remote_command.run
update_master_repo_command.run update_master_repo_command.run
else else
......
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