Skip to content

Commit

Permalink
round.
Browse files Browse the repository at this point in the history
  • Loading branch information
byohay committed Jun 9, 2022
1 parent 5ccccef commit d3aa28f
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 101 deletions.
2 changes: 1 addition & 1 deletion bin/kintsugi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require "kintsugi"

begin
Kintsugi::run(ARGV)
Kintsugi.run(ARGV)
rescue ArgumentError, Kintsugi::MergeError
exit(1)
end
2 changes: 1 addition & 1 deletion kintsugi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Gem::Specification.new do |spec|

spec.add_dependency "xcodeproj", ">= 1.19.0", "<= 1.21.0"

spec.add_development_dependency "git", "~> 1.11"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.9"
spec.add_development_dependency "rubocop", "1.12.0"
spec.add_development_dependency "rubocop-rspec", "2.2.0"
spec.add_development_dependency "simplecov", "~> 0.21"
spec.add_development_dependency "git", "~> 1.11"
end
2 changes: 1 addition & 1 deletion lib/kintsugi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Copyright (c) 2022 Lightricks. All rights reserved.
# Created by Ben Yohay.

require_relative "kintsugi/kintsugi"
require_relative "kintsugi/cli"
require_relative "kintsugi/error"
require_relative "kintsugi/merge"

module Kintsugi
class << self
Expand Down
File renamed without changes.
149 changes: 149 additions & 0 deletions spec/kintsugi_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Copyright (c) 2021 Lightricks. All rights reserved.
# Created by Ben Yohay.
# frozen_string_literal: true

require "git"
require "json"
require "rspec"
require "tempfile"
require "tmpdir"

require "kintsugi"

shared_examples "tests" do |git_command, project_name|
let(:temporary_directories_paths) { [] }
let(:git_directory_path) { make_temp_directory }
let(:git) { Git.init(git_directory_path) }

before do
git.config("user.email", "you@example.com")
git.config("user.name", "Your Name")
end

after do
temporary_directories_paths.each do |directory_path|
FileUtils.remove_entry(directory_path)
end
end

context "should encounter conflicts when running '#{git_command}' with project name '#{project_name}'" do
it "resolves conflicts with root command" do
File.write(File.join(git_directory_path, ".gitattributes"), "*.pbxproj merge=Unset")

project = create_new_project_at_path(File.join(git_directory_path, project_name))

git.add(File.join(git_directory_path, ".gitattributes"))
git.add(project.path)
git.commit("Initial project")

project.new_target("com.apple.product-type.library.static", "foo", :ios)
project.save

git.add(all: true)
git.commit("Add target foo")
first_commit_hash = git.revparse("HEAD")

git.checkout("HEAD^")
project = Xcodeproj::Project.open(project.path)
project.new_target("com.apple.product-type.library.static", "bar", :ios)
project.save
git.add(all: true)
git.commit("Add target bar")

`git -C #{git_directory_path} #{git_command} #{first_commit_hash} &> /dev/null`
Kintsugi.run([File.join(project.path, "project.pbxproj")])

project = Xcodeproj::Project.open(project.path)
expect(project.targets.map(&:display_name)).to contain_exactly("foo", "bar")
end

it "resolves conflicts automatically with driver" do
git.config("merge.kintsugi.name", "Kintsugi driver")
git.config("merge.kintsugi.driver", "#{__dir__}/../bin/kintsugi driver %O %A %B %P")
File.write(File.join(git_directory_path, ".gitattributes"), "*.pbxproj merge=kintsugi")

project = create_new_project_at_path(File.join(git_directory_path, project_name))

git.add(File.join(git_directory_path, ".gitattributes"))
git.add(project.path)
git.commit("Initial project")

project.new_target("com.apple.product-type.library.static", "foo", :ios)
project.save

git.add(all: true)
git.commit("Add target foo")
first_commit_hash = git.revparse("HEAD")

git.checkout("HEAD^")
project = Xcodeproj::Project.open(project.path)
project.new_target("com.apple.product-type.library.static", "bar", :ios)
project.save
git.add(all: true)
git.commit("Add target bar")

`git -C #{git_directory_path} #{git_command} #{first_commit_hash} &> /dev/null`

project = Xcodeproj::Project.open(project.path)
expect(project.targets.map(&:display_name)).to contain_exactly("foo", "bar")
end

it "keeps conflicts if failed to resolve conflicts" do
File.write(File.join(git_directory_path, ".gitattributes"), "*.pbxproj merge=Unset")

project = create_new_project_at_path(File.join(git_directory_path, project_name))
project.new_target("com.apple.product-type.library.static", "foo", :ios)
project.save

git.add(File.join(git_directory_path, ".gitattributes"))
git.add(project.path)
git.commit("Initial project")

project.targets[0].build_configurations.each do |configuration|
configuration.build_settings["PRODUCT_NAME"] = "bar"
end
project.save
git.add(all: true)
git.commit("Change target product name to bar")
first_commit_hash = git.revparse("HEAD")

git.checkout("HEAD^")
project = Xcodeproj::Project.open(project.path)
project.targets[0].build_configurations.each do |configuration|
configuration.build_settings["PRODUCT_NAME"] = "baz"
end
project.save
git.add(all: true)
git.commit("Change target product name to baz")

`git -C #{git_directory_path} #{git_command} #{first_commit_hash} &> /dev/null`

expect {
Kintsugi.run([File.join(project.path, "project.pbxproj")])
}.to raise_error(Kintsugi::MergeError)
expect {
project = Xcodeproj::Project.open(project.path)
}.to raise_error(Xcodeproj::Informative)
end
end

def make_temp_directory
directory_path = Dir.mktmpdir
temporary_directories_paths << directory_path
directory_path
end
end

def create_new_project_at_path(path)
project = Xcodeproj::Project.new(path)
project.save
project
end

describe Kintsugi, :kintsugi do
%w[rebase cherry-pick merge].each do |git_command|
["foo.xcodeproj", "foo with space.xcodeproj"].each do |project_name|
it_behaves_like("tests", git_command, project_name)
end
end
end
98 changes: 0 additions & 98 deletions spec/kintsugi_spec.rb

This file was deleted.

0 comments on commit d3aa28f

Please sign in to comment.