Skip to content

Commit

Permalink
Merge pull request #52 from byohay/feature/raise-project-reference-wi…
Browse files Browse the repository at this point in the history
…thout-file
  • Loading branch information
byohay committed Mar 8, 2022
2 parents 95fd04c + f718d7f commit 508276a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/kintsugi/apply_change_to_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,12 @@ def add_subproject_reference(root_object, project_reference_change)
find_file(root_object.project, project_reference_change["ProjectRef"],
file_filter: filter_subproject_without_project_references)

unless subproject_reference
raise MergeError, "No file reference was found for project reference with change " \
"#{project_reference_change}. This might mean that the file used to exist in the " \
"project the but was removed at some point"
end

attribute =
Xcodeproj::Project::PBXProject.references_by_keys_attributes
.find { |attrb| attrb.name == :project_references }
Expand Down
18 changes: 18 additions & 0 deletions spec/kintsugi_apply_change_to_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require "tempfile"
require "tmpdir"

require "kintsugi/error"
require "kintsugi/apply_change_to_project"

require_relative "be_equivalent_to_project"
Expand Down Expand Up @@ -114,6 +115,23 @@
expect(base_project).to be_equivalent_to_project(theirs_project, ignore_keys: ["containerPortal"])
end

it "raises if adding subproject whose file reference isn't found" do
ours_project = create_copy_of_project(base_project.path, "ours")

add_new_subproject_to_project(base_project, "foo", "foo")
base_project.save

theirs_project = create_copy_of_project(base_project.path, "theirs")

base_project.root_object.project_references.pop

changes_to_apply = get_diff(theirs_project, base_project)

expect {
described_class.apply_change_to_project(ours_project, changes_to_apply)
}.to raise_error(Kintsugi::MergeError)
end

describe "file related changes" do
let(:filepath) { "foo" }

Expand Down

0 comments on commit 508276a

Please sign in to comment.