kintsugi 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d58044d1f7c23e62f290c33defa4d9b3e95c0012b62754997a7c628d96e4358
4
- data.tar.gz: 6d63f1e0cf56c131fe7222c9d316f4f152310077fa2a9f4e386fba54ab82a340
3
+ metadata.gz: 8ebc10e7941cd3b92850cefb1d5fc0d0046b178b0b3e6bdc929833ff9474302f
4
+ data.tar.gz: 5cddf2267408f4361862e68f7391783626c6bf7f536962d0c0021b559c0cc637
5
5
  SHA512:
6
- metadata.gz: 1aa18d3fd3456e1aa44f6497bc3e2f4e4877836e8722887050725012591e43b0086efa490df8eab8f1b63800f900897365a81c87935fb68341b1727e4c432e99
7
- data.tar.gz: f8aa152a98e35b9620a3c855eb010781a7fb65e843c6323ea4d14fb27ba414416c2e585273f797e0d8698dfae67d9f7a963e626cc2a2f40ca0d6cce0707cfc0d
6
+ metadata.gz: b052e5047b603307043b708d804678094ac38ee4e392a3de1d5f94b1ca37a552ff5999320a1168f976f803620cb2072e44712dd49a6fc87d929e666248b64ccf
7
+ data.tar.gz: 213fea0a670e021ae68dae8669e216da4fc19039e71e059e6c33b57adbc753ae824e28d1a5d6b806527215b057a8fd354481c8772794337d73daa88e6c884300
data/.rubocop.yml CHANGED
@@ -6,6 +6,9 @@ RSpec/ExampleLength:
6
6
  RSpec/DescribeClass:
7
7
  Enabled: false
8
8
 
9
+ RSpec/MultipleExpectations:
10
+ Enabled: false
11
+
9
12
  AllCops:
10
13
  DisplayCopNames: true
11
14
  TargetRubyVersion: 2.5
data/Gemfile CHANGED
@@ -2,5 +2,3 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
  gemspec
5
- gem "ruby-debug-ide", "0.7.2"
6
- gem "debase", "0.2.5.beta2"
@@ -266,6 +266,8 @@ module Kintsugi
266
266
  case change["isa"]
267
267
  when "PBXNativeTarget"
268
268
  add_target(component, change)
269
+ when "PBXAggregateTarget"
270
+ add_aggregate_target(component, change)
269
271
  when "PBXFileReference"
270
272
  add_file_reference(component, change)
271
273
  when "PBXGroup"
@@ -307,7 +309,22 @@ module Kintsugi
307
309
  def add_reference_proxy(containing_component, change)
308
310
  case containing_component
309
311
  when Xcodeproj::Project::PBXBuildFile
310
- containing_component.file_ref = find_file(containing_component.project, change)
312
+ # If there are two file references that refer to the same file, one with a build file and
313
+ # the other one without, this method will prefer to take the one without the build file.
314
+ # This assumes that it's preferred to have a file reference with build file than a file
315
+ # reference without/with two build files.
316
+ filter_references_without_build_files = lambda do |reference|
317
+ reference.referrers.find do |referrer|
318
+ referrer.is_a?(Xcodeproj::Project::PBXBuildFile)
319
+ end.nil?
320
+ end
321
+ file_reference =
322
+ find_reference_proxy(containing_component.project, change["remoteRef"],
323
+ reference_filter: filter_references_without_build_files)
324
+ if file_reference.nil?
325
+ file_reference = find_reference_proxy(containing_component.project, change["remoteRef"])
326
+ end
327
+ containing_component.file_ref = file_reference
311
328
  when Xcodeproj::Project::PBXGroup
312
329
  reference_proxy = containing_component.project.new(Xcodeproj::Project::PBXReferenceProxy)
313
330
  containing_component << reference_proxy
@@ -459,7 +476,14 @@ module Kintsugi
459
476
  end
460
477
 
461
478
  def add_subproject_reference(root_object, project_reference_change)
462
- subproject_reference = find_file(root_object.project, project_reference_change["ProjectRef"])
479
+ filter_subproject_without_project_references = lambda do |file_reference|
480
+ root_object.project_references.find do |project_reference|
481
+ project_reference.project_ref.uuid == file_reference.uuid
482
+ end.nil?
483
+ end
484
+ subproject_reference =
485
+ find_file(root_object.project, project_reference_change["ProjectRef"],
486
+ file_filter: filter_subproject_without_project_references)
463
487
 
