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
15ee6d60
Commit
15ee6d60
authored
May 24, 2012
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Specs] Added specifications related to Git caching.
Closes #254.
parent
1801ce2d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
130 additions
and
17 deletions
+130
-17
git.rb
lib/cocoapods/downloader/git.rb
+14
-13
downloader_spec.rb
spec/functional/downloader_spec.rb
+116
-4
No files found.
lib/cocoapods/downloader/git.rb
View file @
15ee6d60
...
@@ -12,7 +12,7 @@ module Pod
...
@@ -12,7 +12,7 @@ module Pod
MAX_CACHE_SIZE
=
500
MAX_CACHE_SIZE
=
500
def
download
def
download
prepare_cache
create_cache
unless
cache_exist?
puts
'-> Cloning git repo'
if
config
.
verbose?
puts
'-> Cloning git repo'
if
config
.
verbose?
if
options
[
:tag
]
if
options
[
:tag
]
download_tag
download_tag
...
@@ -24,13 +24,11 @@ module Pod
...
@@ -24,13 +24,11 @@ module Pod
removed_cached_repos_if_needed
removed_cached_repos_if_needed
end
end
def
prepare_cache
def
create_cache
unless
cache_exist?
puts
"-> Creating cache git repo (
#{
cache_path
}
)"
if
config
.
verbose?
puts
"-> Creating cache git repo (
#{
cache_path
}
)"
if
config
.
verbose?
cache_path
.
rmtree
if
cache_path
.
exist?
cache_path
.
rmtree
if
cache_path
.
exist?
cache_path
.
mkpath
cache_path
.
mkpath
git
"clone '
#{
url
}
'
#{
cache_path
}
"
git
"clone '
#{
url
}
'
#{
cache_path
}
"
end
end
end
def
removed_cached_repos_if_needed
def
removed_cached_repos_if_needed
...
@@ -50,7 +48,7 @@ module Pod
...
@@ -50,7 +48,7 @@ module Pod
end
end
def
cache_exist?
def
cache_exist?
cache_path
.
exist?
&&
origin_url
(
cache_path
)
==
url
cache_path
.
exist?
&&
origin_url
(
cache_path
)
.
to_s
==
url
.
to_s
end
end
def
origin_url
(
dir
)
def
origin_url
(
dir
)
...
@@ -79,13 +77,16 @@ module Pod
...
@@ -79,13 +77,16 @@ module Pod
end
end
end
end
def
ensure_ref_exists
(
ref
)
def
ref_exists?
(
ref
)
Dir
.
chdir
(
cache_path
)
{
git
"rev-list --max-count=1
#{
ref
}
"
}
Dir
.
chdir
(
cache_path
)
{
git
"rev-list --max-count=1
#{
ref
}
"
}
return
if
$?
==
0
$?
==
0
end
def
ensure_ref_exists
(
ref
)
return
if
ref_exists?
(
ref
)
# Skip pull if not needed
# Skip pull if not needed
update_cache
update_cache
Dir
.
chdir
(
cache_path
)
{
git
"rev-list --max-count=1
#{
ref
}
"
}
raise
Informative
,
"[!] Cache unable to find git reference `
#{
ref
}
' for `
#{
url
}
'."
.
red
unless
ref_exists?
(
ref
)
raise
Informative
,
"[!] Cache unable to find git reference `
#{
ref
}
' for `
#{
url
}
'."
.
red
unless
$?
==
0
end
end
def
download_head
def
download_head
...
...
spec/functional/downloader_spec.rb
View file @
15ee6d60
...
@@ -36,9 +36,124 @@ describe "Pod::Downloader" do
...
@@ -36,9 +36,124 @@ describe "Pod::Downloader" do
downloader
.
clean
downloader
.
clean
(
@pod
.
root
+
'.git'
).
should
.
not
.
exist
(
@pod
.
root
+
'.git'
).
should
.
not
.
exist
end
end
it
"prepares the cache if it does not exits"
do
@pod
.
top_specification
.
stubs
(
:source
).
returns
(
:git
=>
fixture
(
'banana-lib'
),
:commit
=>
'fd56054'
)
downloader
=
Pod
::
Downloader
.
for_pod
(
@pod
)
downloader
.
cache_path
.
rmtree
if
downloader
.
cache_path
.
exist?
downloader
.
expects
(
:create_cache
).
once
downloader
.
stubs
(
:download_commit
)
downloader
.
download
end
it
"removes the oldest repo if the caches is too big"
do
@pod
.
top_specification
.
stubs
(
:source
).
returns
(
:git
=>
fixture
(
'banana-lib'
),
:commit
=>
'fd56054'
)
original_chace_size
=
Pod
::
Downloader
::
Git
::
MAX_CACHE_SIZE
Pod
::
Downloader
::
Git
.
__send__
(
:remove_const
,
'MAX_CACHE_SIZE'
)
Pod
::
Downloader
::
Git
::
MAX_CACHE_SIZE
=
0
downloader
=
Pod
::
Downloader
.
for_pod
(
@pod
)
downloader
.
stubs
(
:cache_dir
).
returns
(
temporary_directory
)
downloader
.
download
downloader
.
cache_path
.
should
.
not
.
exist?
Pod
::
Downloader
::
Git
.
__send__
(
:remove_const
,
'MAX_CACHE_SIZE'
)
Pod
::
Downloader
::
Git
::
MAX_CACHE_SIZE
=
original_chace_size
end
xit
"raises if it can't find the url"
do
@pod
.
top_specification
.
stubs
(
:source
).
returns
(
:git
=>
'find_me_if_you_can'
)
downloader
=
Pod
::
Downloader
.
for_pod
(
@pod
)
lambda
{
downloader
.
download
}.
should
.
raise
Pod
::
Informative
end
it
"raises if it can't find a commit"
do
@pod
.
top_specification
.
stubs
(
:source
).
returns
(
:git
=>
fixture
(
'banana-lib'
),
:commit
=>
'aaaaaa'
)
downloader
=
Pod
::
Downloader
.
for_pod
(
@pod
)
lambda
{
downloader
.
download
}.
should
.
raise
Pod
::
Informative
end
it
"raises if it can't find a tag"
do
@pod
.
top_specification
.
stubs
(
:source
).
returns
(
:git
=>
fixture
(
'banana-lib'
),
:tag
=>
'aaaaaa'
)
downloader
=
Pod
::
Downloader
.
for_pod
(
@pod
)
lambda
{
downloader
.
download
}.
should
.
raise
Pod
::
Informative
end
it
"does not raise if it can find the reference"
do
@pod
.
top_specification
.
stubs
(
:source
).
returns
(
:git
=>
fixture
(
'banana-lib'
),
:commit
=>
'fd56054'
)
downloader
=
Pod
::
Downloader
.
for_pod
(
@pod
)
lambda
{
downloader
.
download
}.
should
.
not
.
raise
end
it
"returns the cache directory as the clone url"
do
@pod
.
top_specification
.
stubs
(
:source
).
returns
(
:git
=>
fixture
(
'banana-lib'
),
:commit
=>
'fd56054'
)
downloader
=
Pod
::
Downloader
.
for_pod
(
@pod
)
downloader
.
clone_url
.
to_s
.
should
.
match
/^\/Users\/.*\/Library\/Caches\/CocoaPods\/Git\/de23bb241237818bc96a62ce1309e36b6f774253/
end
it
"updates the cache if the HEAD is requested"
do
@pod
.
top_specification
.
stubs
(
:source
).
returns
(
:git
=>
fixture
(
'banana-lib'
)
)
downloader
=
Pod
::
Downloader
.
for_pod
(
@pod
)
downloader
.
expects
(
:update_cache
).
once
downloader
.
download
end
it
"updates the cache if the ref is not available"
do
# create the origin repo and the cache
tmp_repo_path
=
temporary_directory
+
'banana-lib-source'
`git clone
#{
fixture
(
'banana-lib'
)
}
#{
tmp_repo_path
}
`
@pod
.
top_specification
.
stubs
(
:source
).
returns
(
:git
=>
tmp_repo_path
,
:commit
=>
'fd56054'
)
downloader
=
Pod
::
Downloader
.
for_pod
(
@pod
)
downloader
.
download
# make a new commit in the origin
commit
=
''
Dir
.
chdir
(
tmp_repo_path
)
do
`touch test.txt`
`git add test.txt`
`git commit -m 'test'`
commit
=
`git rev-parse HEAD`
.
chomp
end
# require the new commit
pod
=
Pod
::
LocalPod
.
new
(
fixture_spec
(
'banana-lib/BananaLib.podspec'
),
temporary_sandbox
,
Pod
::
Platform
.
ios
)
pod
.
top_specification
.
stubs
(
:source
).
returns
(
:git
=>
tmp_repo_path
,
:commit
=>
commit
)
downloader
=
Pod
::
Downloader
.
for_pod
(
pod
)
downloader
.
download
(
pod
.
root
+
'test.txt'
).
should
.
exist?
end
it
"doesn't updates cache the if the ref is available"
do
@pod
.
top_specification
.
stubs
(
:source
).
returns
(
:git
=>
fixture
(
'banana-lib'
),
:commit
=>
'fd56054'
)
downloader
=
Pod
::
Downloader
.
for_pod
(
@pod
)
downloader
.
download
downloader
.
expects
(
:update_cache
).
never
downloader
.
download
end
end
end
describe
"for G
i
thub repositories, with :download_only set to true"
do
describe
"for G
b
thub repositories, with :download_only set to true"
do
extend
SpecHelper
::
TemporaryDirectory
extend
SpecHelper
::
TemporaryDirectory
it
"downloads HEAD with no other options specified"
do
it
"downloads HEAD with no other options specified"
do
...
@@ -176,7 +291,4 @@ describe "Pod::Downloader" do
...
@@ -176,7 +291,4 @@ describe "Pod::Downloader" do
(
@pod
.
root
+
'file.zip'
).
should
.
not
.
exist
(
@pod
.
root
+
'file.zip'
).
should
.
not
.
exist
end
end
end
end
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