Skip to content

Commit

Permalink
Merge pull request #88 from Lightricks/feature/fix-group-moves
Browse files Browse the repository at this point in the history
  • Loading branch information
byohay authored Sep 12, 2022
2 parents 3d3fad2 + f5622c5 commit fdc1d3c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/kintsugi/apply_change_to_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,17 @@ def apply_group_and_file_diffs(project, diffs)
end

def apply_group_removals(project, removals)
removals.each do |change, path|
removals.sort_by(&:last).reverse.each do |change, path|
next unless %w[PBXGroup PBXVariantGroup].include?(change["isa"])

group_path = join_path(path, change["displayName"])

remove_component(project[group_path], change)
# by now we've deleted all of this group's children in the project, so we need to adapt the
# change to the expected current state of the group, that is, without any children.
change_without_children = change.dup
change_without_children["children"] = []

remove_component(project[group_path], change_without_children)
end
end

Expand Down
49 changes: 49 additions & 0 deletions spec/kintsugi_apply_change_to_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,55 @@
expect(base_project).to be_equivalent_to_project(theirs_project)
end

it "moves a group with files in it" do
new_group = base_project.main_group.find_subpath("new_group", true)
new_group.new_reference("new_file")
base_project.save

theirs_project = create_copy_of_project(base_project.path, "theirs")
new_group2 = theirs_project.main_group.find_subpath("new_group2", true)
theirs_project["new_group"].move(new_group2)

changes_to_apply = get_diff(theirs_project, base_project)

described_class.apply_change_to_project(base_project, changes_to_apply)

expect(base_project).to be_equivalent_to_project(theirs_project)
end

it "moves a group with a group in it" do
new_group = base_project.main_group.find_subpath("new_group", true)
new_group.find_subpath("sub_group", true)
base_project.save

theirs_project = create_copy_of_project(base_project.path, "theirs")
new_group2 = theirs_project.main_group.find_subpath("new_group2", true)
theirs_project["new_group"].move(new_group2)

changes_to_apply = get_diff(theirs_project, base_project)

described_class.apply_change_to_project(base_project, changes_to_apply)

expect(base_project).to be_equivalent_to_project(theirs_project)
end

it "moves a group with a group with a file in it" do
new_group = base_project.main_group.find_subpath("new_group", true)
sub_group = new_group.find_subpath("sub_group", true)
sub_group.new_reference("new_file")
base_project.save

theirs_project = create_copy_of_project(base_project.path, "theirs")
new_group2 = theirs_project.main_group.find_subpath("new_group2", true)
theirs_project["new_group"].move(new_group2)

changes_to_apply = get_diff(theirs_project, base_project)

described_class.apply_change_to_project(base_project, changes_to_apply)

expect(base_project).to be_equivalent_to_project(theirs_project)
end

it "adds file with include in index and last known file type as nil" do
theirs_project = create_copy_of_project(base_project.path, "theirs")
file_reference = theirs_project.main_group.new_reference("#{filepath}.h")
Expand Down

0 comments on commit fdc1d3c

Please sign in to comment.