Module: Kintsugi
- Defined in:
- lib/kintsugi.rb,
lib/kintsugi/apply_change_to_project.rb
Class Method Summary collapse
-
.apply_change_to_project(project, change) ⇒ void
Applies the change specified by
changetoproject. -
.resolve_conflicts(project_file_path, changes_output_path) ⇒ void
Resolves git conflicts of a pbxproj file specified by
project_file_path.
Class Method Details
.apply_change_to_project(project, change) ⇒ void
This method returns an undefined value.
Applies the change specified by change to project.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kintsugi/apply_change_to_project.rb', line 23 def apply_change_to_project(project, change) # We iterate over the main group and project references first because they might create file # or project references that are referenced in other parts. unless change["rootObject"]["mainGroup"].nil? if project.root_object.main_group.nil? puts "Warning: Main group doesn't exist, ignoring changes to it." else apply_change_to_component(project.root_object, "mainGroup", change["rootObject"]["mainGroup"]) end end unless change["rootObject"]["projectReferences"].nil? apply_change_to_component(project.root_object, "projectReferences", change["rootObject"]["projectReferences"]) end apply_change_to_component(project, "rootObject", change["rootObject"].reject { |key| %w[mainGroup projectReferences].include?(key) }) end |
.resolve_conflicts(project_file_path, changes_output_path) ⇒ void
This method returns an undefined value.
Resolves git conflicts of a pbxproj file specified by project_file_path.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/kintsugi.rb', line 30 def resolve_conflicts(project_file_path, changes_output_path) validate_project(project_file_path) project_in_temp_directory = open_project_of_current_commit_in_temporary_directory(project_file_path) change = change_of_conflicting_commit_with_parent(project_file_path) if changes_output_path File.write(changes_output_path, JSON.pretty_generate(change)) end apply_change_to_project(project_in_temp_directory, change) project_in_temp_directory.save Dir.chdir(File.dirname(project_file_path)) do `git reset #{project_file_path}` end FileUtils.cp(File.join(project_in_temp_directory.path, "project.pbxproj"), project_file_path) # Some of the metadata in a `pbxproj` file include a part of the name of the directory it's # inside. The modified project is stored in a temporary directory and then copied to the # original path, therefore its metadata is incorrect. To fix this, the project at the original # path is opened and saved. Xcodeproj::Project.open(File.dirname(project_file_path)).save end |