CocoaPods / CocoaPods/Xcodeproj
Project diff returns unexpected result when project references differ.
- Dominant language
- Ruby
- Stars
- 2.4k
- Forks
- 488
- PR merge metrics
- No merged PRs in 30d
Description
When the difference between the projects contains project references, the `project_diff` returns unexpected results:
```ruby
project_1 = {
'projectReferences' => [
{
'ProductGroup' => {
'displayName' => 'Products',
'isa' => 'PBXGroup',
'sourceTree' => '',
'name' => 'Products',
'children' => []
},
'ProjectRef' => {
'displayName' => 'Foo.xcodeproj',
'isa' => 'PBXFileReference',
'name' => 'Foo.xcodeproj',
'path' => '../Foo/Foo.xcodeproj',
'sourceTree' => '',
'lastKnownFileType' => 'wrapper.pb-project'
}
}
]
}
project_2 = {
'projectReferences' => [
{
'ProductGroup' => {
'displayName' => 'Products',
'isa' => 'PBXGroup',
'sourceTree' => '',
'name' => 'Products',
'children' => []
},
'ProjectRef' => {
'displayName' => 'Bar.xcodeproj',
'isa' => 'PBXFileReference',
'name' => 'Bar.xcodeproj',
'path' => '../Bar/Bar.xcodeproj',
'sourceTree' => '',
'lastKnownFileType' => 'wrapper.pb-project'
}
}
]
}
diff = Differ.project_diff(project_1, project_2)
# diff:
# "projectReferences" => {
# nil => {
# "ProjectRef" => {
# "displayName" => {
# "project_1" => "Foo.xcodeproj",
# "project_2"=> "Bar.xcodeproj"
# },
# "name" => {
# "project_1" => "Foo.xcodeproj",
# "project_2" => "Bar.xcodeproj"
# },
# "path" => {
# "project_1"=> "../Foo/Foo.xcodeproj",
# "project_2"=> "../Bar/Bar.xcodeproj"
# }
# }
# }
# }
```
I narrowed down the problem to `array_diff`. The problem is that the options it receives contains `displayName` that is passed down to it from `project_diff`. But the hash elements in the array doesn't contain `displayName` in the case of project references.
It seems to me that the solution is to check in `array_diff` if the first hash element in both values contain the given key, and add this check to [this line](https://github.com/CocoaPods/Xcodeproj/blob/master/lib/xcodeproj/differ.rb#L121). This assumes that the elements are homogenous, which I'm not sure is true. Does that sound reasonable?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in lib/xcodeproj/differ.rb around line 121 and trace how project_diff passes options into array_diff. Reproduce the supplied projectReferences example and inspect how the missing displayName key affects matching. Done means project_diff reports the differing project references without grouping them under nil.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100