464
488
  attribute =
465
489
  Xcodeproj::Project::PBXProject.references_by_keys_attributes
@@ -489,6 +513,12 @@ module Kintsugi
489
513
  add_attributes_to_component(target, change)
490
514
  end
491
515
 
516
+ def add_aggregate_target(root_object, change)
517
+ target = root_object.project.new(Xcodeproj::Project::PBXAggregateTarget)
518
+ root_object.project.targets << target
519
+ add_attributes_to_component(target, change)
520
+ end
521
+
492
522
  def add_file_reference(containing_component, change)
493
523
  # base configuration reference and product reference always reference a file that exists
494
524
  # inside a group, therefore in these cases the file is searched for.
@@ -556,25 +586,29 @@ module Kintsugi
556
586
  end
557
587
  end
558
588
 
559
- def find_file(project, file_reference_change)
560
- case file_reference_change["isa"]
561
- when "PBXFileReference"
562
- project.files.find do |file_reference|
563
- next file_reference.path == file_reference_change["path"]
564
- end
565
- when "PBXReferenceProxy"
566
- find_reference_proxy(project, file_reference_change["remoteRef"])
567
- else
568
- raise "Unsupported file reference change of type #{file_reference["isa"]}."
589
+ def find_file(project, file_reference_change, file_filter: ->(_) { true })
590
+ file_references = project.files.select do |file_reference|
591
+ file_reference.path == file_reference_change["path"] && file_filter.call(file_reference)
569
592
  end
593
+ if file_references.length > 1
594
+ puts "Debug: Found more than one matching file with path " \
595
+ "'#{file_reference_change["path"]}'. Using the first one."
596
+ elsif file_references.empty?
597
+ puts "Debug: No file reference found for file with path " \
598
+ "'#{file_reference_change["path"]}'."
599
+ return
600
+ end
601
+
602
+ file_references.first
570
603
  end
571
604
 
572
- def find_reference_proxy(project, container_item_proxy_change)
605
+ def find_reference_proxy(project, container_item_proxy_change, reference_filter: ->(_) { true })
573
606
  reference_proxies = project.root_object.project_references.map do |project_ref_and_products|
574
607
  project_ref_and_products[:product_group].children.find do |product|
575
608
  product.remote_ref.remote_global_id_string ==
576
609
  container_item_proxy_change["remoteGlobalIDString"] &&
577
- product.remote_ref.remote_info == container_item_proxy_change["remoteInfo"]
610
+ product.remote_ref.remote_info == container_item_proxy_change["remoteInfo"] &&
611
+ reference_filter.call(product)
578
612
  end
579
613
  end.compact
580
614
 
@@ -3,6 +3,6 @@
3
3
  module Kintsugi
4
4
  # This module holds the Kintsugi version information.
5
5
  module Version
6
- STRING = "0.2.0"
6
+ STRING = "0.3.0"
7
7
  end
8
8
  end
data/lib/kintsugi.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  # Created by Ben Yohay.
3
3
  # frozen_string_literal: true
4
4
 
5
+ require "json"
5
6
  require "tmpdir"
6
7
  require "tempfile"
7
8
  require "xcodeproj"
@@ -16,7 +17,7 @@ module Kintsugi
16
17
  # @param [String] project_file_path
17
18
  # Project to which to apply the changes.
18
19
  #
19
- # @param [String] output_changes_path
20
+ # @param [String] changes_output_path
20
21
  # Path to where the changes to apply to the project are written in JSON format.
21
22
  #
22
23
  # @raise [ArgumentError]
@@ -38,6 +38,18 @@ describe Kintsugi, :apply_change_to_project do
38
38
  expect(base_project).to be_equivalent_to_project(theirs_project)
39
39
  end
40
40
 
41
+ it "adds new aggregate target" do
42
+ theirs_project = create_copy_of_project(base_project.path, "theirs")
43
+ theirs_project.new_aggregate_target("foo")
44
+
45
+ changes_to_apply = get_diff(theirs_project, base_project)
46
+
47
+ described_class.apply_change_to_project(base_project, changes_to_apply)
48
+ base_project.save
49
+
50
+ expect(base_project).to be_equivalent_to_project(theirs_project)
51
+ end
52
+
41
53
  it "adds new subproject" do
42
54
  theirs_project = create_copy_of_project(base_project.path, "theirs")
43
55
  add_new_subproject_to_project(theirs_project, "foo", "foo")
