Skip to content

Commit

Permalink
Accept new sources when they are just redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
neonichu committed Apr 6, 2014
1 parent 2c75823 commit d7e0497
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
33 changes: 28 additions & 5 deletions lib/cocoapods-core/source/acceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ def analyze_path(spec_path)
# @!group Private helpers
#-----------------------------------------------------------------------#

# Resolve potential redirects and return the final URL.
#
# @return [string]
#
def get_actual_url(url)
loop do
require 'rest'
response = REST.head(url)

if response.status_code == 301
url = response.headers['location'].first
else
break
end
end

url
end

# Checks whether the source of the proposed specification is different
# from the one of the reference specification.
#
Expand All @@ -68,11 +87,15 @@ def check_spec_source_change(spec, errors)
source = spec.source.values_at(*keys).compact.first
old_source = reference_spec(spec).source.values_at(*keys).compact.first
unless source == old_source
message = "The source of the spec doesn't match with the recorded "
message << "ones. Source: `#{source}`. Previous: `#{old_source}`.\n "
message << 'Please contact the specs repo maintainers if the'
message << 'library changed location.'
errors << message
source = get_actual_url(source)
old_source = get_actual_url(old_source)
unless source == old_source
message = "The source of the spec doesn't match with the recorded "
message << "ones. Source: `#{source}`. Previous: `#{old_source}`.\n "
message << 'Please contact the specs repo maintainers if the'
message << 'library changed location.'
errors << message
end
end
end

Expand Down
12 changes: 12 additions & 0 deletions spec/source/acceptor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ module Pod
describe Source::Acceptor do

before do
WebMock::API.stub_request( :head, /http:\/\/banana-corp.local\/banana-lib.git/ ).to_return(
:status => 301, :headers => { 'Location' => 'http://NEW-URL/banana-lib.git' } )
WebMock::API.stub_request( :head, /http:\/\/evil-gorilla-fork\/banana-lib.git/ ).to_return(
:status => 200 )
WebMock::API.stub_request( :head, /http:\/\/new-url\/banana-lib.git/).to_return(
:status => 200 )
@spec_path = fixture('BananaLib.podspec')
@spec = Specification.from_file(@spec_path)
Specification.any_instance.stubs(:dependencies).returns([])
Expand Down Expand Up @@ -52,6 +58,12 @@ module Pod
errors.should.not.match /The source of the spec doesn't match/
end

it "doesn't fail if the new source of the specification is a redirect" do
@spec.source = { :git => 'http://NEW-URL/banana-lib.git', :tag => 'v1.0' }
errors = @sut.analyze(@spec).join("\n")
errors.should.not.match /The source of the spec doesn't match/
end

it 'rejects a Git based specification without tag if there is at least one tagged version' do
@spec.source = { :git => 'http://banana-corp.local/banana-lib.git', :commit => 'SHA' }
errors = @sut.analyze(@spec).join("\n")
Expand Down

0 comments on commit d7e0497

Please sign in to comment.