Skip to content

Commit 5948db9

Browse files
committed
Merge pull request CocoaPods#102 from CocoaPods/feature-accept-redirects
Accept new sources when they are just redirects
2 parents 2c75823 + d7e0497 commit 5948db9

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

lib/cocoapods-core/source/acceptor.rb

+28-5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ def analyze_path(spec_path)
5353
# @!group Private helpers
5454
#-----------------------------------------------------------------------#
5555

56+
# Resolve potential redirects and return the final URL.
57+
#
58+
# @return [string]
59+
#
60+
def get_actual_url(url)
61+
loop do
62+
require 'rest'
63+
response = REST.head(url)
64+
65+
if response.status_code == 301
66+
url = response.headers['location'].first
67+
else
68+
break
69+
end
70+
end
71+
72+
url
73+
end
74+
5675
# Checks whether the source of the proposed specification is different
5776
# from the one of the reference specification.
5877
#
@@ -68,11 +87,15 @@ def check_spec_source_change(spec, errors)
6887
source = spec.source.values_at(*keys).compact.first
6988
old_source = reference_spec(spec).source.values_at(*keys).compact.first
7089
unless source == old_source
71-
message = "The source of the spec doesn't match with the recorded "
72-
message << "ones. Source: `#{source}`. Previous: `#{old_source}`.\n "
73-
message << 'Please contact the specs repo maintainers if the'
74-
message << 'library changed location.'
75-
errors << message
90+
source = get_actual_url(source)
91+
old_source = get_actual_url(old_source)
92+
unless source == old_source
93+
message = "The source of the spec doesn't match with the recorded "
94+
message << "ones. Source: `#{source}`. Previous: `#{old_source}`.\n "
95+
message << 'Please contact the specs repo maintainers if the'
96+
message << 'library changed location.'
97+
errors << message
98+
end
7699
end
77100
end
78101

spec/source/acceptor_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ module Pod
44
describe Source::Acceptor do
55

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

61+
it "doesn't fail if the new source of the specification is a redirect" do
62+
@spec.source = { :git => 'http://NEW-URL/banana-lib.git', :tag => 'v1.0' }
63+
errors = @sut.analyze(@spec).join("\n")
64+
errors.should.not.match /The source of the spec doesn't match/
65+
end
66+
5567
it 'rejects a Git based specification without tag if there is at least one tagged version' do
5668
@spec.source = { :git => 'http://banana-corp.local/banana-lib.git', :commit => 'SHA' }
5769
errors = @sut.analyze(@spec).join("\n")

0 commit comments

Comments
 (0)