Commit 6baca709 authored by Samuel E. Giddins's avatar Samuel E. Giddins

Conditionally include `sudo` in suggested update command

Closes https://github.com/CocoaPods/CocoaPods/issues/2058
parent c6e5b500
......@@ -205,9 +205,12 @@ module Pod
"Update CocoaPods, or checkout the appropriate tag in the repo."
end
needs_sudo = path_writable?(__FILE__)
if config.new_version_message? && cocoapods_update?(versions)
UI.puts "\nCocoaPods #{versions['last']} is available.\n" \
"To update use: [sudo] gem install cocoapods\n".green
"To update use: #{needs_sudo ? 'sudo ' : ''}" \
'gem install cocoapods\n'.green
end
end
......@@ -284,6 +287,12 @@ module Pod
#-----------------------------------------------------------------------#
private
def path_writable?(path)
Pathname(path).dirname.writable?
end
end
end
end
......
......@@ -146,6 +146,12 @@ module Pod
e.message.should.match /Update CocoaPods/
end
it 'returns whether a path is writable' do
path = '/Users/'
Pathname.any_instance.stubs(:writable?).returns(true)
SourcesManager.send(:path_writable?, path).should.be.true
end
it "returns whether a repository is compatible" do
SourcesManager.stubs(:version_information).returns({ 'min' => '0.0.1' })
SourcesManager.repo_compatible?('stub').should.be.true
......
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