-
Notifications
You must be signed in to change notification settings - Fork 22
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
Kintsugi: Avoid adding duplicates if settings don't allow. #76
Kintsugi: Avoid adding duplicates if settings don't allow. #76
Conversation
byohay
commented
Jul 18, 2022
- Kintusgi: Add Settings class.
- Kintsugi: Avoid adding duplicates if settings don't allow.
cd6cb75
to
e2b25c8
Compare
(old_value || []) + (added_change || []) - (removed_change || []) | ||
|
||
new_value = (old_value || []) + (added_change || []) - (removed_change || []) | ||
Settings.allow_duplicates ? new_value : new_value.uniq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use uniq
here, you will also delete duplicates in the old values, which is beyond the mandate given to Kintsugi.
@@ -506,6 +514,11 @@ def add_build_file(build_phase, change, change_path) | |||
return | |||
end | |||
|
|||
duplicate_build_file_exist = build_phase.files.find do |build_file| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate_build_file_exist = build_phase.files.find do |build_file| | |
duplicate_build_file_exists = build_phase.files.find do |build_file| |
@@ -581,6 +594,13 @@ def find_containing_project_uuid(project, container_item_proxy_change) | |||
end | |||
|
|||
def add_subproject_reference(root_object, project_reference_change, change_path) | |||
duplicate_subproject_exist = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate_subproject_exist = | |
duplicate_subproject_exists = |
@@ -649,6 +669,10 @@ def add_file_reference(containing_component, change, change_path) | |||
return | |||
end | |||
|
|||
return if !Settings.allow_duplicates && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also merge duplicate groups
e2b25c8
to
4db7f04
Compare
@ashdnazg round done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
F&S&M
def find_file_in_group(group, filetype, filepath) | ||
group | ||
.children | ||
.select { |child| child.instance_of?(filetype) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why instance_of and not is_a?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because PBXVariantGroup
inherit from PBXGroup
, and I didn't want to treat them as duplicates if they have a different type.
@@ -1400,6 +1380,164 @@ | |||
expect(base_project).to be_equivalent_to_project(theirs_project) | |||
end | |||
|
|||
describe "avoiding duplicate references to the same component" do | |||
it "avoids adding file reference that already exist" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it "avoids adding file reference that already exist" do | |
it "avoids adding file reference that already exists" do |
expect(other_project).to be_equivalent_to_project(base_project) | ||
end | ||
|
||
it "avoids adding group that already exist" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it "avoids adding group that already exist" do | |
it "avoids adding group that already exists" do |
expect(other_project).to be_equivalent_to_project(base_project) | ||
end | ||
|
||
it "avoids adding variant group that already exist" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it "avoids adding variant group that already exist" do | |
it "avoids adding variant group that already exists" do |
expect(other_project).to be_equivalent_to_project(base_project) | ||
end | ||
|
||
it "avoids adding subproject that already exist" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it "avoids adding subproject that already exist" do | |
it "avoids adding subproject that already exists" do |
expect(ours_project.root_object.project_references.count).to equal(1) | ||
end | ||
|
||
it "avoids adding build file that already exist" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it "avoids adding build file that already exist" do | |
it "avoids adding build file that already exists" do |
expect(other_project).to be_equivalent_to_project(base_project) | ||
end | ||
|
||
it "avoids adding reference proxy that already exist" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it "avoids adding reference proxy that already exist" do | |
it "avoids adding reference proxy that already exists" do |
expect(other_project).to be_equivalent_to_project(base_project) | ||
end | ||
|
||
it "keeps array if adding string value that already exist in array" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it "keeps array if adding string value that already exist in array" do | |
it "keeps array if adding string value that already exists in array" do |
e7a71a9
to
0bc1680
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
F&S&M
duplicate_build_file_exists = !build_phase.files.find do |build_file| | ||
build_file.file_ref.path == change["fileRef"]["path"] | ||
end.nil? | ||
return if !Settings.allow_duplicates && duplicate_build_file_exists | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a bit hard to read when the !
is in the beginning and the .nil?
is in the end.
consider
duplicate_build_file_exists = !build_phase.files.find do |build_file| | |
build_file.file_ref.path == change["fileRef"]["path"] | |
end.nil? | |
return if !Settings.allow_duplicates && duplicate_build_file_exists | |
duplicate_build_file = build_phase.files.find do |build_file| | |
build_file.file_ref.path == change["fileRef"]["path"] | |
end | |
return if !Settings.allow_duplicates && !duplicate_build_file.nil? |
same in other places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe existing_build_file
instead of duplicate_build_file
lib/kintsugi/settings.rb
Outdated
# frozen_string_literal: true | ||
|
||
module Kintsugi | ||
# Kintsugi global settings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Kintsugi global settings | |
# Kintsugi global settings. |
0bc1680
to
a58f65b
Compare
The class contains global build settings, e.g. the `allow_duplicates` flag.
a58f65b
to
c978bff
Compare
This setting is relevant to: - File references. - Subprojects - Build files - Array build settings. - Groups and variant groups.
c978bff
to
ed85ff5
Compare