Commit b8e10806 authored by Fabio Pelosin's avatar Fabio Pelosin

Merge branch 'master' of https://github.com/playhaven/CocoaPods into playhaven-master

* 'master' of https://github.com/playhaven/CocoaPods:
  [tweak] remove .to_a method since unnecessary with splat operator
  [fix] unit tests now passing
  [fix] small syntax error
  [add] ability to specify :branch in Podfiles and Podspecs

Conflicts:
	.gitignore
	lib/cocoapods/downloader/git.rb
	spec/fixtures/banana-lib.tar.gz
	spec/functional/downloader_spec.rb
parents 86f64244 4f92cc88
...@@ -159,6 +159,7 @@ module Pod ...@@ -159,6 +159,7 @@ module Pod
def description def description
"from `#{@params[:git]}'".tap do |description| "from `#{@params[:git]}'".tap do |description|
description << ", commit `#{@params[:commit]}'" if @params[:commit] description << ", commit `#{@params[:commit]}'" if @params[:commit]
description << ", branch `#{@params[:branch]}'" if @params[:branch]
description << ", tag `#{@params[:tag]}'" if @params[:tag] description << ", tag `#{@params[:tag]}'" if @params[:tag]
end end
end end
......
...@@ -16,6 +16,8 @@ module Pod ...@@ -16,6 +16,8 @@ module Pod
puts '-> Cloning git repo' if config.verbose? puts '-> Cloning git repo' if config.verbose?
if options[:tag] if options[:tag]
download_tag download_tag
elsif options[:branch]
download_branch
elsif options[:commit] elsif options[:commit]
download_commit download_commit
else else
...@@ -89,6 +91,13 @@ module Pod ...@@ -89,6 +91,13 @@ module Pod
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 ref_exists?(ref)
end end
def ensure_remote_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
end
def download_head def download_head
update_cache update_cache
git "clone '#{clone_url}' '#{target_path}'" git "clone '#{clone_url}' '#{target_path}'"
...@@ -112,6 +121,17 @@ module Pod ...@@ -112,6 +121,17 @@ module Pod
git "checkout -b activated-pod-commit #{options[:commit]}" git "checkout -b activated-pod-commit #{options[:commit]}"
end end
end end
def download_branch
ensure_remote_branch_exists(options[:branch])
git "clone '#{clone_url}' '#{target_path}'"
Dir.chdir(target_path) do
git "remote add upstream #{@url}" # we need to add the original url, not the cache url
git "fetch -q upstream" # refresh the branches
git "checkout --track -b activated-pod-commit upstream/#{options[:branch]}" # create a new tracking branch
puts "Just downloaded and checked out branch: #{options[:branch]} from upstream #{clone_url}" if config.verbose?
end
end
end end
class GitHub < Git class GitHub < Git
...@@ -127,8 +147,12 @@ module Pod ...@@ -127,8 +147,12 @@ module Pod
download_only? ? download_and_extract_tarball(options[:commit]) : super download_only? ? download_and_extract_tarball(options[:commit]) : super
end end
def download_branch
download_only? ? download_and_extract_tarball(options[:branch]) : super
end
def tarball_url_for(id) def tarball_url_for(id)
original_url, username, reponame = *(url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/).to_a) original_url, username, reponame = *(url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/))
"https://github.com/#{username}/#{reponame}/tarball/#{id}" "https://github.com/#{username}/#{reponame}/tarball/#{id}"
end end
......
...@@ -18,12 +18,23 @@ describe "Pod::Downloader" do ...@@ -18,12 +18,23 @@ describe "Pod::Downloader" do
(@pod.root + 'README').read.strip.should == 'first commit' (@pod.root + 'README').read.strip.should == 'first commit'
end end
it "check's out a specific branch" do
@pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :branch => 'topicbranch'
)
downloader = Pod::Downloader.for_pod(@pod)
downloader.download
(@pod.root + 'README').read.strip.should == 'topicbranch'
end
it "check's out a specific tag" do it "check's out a specific tag" do
@pod.top_specification.stubs(:source).returns( @pod.top_specification.stubs(:source).returns(
:git => fixture('banana-lib'), :tag => 'v1.0' :git => fixture('banana-lib'), :tag => 'v1.0'
) )
downloader = Pod::Downloader.for_pod(@pod) downloader = Pod::Downloader.for_pod(@pod)
downloader.download downloader.download
(@pod.root + 'README').read.strip.should == 'v1.0' (@pod.root + 'README').read.strip.should == 'v1.0'
end end
...@@ -170,6 +181,19 @@ describe "Pod::Downloader" do ...@@ -170,6 +181,19 @@ describe "Pod::Downloader" do
(@pod.root + 'libPusher.podspec').readlines.grep(/1.1/).should.not.be.empty (@pod.root + 'libPusher.podspec').readlines.grep(/1.1/).should.not.be.empty
end end
it "downloads a specific branch when specified" do
@pod.top_specification.stubs(:source).returns(
:git => "git://github.com/lukeredpath/libPusher.git", :branch => 'gh-pages', :download_only => true
)
downloader = Pod::Downloader.for_pod(@pod)
VCR.use_cassette('tarballs', :record => :new_episodes) { downloader.download }
# deliberately keep this assertion as loose as possible for now
(@pod.root + 'index.html').readlines.grep(/libPusher Documentation/).should.not.be.empty
end
it "downloads a specific commit when specified" do it "downloads a specific commit when specified" do
@pod.top_specification.stubs(:source).returns( @pod.top_specification.stubs(:source).returns(
:git => "git://github.com/lukeredpath/libPusher.git", :commit => 'eca89998d5', :download_only => true :git => "git://github.com/lukeredpath/libPusher.git", :commit => 'eca89998d5', :download_only => true
......
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