Module: Kintsugi

Defined in:
lib/kintsugi.rb,
lib/kintsugi/cli.rb,
lib/kintsugi/version.rb,
lib/kintsugi/apply_change_to_project.rb

Defined Under Namespace

Modules: Version Classes: CLI

Class Method Summary collapse

Class Method Details

.apply_change_to_project(project, change) ⇒ void

This method returns an undefined value.

Applies the change specified by change to project.

Parameters:

  • project (Xcodeproj::Project)

    Project to which to apply the change.

  • change (Hash)

    Change to apply to project. Assumed to be in the format emitted by Xcodeproj::Differ#project_diff where its key_1 and key_2 parameters have values of :added and :removed respectively.



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.

Parameters:

  • project_file_path (String)

    Project to which to apply the changes.

  • output_changes_path (String)

    Path to where the changes to apply to the project are written in JSON format.

Raises:

  • (ArgumentError)

    If the file extension is not pbxproj or the file doesn’t exist

  • (RuntimeError)

    If no rebase, cherry-pick, or merge is in progress, or the project file couldn’t be opened, or there was an error applying the change to the project.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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_and_copy_to_original_path(project_in_temp_directory, change, project_file_path)
end

.three_way_merge(base_project_path, ours_project_path, theirs_project_path, original_project_path) ⇒ void

This method returns an undefined value.

Merges the changes done between theirs_project_path and base_project_path to the file at ours_project_path. The files may not be at the original path, and therefore the original_project_path is required in order for the project metadata to be written properly.

Parameters:

  • base_project_path (String)

    Path to the base version of the project.

  • ours_project_path (String)

    Path to ours version of the project.

  • theirs_project_path (String)

    Path to theirs version of the project.

  • original_project_path (String)

    Path to the original path of the file.

Raises:

  • (RuntimeError)

    If there was an error applying the change to the project.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/kintsugi.rb', line 65

def three_way_merge(base_project_path, ours_project_path, theirs_project_path,
                    original_project_path)
  original_directory_name = File.basename(File.dirname(original_project_path))
  base_temporary_project =
    copy_project_to_temporary_path_in_directory_with_name(base_project_path,
                                                          original_directory_name)
  ours_temporary_project =
    copy_project_to_temporary_path_in_directory_with_name(ours_project_path,
                                                          original_directory_name)
  theirs_temporary_project =
    copy_project_to_temporary_path_in_directory_with_name(theirs_project_path,
                                                          original_directory_name)

  change =
    Xcodeproj::Differ.project_diff(theirs_temporary_project, base_temporary_project,
                                   :added, :removed)

  apply_change_and_copy_to_original_path(ours_temporary_project, change, ours_project_path)
end