Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add group to have correct parent set #614

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Next

### Fixed

- Adding group set incorrect parent in case of complex path [#614](https://github.com/tuist/XcodeProj/pull/614) by [@avdyushin](https://github.com/avdyushin)

## 7.23.0 - Bonsai
### Added

Expand Down
2 changes: 1 addition & 1 deletion Sources/XcodeProj/Objects/Files/PBXGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public extension PBXGroup {
return groupName.components(separatedBy: "/").reduce(into: [PBXGroup]()) { groups, name in
let group = groups.last ?? self
let newGroup = PBXGroup(children: [], sourceTree: .group, name: name, path: options.contains(.withoutFolder) ? nil : name)
newGroup.parent = self
newGroup.parent = group
group.childrenReferences.append(newGroup.reference)
objects.add(object: newGroup)
groups.append(newGroup)
Expand Down
16 changes: 16 additions & 0 deletions Tests/XcodeProjTests/Objects/Files/PBXGroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ final class PBXGroupTests: XCTestCase {
XCTAssertNotNil(childGroup?.parent)
}

func test_addGroup_assignAllParents() {
let project = makeEmptyPBXProj()
let group = PBXGroup(children: [],
sourceTree: .group,
name: "group")
project.add(object: group)

let expectGroups = ["foo", "bar", "baz"]
let createdGroups = try? group.addGroup(named: expectGroups.joined(separator: "/"))

XCTAssertEqual(3, createdGroups?.count)
XCTAssertEqual(createdGroups?[0].parent?.name, "group")
XCTAssertEqual(createdGroups?[1].parent?.name, "foo")
XCTAssertEqual(createdGroups?[2].parent?.name, "bar")
}

func test_addVariantGroup() {
let project = makeEmptyPBXProj()
let group = PBXGroup(children: [],
Expand Down