@@ -50,6 +62,26 @@ describe Kintsugi, :apply_change_to_project do
50
62
  expect(base_project).to be_equivalent_to_project(theirs_project, ignore_keys: ["containerPortal"])
51
63
  end
52
64
 
65
+ it "adds subproject that already exists" do
66
+ theirs_project = create_copy_of_project(base_project.path, "theirs")
67
+
68
+ subproject = add_new_subproject_to_project(theirs_project, "foo", "foo")
69
+ theirs_project.save
70
+
71
+ ours_project = create_copy_of_project(base_project.path, "ours")
72
+ add_existing_subproject_to_project(ours_project, subproject, "foo")
73
+
74
+ changes_to_apply = get_diff(theirs_project, base_project)
75
+
76
+ described_class.apply_change_to_project(ours_project, changes_to_apply)
77
+ ours_project.save
78
+
79
+ expect(ours_project.root_object.project_references[0][:project_ref].uuid)
80
+ .not_to equal(ours_project.root_object.project_references[1][:project_ref].uuid)
81
+ expect(ours_project.root_object.project_references[0][:project_ref].proxy_containers).not_to be_empty
82
+ expect(ours_project.root_object.project_references[1][:project_ref].proxy_containers).not_to be_empty
83
+ end
84
+
53
85
  # Checks that the order the changes are applied in is correct.
54
86
  it "adds new subproject and reference to its framework" do
55
87
  theirs_project = create_copy_of_project(base_project.path, "theirs")
@@ -417,6 +449,30 @@ describe Kintsugi, :apply_change_to_project do
417
449
  expect(base_project).to be_equivalent_to_project(theirs_project, ignore_keys: ["containerPortal"])
418
450
  end
419
451
 
452
+ it "adds build file to a file reference that already exist" do
453
+ file_reference = base_project.main_group.new_reference("bar")
454
+ base_project.targets[0].frameworks_build_phase.add_file_reference(file_reference)
455
+
456
+ base_project.main_group.new_reference("bar")
457
+
458
+ base_project.save
459
+
460
+ theirs_project = create_copy_of_project(base_project.path, "theirs")
461
+
462
+ theirs_file_reference = theirs_project.main_group.files.find do |file|
463
+ !file.referrers.find { |referrer| referrer.is_a?(Xcodeproj::Project::PBXBuildFile) } &&
464
+ file.display_name == "bar"
465
+ end
466
+ theirs_project.targets[0].frameworks_build_phase.add_file_reference(theirs_file_reference)
467
+
468
+ changes_to_apply = get_diff(theirs_project, base_project)
469
+
470
+ described_class.apply_change_to_project(base_project, changes_to_apply)
471
+ base_project.save
472
+
473
+ expect(base_project).to be_equivalent_to_project(theirs_project)
474
+ end
475
+
420
476
  it "adds file reference to build file" do
421
477
  file_reference = base_project.main_group.new_reference("bar")
422
478
 
@@ -789,7 +845,7 @@ describe Kintsugi, :apply_change_to_project do
789
845
  expect(ours_project).to be_equivalent_to_project(theirs_project)
790
846
  end
791
847
 
792
- it "identifies subproject added in separate times" do
848
+ it "identifies subproject added at separate times when adding a product to the subproject" do
793
849
  framework_filename = "baz"
794
850
 
795
851
  subproject = new_subproject("subproj", framework_filename)
@@ -870,10 +926,10 @@ describe Kintsugi, :apply_change_to_project do
870
926
  file_reference.path == subproject_product_name
871
927
  end.remove_from_project
872
928
 
873
- project.root_object.project_references[0][:product_group] =
929
+ project.root_object.project_references[-1][:product_group] =
874
930
  project.new(Xcodeproj::Project::PBXGroup)
875
- project.root_object.project_references[0][:product_group].name = "Products"
876
- project.root_object.project_references[0][:product_group] <<
931
+ project.root_object.project_references[-1][:product_group].name = "Products"
932
+ project.root_object.project_references[-1][:product_group] <<
877
933
  create_reference_proxy_from_product_reference(project, subproject_reference,
878
934
  subproject.products_group.files[0])
879
935
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kintsugi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Yohay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-20 00:00:00.000000000 Z
11
+ date: 2021-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj
@@ -143,7 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.1.2
146
+ rubyforge_project:
147
+ rubygems_version: 2.7.3
147
148
  signing_key:
148
149
  specification_version: 4
149
150
  summary: pbxproj files git conflicts solver