Commit 5b9704f6 authored by Samuel E. Giddins's avatar Samuel E. Giddins

[SourcesManager] More robust generation of source names from URLs

parent d6e438d1
......@@ -11,6 +11,10 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
[Boris Bügling](https://github.com/neonichu)
[#2542](https://github.com/CocoaPods/CocoaPods/issues/2542)
* More robust generation of source names from URLs.
[Samuel Giddins](https://github.com/segiddins)
[#2534](https://github.com/CocoaPods/CocoaPods/issues/2534)
## 0.34.1
......
......@@ -405,18 +405,27 @@ module Pod
# @return [String] A suitable repository name for `url`.
#
def name_for_url(url)
case url.downcase
base_from_host_and_path = lambda do |host, path|
base = host.split('.')[-2] || host
base += '-' + path.gsub(/.git$/, '').gsub(/^\//, '').
split('/').join('-')
end
case url.to_s.downcase
when %r{github.com(:|/)cocoapods/specs}
base = 'master'
when %r{github.com(:|/)(.+)/(.+)}
base = Regexp.last_match[2]
else
raise Informative,
"`#{url}` is not a valid URL." unless url =~ URI.regexp
when URI.regexp
url = URI(url.downcase)
base = url.host.split('.')[-2] +
url.path.gsub(/.git$/, '').split('/').join('-')
base = base_from_host_and_path[url.host, url.path]
when %r{^\S+@(\S+)[:/](.+)$}
host, path = Regexp.last_match.captures
base = base_from_host_and_path[host, path]
else
url.to_s.downcase
end
name = base
infinity = 1.0 / 0
(1..infinity).each do |i|
......
......@@ -127,6 +127,24 @@ module Pod
should == 'sourceforge-artsy-specs'
end
it 'supports scp-style URLs' do
url = 'git@git-host.com/specs.git'
SourcesManager.send(:name_for_url, url).
should == 'git-host-specs'
end
it 'supports ssh URLs with an aliased hostname' do
url = 'ssh://user@companyalias/pod-specs'
SourcesManager.send(:name_for_url, url).
should == 'companyalias-pod-specs'
end
it 'supports ssh URLs with no user component' do
url = 'ssh://company.com/pods/specs.git'
SourcesManager.send(:name_for_url, url).
should == 'company-pods-specs'
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?).
......
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