CocoaPods / Xcodeproj

Create and modify Xcode projects from Ruby.

Home Page:http://rubygems.org/gems/xcodeproj

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Project diff returns unexpected result when project references differ.

byohay opened this issue · comments

When the difference between the projects contains project references, the project_diff returns unexpected results:

        project_1 = {
          'projectReferences' => [
            {
              'ProductGroup' => {
                'displayName' => 'Products',
                'isa' => 'PBXGroup',
                'sourceTree' => '<group>',
                'name' => 'Products',
                'children' => []
              },
              'ProjectRef' => {
                'displayName' => 'Foo.xcodeproj',
                'isa' => 'PBXFileReference',
                'name' => 'Foo.xcodeproj',
                'path' => '../Foo/Foo.xcodeproj',
                'sourceTree' => '<group>',
                'lastKnownFileType' => 'wrapper.pb-project'
              }
            }
          ]
        }

        project_2 = {
          'projectReferences' => [
            {
              'ProductGroup' => {
                'displayName' => 'Products',
                'isa' => 'PBXGroup',
                'sourceTree' => '<group>',
                'name' => 'Products',
                'children' => []
              },
              'ProjectRef' => {
                'displayName' => 'Bar.xcodeproj',
                'isa' => 'PBXFileReference',
                'name' => 'Bar.xcodeproj',
                'path' => '../Bar/Bar.xcodeproj',
                'sourceTree' => '<group>',
                '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. This assumes that the elements are homogenous, which I'm not sure is true. Does that sound reasonable?

yes it does! can you make a PR and add tests?