Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'setup-push'

* setup-push:
  [#112] Introduced --push option for setup command
  • Loading branch information...
commit 613db0bc29002ac639c006694d6991bdca8d7304 2 parents 194de44 + a403638
@fabiopelosin fabiopelosin authored
View
2  lib/cocoapods/command.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
View
9 lib/cocoapods/command/repo.rb
@@ -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
View
38 lib/cocoapods/command/setup.rb
@@ -14,20 +14,52 @@ 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
@@ -35,7 +67,7 @@ def update_master_repo_command
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

2 comments on commit 613db0b

@alloy
Owner

It looks good.

However, I’m thinking that with --push-access support, we don’t really need the set-url (and read-url) commands anymore. Can you move that to the setup class? (But not as commands, just methods.)

@fabiopelosin

Consider it done. I'm glad you found a way to get rid of that attr_accessor :output :)

Please sign in to comment.
Something went wrong with that request. Please try again.