Permalink
Browse files

[#112] Introduced --push option for setup command

  • Loading branch information...
1 parent c3bb9a1 commit a403638663dd96edbfe068e3ccfd9593235d14d6 @fabiopelosin fabiopelosin committed Mar 20, 2012
Showing with 45 additions and 4 deletions.
  1. +2 −0 lib/cocoapods/command.rb
  2. +8 −1 lib/cocoapods/command/repo.rb
  3. +35 −3 lib/cocoapods/command/setup.rb
@@ -8,6 +8,8 @@ class Command
autoload :Setup, 'cocoapods/command/setup'
autoload :Spec, 'cocoapods/command/spec'
+ attr_accessor :output
+
class Help < Informative
def initialize(command_class, argv)
@command_class, @argv = command_class, argv
@@ -30,7 +30,7 @@ def initialize(argv)
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'."
end
- when 'update'
+ when 'update', 'read-url'
@name = argv.arguments[1]
else
super
@@ -64,6 +64,13 @@ def set_url
git("remote set-url origin '#{@url}'")
end
end
+
+ def read_url
+ Dir.chdir(dir) do
+ @output = git("remote -v")
+ end
+ end
+
end
end
end
@@ -14,28 +14,60 @@ def self.banner
If the clone already exists, it will ensure that it is up-to-date.}
end
+ def self.options
+ " --push Use this option to enable push access once granted\n" +
+ super
+ end
+
def initialize(argv)
+ @push_access = argv.option('--push') || already_push?
+ puts "Setup with push access" if @push_access && !config.silent
super unless argv.empty?
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
'git://github.com/CocoaPods/Specs.git'
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
- @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
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
def update_master_repo_command
Repo.new(ARGV.new(['update', 'master']))
end
def run
- if (config.repos_dir + 'master').exist?
+ if master_repo_exists?
update_master_repo_remote_command.run
update_master_repo_command.run
else

0 comments on commit a403638

Please sign in to comment.