Skip to content

Commit

Permalink
apply_change_to_project: Fix removal of simple value that's nil already.
Browse files Browse the repository at this point in the history
If the applied change removed a value and the existing value is
different from the removed value, it is considered a conflict.
However, this is not true in the case the existing value was already
removed.

In addition, improve messages in case of real conflicts when dealing
with removal of simple attributes.
  • Loading branch information
byohay committed Jul 11, 2021
1 parent e2876cf commit 0a07723
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/kintsugi/apply_change_to_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,15 @@ def apply_removal_to_simple_attribute(old_value, change)
(old_value || {}).reject do |key, value|
if value != change[key]
raise "Trying to remove value #{change[key]} of hash with key #{key} but it changed " \
"to #{value}."
"to #{value}. This is considered a conflict that should be resolved manually."
end

change.key?(key)
end
when String
if old_value != change
raise "Value changed from #{old_value} to #{change}."
if old_value != change && !old_value.nil?
raise "Trying to remove value #{change}, but the existing value is #{old_value}. This " \
"is considered a conflict that should be resolved manually."
end

nil
Expand All @@ -218,7 +219,7 @@ def apply_addition_to_simple_attribute(old_value, change)
new_value = old_value.merge(change)

unless (old_value.to_a - new_value.to_a).empty?
raise "New hash #{change} contains values that conflict with old hash #{old_value}"
raise "New hash #{change} contains values that conflicts with old hash #{old_value}"
end

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

it "removes attribute target changes from a project it was removed from already" do
base_project.root_object.attributes["TargetAttributes"] =
{"foo" => {"LastSwiftMigration" => "1140"}}
base_project.save

theirs_project = create_copy_of_project(base_project.path, "theirs")
theirs_project.root_object.attributes["TargetAttributes"]["foo"] = {}

ours_project = create_copy_of_project(base_project.path, "ours")
ours_project.root_object.attributes["TargetAttributes"]["foo"] = {}

changes_to_apply = get_diff(theirs_project, base_project)

described_class.apply_change_to_project(ours_project, changes_to_apply)
ours_project.save

expect(ours_project).to be_equivalent_to_project(theirs_project)
end

it "identifies subproject added in separate times" do
framework_filename = "baz"

Expand Down

0 comments on commit 0a07723

Please sign in to comment.