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_to_project: Raise on project reference without file. #52

Merged
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
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