Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
fd1e891f
Commit
fd1e891f
authored
Mar 21, 2012
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[#112] Refactoring based on suggestions by @alloy
parent
89f81e10
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
50 deletions
+55
-50
command.rb
lib/cocoapods/command.rb
+0
-2
repo.rb
lib/cocoapods/command/repo.rb
+3
-20
setup.rb
lib/cocoapods/command/setup.rb
+32
-25
command_spec.rb
spec/functional/command_spec.rb
+11
-1
command_spec.rb
spec/unit/command_spec.rb
+9
-2
No files found.
lib/cocoapods/command.rb
View file @
fd1e891f
...
...
@@ -8,8 +8,6 @@ module Pod
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
...
...
lib/cocoapods/command/repo.rb
View file @
fd1e891f
...
...
@@ -14,11 +14,7 @@ module Pod
$ pod repo update NAME
Updates the local clone of the spec-repo `NAME'. If `NAME' is omitted
this will update all spec-repos in `~/.cocoapods'.
$ pod repo set-url NAME URL
Updates the remote `URL' of the spec-repo `NAME'.}
this will update all spec-repos in `~/.cocoapods'.}
end
extend
Executable
...
...
@@ -26,11 +22,11 @@ module Pod
def
initialize
(
argv
)
case
@action
=
argv
.
arguments
[
0
]
when
'add'
,
'set-url'
when
'add'
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'
,
'read-url'
when
'update'
@name
=
argv
.
arguments
[
1
]
else
super
...
...
@@ -58,19 +54,6 @@ module Pod
Dir
.
chdir
(
dir
)
{
git
(
"pull"
)
}
end
end
def
set_url
Dir
.
chdir
(
dir
)
do
git
(
"remote set-url origin '
#{
@url
}
'"
)
end
end
def
read_url
Dir
.
chdir
(
dir
)
do
@output
=
git
(
'config --get remote.origin.url'
)
end
end
end
end
end
...
...
lib/cocoapods/command/setup.rb
View file @
fd1e891f
...
...
@@ -19,47 +19,53 @@ module Pod
super
end
extend
Executable
executable
:git
def
initialize
(
argv
)
@push_access
=
argv
.
option
(
'--push'
)
||
already_push?
puts
"Setup with push access"
if
@push_access
&&
!
config
.
silent
@push_option
=
argv
.
option
(
'--push'
)
super
unless
argv
.
empty?
end
def
already_push?
if
master_repo_exists?
read_master_repo_remote_command
.
run
read_master_repo_remote_command
.
output
.
chomp
==
master_repo_url_with_push
else
false
end
def
dir
config
.
repos_dir
+
'master'
end
def
master_repo_exists?
(
config
.
repos_dir
+
'master'
).
exist?
end
def
master_repo_url
def
read_only_url
'git://github.com/CocoaPods/Specs.git'
end
def
master_repo_url_with_push
def
read_write_url
'git@github.com:CocoaPods/Specs.git'
end
def
repo_url
@push_access
?
master_repo_url_with_push
:
master_repo_url
def
url
if
push?
read_write_url
else
read_only_url
end
end
def
add_master_repo_command
@command
||=
Repo
.
new
(
ARGV
.
new
([
'add'
,
'master'
,
repo_url
]))
def
origin_url_push?
Dir
.
chdir
(
dir
)
do
origin_url
=
git
(
'config --get remote.origin.url'
)
origin_url
.
chomp
==
read_write_url
end
end
def
push?
@push_option
||
(
dir
.
exist?
&&
origin_url_push?
)
end
def
read_master_repo_remote_command
@read_command
||=
Repo
.
new
(
ARGV
.
new
([
'read-url'
,
'master'
]))
def
set_master_repo_url
Dir
.
chdir
(
dir
)
do
git
(
"remote set-url origin '
#{
url
}
'"
)
end
end
def
update_master_repo_remote
_command
Repo
.
new
(
ARGV
.
new
([
'set-url'
,
'master'
,
repo_
url
]))
def
add_master_repo
_command
@command
||=
Repo
.
new
(
ARGV
.
new
([
'add'
,
'master'
,
url
]))
end
def
update_master_repo_command
...
...
@@ -67,8 +73,9 @@ module Pod
end
def
run
if
master_repo_exists?
update_master_repo_remote_command
.
run
puts
"Using push access"
if
push?
&&
!
config
.
silent
if
dir
.
exist?
set_master_repo_url
update_master_repo_command
.
run
else
add_master_repo_command
.
run
...
...
spec/functional/command_spec.rb
View file @
fd1e891f
...
...
@@ -6,11 +6,21 @@ describe "Pod::Command" do
it
"creates the local spec-repos directory and creates a clone of the `master' repo"
do
command
=
Pod
::
Command
.
parse
(
'setup'
,
'--silent'
)
def
command
.
master_repo_
url
;
SpecHelper
.
fixture
(
'spec-repos/master'
);
end
def
command
.
url
;
SpecHelper
.
fixture
(
'spec-repos/master'
);
end
command
.
run
git_config
(
'master'
,
'remote.origin.url'
).
should
==
fixture
(
'spec-repos/master'
).
to_s
end
it
"preserve push access for the `master' repo"
do
command
=
Pod
::
Command
.
parse
(
'setup'
,
'--silent'
)
def
command
.
url
;
SpecHelper
.
fixture
(
'spec-repos/master'
);
end
command
.
run
command2
=
Pod
::
Command
.
parse
(
'setup'
,
'--silent'
)
command2
.
url
.
should
==
'git://github.com/CocoaPods/Specs.git'
git
(
'master'
,
'remote set-url origin git@github.com:CocoaPods/Specs.git'
)
command2
.
url
.
should
==
'git@github.com:CocoaPods/Specs.git'
end
it
"adds a spec-repo"
do
add_repo
(
'private'
,
fixture
(
'spec-repos/master'
))
git_config
(
'private'
,
'remote.origin.url'
).
should
==
fixture
(
'spec-repos/master'
).
to_s
...
...
spec/unit/command_spec.rb
View file @
fd1e891f
...
...
@@ -2,6 +2,7 @@ require File.expand_path('../../spec_helper', __FILE__)
describe
"Pod::Command"
do
it
"returns the proper command class"
do
config
.
silent
.
should
==
true
Pod
::
Command
.
parse
(
'setup'
).
should
.
be
.
instance_of
Pod
::
Command
::
Setup
#Pod::Command.parse('spec').should.be.instance_of Pod::Command::Spec
Pod
::
Command
.
parse
(
'repo'
,
'update'
).
should
.
be
.
instance_of
Pod
::
Command
::
Repo
...
...
@@ -13,9 +14,15 @@ describe "Pod::Command::Setup" do
lambda
{
Pod
::
Command
::
Setup
.
new
(
argv
(
'something'
))
}.
should
.
raise
Pod
::
Command
::
Help
end
it
"returns the URL of the `master' spec-repo"
do
it
"returns the
read only
URL of the `master' spec-repo"
do
command
=
Pod
::
Command
::
Setup
.
new
(
argv
)
command
.
master_repo_url
.
should
==
'git://github.com/CocoaPods/Specs.git'
command
.
url
.
should
==
'git://github.com/CocoaPods/Specs.git'
end
it
"returns the push URL of the `master' spec-repo"
do
config
.
silent
=
true
command
=
Pod
::
Command
::
Setup
.
new
(
argv
(
'--push'
))
command
.
url
.
should
==
'git@github.com:CocoaPods/Specs.git'
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment