diff --git a/lib/cocoapods-core/source/acceptor.rb b/lib/cocoapods-core/source/acceptor.rb index 7c3a8596a..50234124a 100644 --- a/lib/cocoapods-core/source/acceptor.rb +++ b/lib/cocoapods-core/source/acceptor.rb @@ -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. # @@ -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 diff --git a/spec/source/acceptor_spec.rb b/spec/source/acceptor_spec.rb index 23a47957f..5ed54d549 100644 --- a/spec/source/acceptor_spec.rb +++ b/spec/source/acceptor_spec.rb @@ -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([]) @@ -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")