Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: CocoaPods/Core
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 13f4303becec31b91aa2fa2843eb4694070e3c28
Choose a base ref
..
head repository: CocoaPods/Core
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f7675b5a4863254f4eabe330dbd6030fd530da5a
Choose a head ref
Showing with 90 additions and 29 deletions.
  1. +1 −1 lib/cocoapods-core/cdn_source.rb
  2. +38 −17 lib/cocoapods-core/source/manager.rb
  3. +51 −11 spec/source/manager_spec.rb
2 changes: 1 addition & 1 deletion lib/cocoapods-core/cdn_source.rb
Original file line number Diff line number Diff line change
@@ -371,7 +371,7 @@ def download_and_save_with_retries_async(partial_url, file_remote_url, etag, ret

download_task = download_typhoeus_impl_async(file_remote_url, etag).then do |response|
case response.response_code
when 301
when 301, 302
redirect_location = response.headers['location']
debug "CDN: #{name} Redirecting from #{file_remote_url} to #{redirect_location}"
download_and_save_with_retries_async(partial_url, redirect_location, etag)
55 changes: 38 additions & 17 deletions lib/cocoapods-core/source/manager.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'public_suffix'

module Pod
class Source
class Manager
@@ -412,12 +414,12 @@ def canonic_url(url)
# @example A non-Github.com URL
#
# name_for_url('https://sourceforge.org/Artsy/Specs.git')
# # sourceforge-artsy-specs
# # sourceforge-artsy
#
# @example A file URL
#
# name_for_url('file:///Artsy/Specs.git')
# # artsy-specs
# # artsy
#
# @param [#to_s] url
# The URL of the source.
@@ -427,33 +429,52 @@ def canonic_url(url)
def name_for_url(url)
base_from_host_and_path = lambda do |host, path|
if host && !host.empty?
base = host.split('.')[-2] || host
base += '-'
domain = PublicSuffix.parse(host) rescue nil
base = [domain&.sld || host]
base = [] if base == %w(github)
else
base = ''
base = []
end

base + path.gsub(/.git$/, '').gsub(%r{^/}, '').split('/').join('-')
path = path.gsub(/.git$/, '').gsub(%r{^/}, '').split('/')
path.pop if path.last == 'specs'

(base + path).join('-')
end

valid_url = lambda do |url|
url =~ URI.regexp && (URI(url) rescue false)
end

valid_scp_url = lambda do |url|
valid_url['scp://' + url]
end

case url.to_s.downcase
url = url.to_s.downcase

case url
when %r{https://#{Regexp.quote(trunk_repo_hostname)}}i
# Main CDN repo
base = Pod::TrunkSource::TRUNK_REPO_NAME
when %r{github.com[:/]+(.+)/(.+)}
base = Regexp.last_match[1]
when %r{^\S+@(\S+)[:/]+(.+)$}
host, path = Regexp.last_match.captures
base = base_from_host_and_path[host, path]
when URI.regexp
url = URI(url.downcase)
when valid_url
# HTTPS URL or something similar
url = valid_url[url]
base = base_from_host_and_path[url.host, url.path]
when valid_scp_url
# SCP-style URLs for private git repos
url = valid_scp_url[url]
base = base_from_host_and_path[url.host, url.path]
when %r{(?:git|ssh|https?|git@([-\w.]+)):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$}i
# Additional SCP-style URLs for private git repos
host, _, path = Regexp.last_match.captures
base = base_from_host_and_path[host, path]
else
base = url.to_s.downcase
# This is nearly impossible, with all the previous cases
raise Informative, "Couldn't determine repo name for URL: #{url}"
end

name = base
infinity = 1.0 / 0
(1..infinity).each do |i|
(1..).each do |i|
break unless source_dir(name).exist?
name = "#{base}-#{i}"
end
62 changes: 51 additions & 11 deletions spec/source/manager_spec.rb
Original file line number Diff line number Diff line change
@@ -198,29 +198,61 @@ module Pod
@sources_manager.send(:name_for_url, url).should == 'trunk'
end

it 'uses the organization name for github.com URLs' do
it 'uses the organization and repo name for github.com URLs' do
url = 'https://github.com/segiddins/banana.git'
@sources_manager.send(:name_for_url, url).should == 'segiddins-banana'
end

it 'uses the organization name only for github.com specs URLs' do
url = 'https://github.com/segiddins/Specs.git'
@sources_manager.send(:name_for_url, url).should == 'segiddins'
end

it 'uses a combination of host and path for other URLs' do
url = 'https://sourceforge.org/Artsy/Specs.git'
@sources_manager.send(:name_for_url, url).
should == 'sourceforge-artsy-specs'
should == 'sourceforge-artsy'
url = 'https://sourceforge.org.au/Artsy/Specs.git'
@sources_manager.send(:name_for_url, url).
should == 'sourceforge-artsy'
url = 'https://pvt.sourceforge.org.au/Artsy/Specs.git'
@sources_manager.send(:name_for_url, url).
should == 'sourceforge-artsy'
end

it 'does not remove /specs path component if it is not the last one' do
url = 'https://sourceforge.org.au/Specs/Path/Repo.git'
@sources_manager.send(:name_for_url, url).should == 'sourceforge-specs-path-repo'
end

it 'can understand arbitrary URI schemes' do
url = 'banana://website.org/Artsy/Specs.git'
@sources_manager.send(:name_for_url, url).
should == 'website-artsy'
end

it 'should raise on completely ridiculous non-URL input' do
url = ' '
should.raise Informative do
@sources_manager.send(:name_for_url, url)
end.message.should.== "Couldn't determine repo name for URL: #{url}"
end

it 'supports scp-style URLs' do
url = 'git@git-host.com:specs.git'
@sources_manager.send(:name_for_url, url).
should == 'git-host-specs'
should == 'git-host'

url = 'git@git-host.com/specs.git'
@sources_manager.send(:name_for_url, url).
should == 'git-host-specs'
should == 'git-host'

url = 'git@git-host.com:/specs.git'
@sources_manager.send(:name_for_url, url).
should == 'git-host-specs'
should == 'git-host'
url = 'git@github.com/segiddins/Specs'
@sources_manager.send(:name_for_url, url).
should == 'segiddins'
end

it 'supports ssh URLs with an aliased hostname' do
@@ -230,9 +262,12 @@ module Pod
end

it 'supports file URLs' do
url = 'file:///Users/kurrytran/pod-specs'
url = 'file:///Users/kurrytran/etc'
@sources_manager.send(:name_for_url, url).
should == 'users-kurrytran-pod-specs'
should == 'users-kurrytran-etc'
url = 'file:///Users/kurrytran/specs'
@sources_manager.send(:name_for_url, url).
should == 'users-kurrytran'
end

it 'uses the repo name if no parent directory' do
@@ -244,20 +279,25 @@ module Pod
it 'supports ssh URLs with no user component' do
url = 'ssh://company.com/pods/specs.git'
@sources_manager.send(:name_for_url, url).
should == 'company-pods-specs'
should == 'company-pods'
end

it 'appends a number to the name if the base name dir exists' do
url = 'https://github.com/segiddins/banana.git'
Pathname.any_instance.stubs(:exist?).
returns(true).then.returns(false)
@sources_manager.send(:name_for_url, url).should == 'segiddins-1'
@sources_manager.send(:name_for_url, url).should == 'segiddins-banana-1'

url = 'https://sourceforge.org/Artsy/Specs.git'
Pathname.any_instance.stubs(:exist?).
returns(true).then.returns(false)
@sources_manager.send(:name_for_url, url).
should == 'sourceforge-artsy-specs-1'
@sources_manager.send(:name_for_url, url).should == 'sourceforge-artsy-1'

url = 'https://sourceforge.org/Artsy/Specs.git'
Pathname.any_instance.stubs(:exist?).
returns(true).then.
returns(true).then.returns(false)
@sources_manager.send(:name_for_url, url).should == 'sourceforge-artsy-2'
end
end