diff --git a/lib/cocoapods-core/lockfile.rb b/lib/cocoapods-core/lockfile.rb index 6ef672b7..86f7ee48 100644 --- a/lib/cocoapods-core/lockfile.rb +++ b/lib/cocoapods-core/lockfile.rb @@ -485,7 +485,8 @@ def generate_dependencies_data(podfile) # { "https://github.com/cocoapods/cocoapods.git" => ["Alamofire", "Moya"] } # def generate_spec_repos(spec_repos) - Hash[spec_repos.map do |source, specs| + output = Hash.new {|h, k| h[k] = Array.new(0)} + spec_repos.each do |source, specs| next unless source next if specs.empty? key = source.url || source.name @@ -493,9 +494,18 @@ def generate_spec_repos(spec_repos) # save `trunk` as 'trunk' so that the URL itself can be changed without lockfile churn key = Pod::TrunkSource::TRUNK_REPO_NAME if source.name == Pod::TrunkSource::TRUNK_REPO_NAME - value = specs.map { |s| s.root.name }.uniq - [key, YAMLHelper.sorted_array(value)] - end.compact] + value = specs.map { |s| s.root.name } + + if output.has_key?(key) + value = value + output[key] + end + + if value.length > 0 + output[key] = YAMLHelper.sorted_array(value.uniq) + end + end + + output.compact end # Generates the information of the external sources. diff --git a/spec/lockfile_spec.rb b/spec/lockfile_spec.rb index 91480997..00036fe9 100644 --- a/spec/lockfile_spec.rb +++ b/spec/lockfile_spec.rb @@ -617,6 +617,39 @@ def self.specs_by_source spec_repos_data.should == { 'trunk' => %w(a b C) } end end + + describe '#generate_spec_repos_with_duplicated_source' do + it 'merges specs if sources have same key' do + spec_repos = { + Source.new(fixture('spec-repos/trunk')) => [ + Specification.new do |s| + s.name = 'a' + s.version = '1.0' + end, + Specification.new do |s| + s.name = 'b' + s.version = '1.0' + end, + Specification.new do |s| + s.name = 'C' + s.version = '1.0' + end, + ], + Source.new(fixture('spec-repos/trunk')) => [ + Specification.new do |s| + s.name = 'd' + s.version = '1.0' + end, + Specification.new do |s| + s.name = 'E' + s.version = '1.0' + end, + ], + } + spec_repos_data = Lockfile.send(:generate_spec_repos, spec_repos) + spec_repos_data.should == { 'trunk' => %w(a b C d E) } + end + end end end end