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

apply change: Fix adding component with non default simple attributes. #67

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/kintsugi/apply_change_to_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,11 @@ def add_attributes_to_component(component, change, change_path, ignore_keys: [])

attribute_name = attribute_name_from_change_name(change_name)
if simple_attribute?(component, attribute_name)
apply_change_to_simple_attribute(component, attribute_name, {added: change_value})
simple_attribute_change = {
added: change_value,
removed: simple_attribute_default_value(component, attribute_name)
}
apply_change_to_simple_attribute(component, attribute_name, simple_attribute_change)
next
end

Expand All @@ -694,6 +698,12 @@ def add_attributes_to_component(component, change, change_path, ignore_keys: [])
end
end

def simple_attribute_default_value(component, attribute_name)
component.simple_attributes.find do |attribute|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awful, but it's probably not worth using private API

attribute.name == attribute_name
end.default_value
end

def find_file(project, file_reference_change, file_filter: ->(_) { true })
file_references = project.files.select do |file_reference|
file_reference.path == file_reference_change["path"] && file_filter.call(file_reference)
Expand Down
14 changes: 14 additions & 0 deletions spec/kintsugi_apply_change_to_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,20 @@
expect(base_project).to be_equivalent_to_project(theirs_project)
end

it "adds build phase with a simple attribute value that has non nil default" do
theirs_project = create_copy_of_project(base_project.path, "theirs")

theirs_project.targets[0].new_shell_script_build_phase("bar")
theirs_project.targets[0].build_phases.last.shell_script = "Other value"

changes_to_apply = get_diff(theirs_project, base_project)

described_class.apply_change_to_project(base_project, changes_to_apply)
base_project.save

expect(base_project).to be_equivalent_to_project(theirs_project)
end

it "removes build phase" do
base_project.targets[0].new_shell_script_build_phase("bar")

Expand Down