Abort sync if project has groups containing a forward slash

This commit is contained in:
Mark Larsen
2014-05-31 21:13:12 -07:00
parent 4c17ccf137
commit 26f1c95454
7 changed files with 64 additions and 13 deletions

View File

@@ -124,6 +124,17 @@ module Xcodeproj
end
private :squash_duplicate_file_references
def groups_containing_forward_slash
found_groups = []
groups.each do |group|
unless group.excluded_from_sync?
found_groups << group if group.basename.include?("/")
found_groups |= group.groups_containing_forward_slash
end
end
found_groups
end
end
end
end

View File

@@ -14,6 +14,7 @@ module Synx
def sync(options={})
set_options(options)
presync_check
Synx::Tabber.increase
Synx::Tabber.puts "Syncing files that are included in Xcode project...".bold.white
main_group.all_groups.each { |gr| gr.sync(main_group) }
@@ -25,6 +26,18 @@ module Synx
save
end
def presync_check
forward_slash_groups = main_group.groups_containing_forward_slash
unless forward_slash_groups.empty?
Synx::Tabber.puts "Synx cannot sync projects with groups that contain '/'. Please rename the following groups before running synx again:".yellow
Synx::Tabber.increase
forward_slash_groups.each do |group|
Synx::Tabber.puts group.hierarchy_path
end
abort
end
end
def set_options(options)
self.prune = options[:prune]

View File

@@ -2,10 +2,17 @@ require 'bundler/setup'
Bundler.setup
require 'synx'
require 'pry'
require 'pry-debugger'
require 'coveralls'
Coveralls.wear!
DUMMY_SYNX_PATH = File.join(File.dirname(__FILE__), 'dummy')
DUMMY_SYNX_TEST_PATH = File.join(File.dirname(__FILE__), 'test_dummy')
DUMMY_SYNX_TEST_PROJECT_PATH = File.join(DUMMY_SYNX_TEST_PATH, 'dummy.xcodeproj')
FileUtils.rm_rf(DUMMY_SYNX_TEST_PATH)
FileUtils.cp_r(DUMMY_SYNX_PATH, DUMMY_SYNX_TEST_PATH)
DUMMY_SYNX_TEST_PROJECT = Synx::Project.open(DUMMY_SYNX_TEST_PROJECT_PATH)
RSpec.configure do |config|
end

View File

@@ -0,0 +1,30 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
describe Xcodeproj::Project::Object::PBXGroup do
describe "groups_containing_forward_slash" do
before(:all) do
DUMMY_SYNX_TEST_PROJECT.send(:set_options, {})
end
after(:all) do
DUMMY_SYNX_TEST_PROJECT["top group"].remove_from_project
end
it "should return all child and grandchild groups containing forward slash" do
top_group = DUMMY_SYNX_TEST_PROJECT.main_group.new_group("top group")
child_1 = top_group.new_group("have / slash")
child_1_1 = child_1.new_group("1 no slash")
child_1_2 = child_1.new_group("1 / slash")
child_2 = top_group.new_group("no slash")
child_2_1 = child_2.new_group("2 no slash")
child_2_2 = child_2.new_group("2 / slash")
expect(top_group.groups_containing_forward_slash).to eq([child_1, child_1_2, child_2_2])
end
end
end

View File

@@ -30,16 +30,6 @@ end
describe Synx::Project do
DUMMY_SYNX_PATH = File.join(File.dirname(__FILE__), '..', 'dummy')
DUMMY_SYNX_TEST_PATH = File.join(File.dirname(__FILE__), '..', 'test_dummy')
DUMMY_SYNX_TEST_PROJECT_PATH = File.join(DUMMY_SYNX_TEST_PATH, 'dummy.xcodeproj')
before(:all) do
FileUtils.rm_rf(DUMMY_SYNX_TEST_PATH)
FileUtils.cp_r(DUMMY_SYNX_PATH, DUMMY_SYNX_TEST_PATH)
DUMMY_SYNX_TEST_PROJECT = Synx::Project.open(DUMMY_SYNX_TEST_PROJECT_PATH)
end
describe "#sync" do
def verify_group_structure(group, expected_structure)

View File

@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
describe Synx::Tabber do
after(:each) do
before(:each) do
Synx::Tabber.reset
end

View File

@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "coveralls"
spec.add_development_dependency "rake", "~> 10.3"
spec.add_development_dependency "rspec", "~> 2.14"
spec.add_development_dependency "pry", "~> 0.9"
spec.add_development_dependency "pry-debugger", "~> 0.2"
spec.add_dependency "clamp", "~> 0.6"
spec.add_dependency "colored", "~> 1.2"