Commit 4bdb17b1 authored by Eloy Durán's avatar Eloy Durán

Merge pull request #514 from raylillywhite/master

Update git repo cache if branch isn't found
parents a2a9eab5 33509e01
......@@ -79,6 +79,7 @@ module Pod
git! "reset --hard HEAD"
git! "clean -d -x -f"
git! "pull origin master"
git! "fetch"
git! "fetch --tags"
end
end
......@@ -95,10 +96,15 @@ module Pod
raise Informative, "[!] Cache unable to find git reference `#{ref}' for `#{url}'.".red unless ref_exists?(ref)
end
def ensure_remote_branch_exists(branch)
def branch_exists?(branch)
Dir.chdir(cache_path) { git "branch -r | grep #{branch}$" } # check for remote branch and do suffix matching ($ anchor)
return if $? == 0
raise Informative, "[!] Cache unable to find git reference `#{branch}' for `#{url}' (#{$?}).".red
$? == 0
end
def ensure_remote_branch_exists(branch)
return if branch_exists?(branch)
update_cache
raise Informative, "[!] Cache unable to find git reference `#{branch}' for `#{url}' (#{$?}).".red unless branch_exists?(branch)
end
def download_head
......
......@@ -197,6 +197,47 @@ module Pod
downloader.expects(:update_cache).never
downloader.download
end
it "updates the cache if the branch 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, :branch => 'master'
)
downloader = Downloader.for_pod(@pod)
downloader.download
# make a new branch in the origin
branch = 'test'
Dir.chdir(tmp_repo_path) do
`touch test.txt`
`git checkout -b #{branch} >/dev/null 2>&1`
`git add test.txt`
`git commit -m 'test'`
end
# require the new branch
pod = LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), temporary_sandbox, Platform.ios)
pod.top_specification.stubs(:source).returns(
:git => tmp_repo_path, :branch => branch
)
downloader = Downloader.for_pod(pod)
downloader.download
(pod.root + 'test.txt').should.exist?
end
it "doesn't update the cache if the branch is available" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :branch => 'master'
)
downloader = Downloader.for_pod(@pod)
downloader.download
@pod.root.rmtree
downloader.expects(:update_cache).never
downloader.download
end
end
......
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