Commit a892a5a9 authored by Kyle Fuller's avatar Kyle Fuller

Merge pull request #3234 from CocoaPods/seg-no-shell

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