Commit ab69dd46 authored by Samuel E. Giddins's avatar Samuel E. Giddins Committed by Kyle Fuller

[Executable] Properly execute things using Open4.spawn using an array of arguments

parent 86424fc3
......@@ -33,7 +33,7 @@ GIT
GIT
remote: https://github.com/CocoaPods/cocoapods-downloader.git
revision: a5a642e572937eb08097fbf65b30e1e7a3c449e9
revision: 217c49204845916071eb3bd160bd7357000f0f62
branch: master
specs:
cocoapods-downloader (0.8.1)
......
......@@ -60,7 +60,7 @@ module Pod
#
def clone_template
UI.section("Cloning `#{template_repo_url}` into `#{@name}`.") do
git! "clone '#{template_repo_url}' #{@name}"
git! ['clone', template_repo_url, @name]
end
end
......
......@@ -39,11 +39,11 @@ module Pod
UI.section("#{prefix} spec repo `#{@name}` from `#{@url}`#{" (branch `#{@branch}`)" if @branch}") do
config.repos_dir.mkpath
Dir.chdir(config.repos_dir) do
command = "clone '#{@url}' #{@name}"
command << ' --depth=1' if @shallow
command = ['clone', @url, @name]
command << '--depth=1' if @shallow
git!(command)
end
Dir.chdir(dir) { git!("checkout #{@branch}") } if @branch
Dir.chdir(dir) { git!('checkout', @branch) } if @branch
SourcesManager.check_version_information(dir)
end
end
......
......@@ -146,10 +146,10 @@ module Pod
FileUtils.cp(spec_file, output_path)
Dir.chdir(repo_dir) do
# only commit if modified
if git!('status --porcelain 2>&1').include?(spec.name)
if git!('status', '--porcelain').include?(spec.name)
UI.puts " - #{message}"
git!("add #{spec.name}")
git!("commit --no-verify -m '#{message}'")
git!('add', spec.name)
git!('commit', '--no-verify', '-m', message)
else
UI.puts " - [No change] #{spec}"
end
......
......@@ -70,7 +70,7 @@ module Pod
#
def set_master_repo_url
Dir.chdir(master_repo_dir) do
git("remote set-url origin '#{url}'")
git('remote', 'set-url', 'origin', url)
end
end
......@@ -101,7 +101,7 @@ module Pod
#
def set_master_repo_branch
Dir.chdir(master_repo_dir) do
git('checkout master')
git %w(checkout master)
end
end
......
......@@ -19,12 +19,12 @@ module Pod
# @return [void]
#
def executable(name)
define_method(name) do |command|
Executable.execute_command(name, command, false)
define_method(name) do |*command|
Executable.execute_command(name, Array(command).flatten, false)
end
define_method(name.to_s + '!') do |command|
Executable.execute_command(name, command, true)
define_method(name.to_s + '!') do |*command|
Executable.execute_command(name, Array(command).flatten, true)
end
end
......@@ -33,7 +33,7 @@ module Pod
# @param [String] bin
# The binary to use.
#
# @param [String] command
# @param [Array<#to_s>] command
# The command to send to the binary.
#
# @param [Bool] raise_on_failure
......@@ -54,7 +54,8 @@ module Pod
require 'open4'
require 'shellwords'
full_command = "#{bin.shellescape} #{command}"
command = command.map(&:to_s)
full_command = "#{bin.shellescape} #{command.map(&:shellescape).join(' ')}"
if Config.instance.verbose?
UI.message("$ #{full_command}")
......@@ -64,7 +65,7 @@ module Pod
end
options = { :stdout => stdout, :stderr => stderr, :status => true }
status = Open4.spawn(full_command, options)
status = Open4.spawn(bin, command, options)
output = stdout.join("\n") + stderr.join("\n")
unless status.success?
if raise_on_failure
......
......@@ -15,7 +15,7 @@ module Pod
end
def save_as(pathname)
gen_bridge_metadata %(-c "#{search_paths.join(' ')}" -o '#{pathname}' '#{headers.join("' '")}')
gen_bridge_metadata('-c', search_paths.join(' '), '-o', pathname, *headers)
end
end
end
......
......@@ -124,7 +124,7 @@ module Pod
ENV.delete('CDPATH')
prepare_command = root_spec.prepare_command.strip_heredoc.chomp
full_command = "\nset -e\n" + prepare_command
bash!(full_command)
bash!('-c', full_command)
end
end
end
......
......@@ -210,7 +210,7 @@ module Pod
UI.section "Updating spec repo `#{source.name}`" do
Dir.chdir(source.repo) do
begin
output = git!('pull --ff-only')
output = git! %w(pull --ff-only)
UI.puts output if show_output && !config.verbose?
rescue Informative
UI.warn 'CocoaPods was not able to update the ' \
......@@ -232,7 +232,7 @@ module Pod
# @return [Bool] Whether the given source is a GIT repo.
#
def git_repo?(dir)
Dir.chdir(dir) { git('rev-parse >/dev/null 2>&1') }
Dir.chdir(dir) { `git rev-parse >/dev/null 2>&1` }
$?.success?
end
......
......@@ -21,7 +21,7 @@ module Pod
it 'should create a new dir for the newly created pod' do
@sut.any_instance.stubs(:configure_template)
url = @sut::TEMPLATE_REPO
@sut.any_instance.expects(:git!).with("clone '#{url}' TestPod").once
@sut.any_instance.expects(:git!).with(['clone', url, 'TestPod']).once
run_command('lib', 'create', 'TestPod')
end
......@@ -47,13 +47,13 @@ module Pod
it 'should use the given template URL' do
template_url = 'https://github.com/custom/template.git'
@sut.any_instance.expects(:git!).with("clone '#{template_url}' TestPod").once
@sut.any_instance.expects(:git!).with(['clone', template_url, 'TestPod']).once
run_command('lib', 'create', 'TestPod', template_url)
end
it 'should use the default URL if no template URL is given' do
template_url = 'https://github.com/CocoaPods/pod-template.git'
@sut.any_instance.expects(:git!).with("clone '#{template_url}' TestPod").once
@sut.any_instance.expects(:git!).with(['clone', template_url, 'TestPod']).once
run_command('lib', 'create', 'TestPod')
end
end
......
......@@ -5,7 +5,7 @@ module Pod
it 'shows the actual command on failure' do
e = lambda do
Executable.execute_command('false',
'', true)
[''], true)
end.should.raise Informative
e.message.should.match(/false/)
end
......@@ -16,8 +16,8 @@ module Pod
result = mock
result.stubs(:success?).returns(true)
Open4.expects(:spawn).with('/Spa\\ ces/are\\"/fun/false ', :stdout => [], :stderr => [], :status => true).once.returns(result)
Executable.execute_command(cmd, '', true)
Open4.expects(:spawn).with('/Spa ces/are"/fun/false', [], :stdout => [], :stderr => [], :status => true).once.returns(result)
Executable.execute_command(cmd, [], true)
end
end
end
......@@ -7,8 +7,8 @@ describe 'Pod::Generator::BridgeSupport' do
it 'generates a metadata file with the appropriate search paths' do
headers = %w(/some/dir/foo.h /some/dir/bar.h /some/other/dir/baz.h).map { |h| Pathname.new(h) }
generator = Pod::Generator::BridgeSupport.new(headers)
expected = %(-c "-I '/some/dir' -I '/some/other/dir'" -o '/path/to/Pods.bridgesupport' '#{headers.join("' '")}')
generator.expects(:gen_bridge_metadata).with(expected)
expected = ['-c', "-I '/some/dir' -I '/some/other/dir'", '-o', '/path/to/Pods.bridgesupport', *headers]
generator.expects(:gen_bridge_metadata).with { |*command| command.map(&:to_s) == expected.map(&:to_s) }
generator.save_as(Pathname.new('/path/to/Pods.bridgesupport'))
end
end
......
......@@ -242,7 +242,7 @@ module Pod
it 'uses the only fast forward git option' do
set_up_test_repo_for_update
SourcesManager.expects(:git!).with { |options| options.should.match /--ff-only/ }
SourcesManager.expects(:git!).with { |options| options.should.include? '--ff-only' }
SourcesManager.update(test_repo_path.basename.to_s, true)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment