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 ...@@ -205,9 +205,12 @@ module Pod
"Update CocoaPods, or checkout the appropriate tag in the repo." "Update CocoaPods, or checkout the appropriate tag in the repo."
end end
needs_sudo = path_writable?(__FILE__)
if config.new_version_message? && cocoapods_update?(versions) if config.new_version_message? && cocoapods_update?(versions)
UI.puts "\nCocoaPods #{versions['last']} is available.\n" \ 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
end end
...@@ -284,6 +287,12 @@ module Pod ...@@ -284,6 +287,12 @@ module Pod
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
private
def path_writable?(path)
Pathname(path).dirname.writable?
end
end end
end end
end end
......
...@@ -63,7 +63,7 @@ module Pod ...@@ -63,7 +63,7 @@ module Pod
sets.all?{ |s| s.class == Specification::Set}.should.be.true sets.all?{ |s| s.class == Specification::Set}.should.be.true
sets.any?{ |s| s.name == 'BananaLib'}.should.be.true sets.any?{ |s| s.name == 'BananaLib'}.should.be.true
end end
it "can perform a full text regexp search of the sets" do it "can perform a full text regexp search of the sets" do
Source::Aggregate.any_instance.stubs(:all).returns([@test_source]) Source::Aggregate.any_instance.stubs(:all).returns([@test_source])
sets = SourcesManager.search_by_name('Ch[aeiou]nky', true) sets = SourcesManager.search_by_name('Ch[aeiou]nky', true)
...@@ -146,6 +146,12 @@ module Pod ...@@ -146,6 +146,12 @@ module Pod
e.message.should.match /Update CocoaPods/ e.message.should.match /Update CocoaPods/
end 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 it "returns whether a repository is compatible" do
SourcesManager.stubs(:version_information).returns({ 'min' => '0.0.1' }) SourcesManager.stubs(:version_information).returns({ 'min' => '0.0.1' })
SourcesManager.repo_compatible?('stub').should.be.true 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