Commit 0574ae2f authored by Sylvain Guillopé's avatar Sylvain Guillopé Committed by Sylvain Guillopé

[Repo Command] Handle SystemCallError when creating "repos_dir"

Creating the "repos" directory when adding a new pod repo my fail due
to system-related errors. For example if the user doesn't have write
permissions to the ~/.cocoapods directory.
Handle the SystemCallError exception to fail gracefully by raising an
Informative exception.

Fixes #4177
parent 585abeb9
......@@ -39,14 +39,19 @@ module Pod
def run
prefix = @shallow ? 'Creating shallow clone of' : 'Cloning'
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
git!(command)
begin
config.repos_dir.mkpath
rescue SystemCallError => e
raise Informative, "Could not create repos directory '#{config.repos_dir}'\n#{e.errno.to_s} #{e.message}"
else
Dir.chdir(config.repos_dir) do
command = ['clone', @url, @name]
command << '--depth=1' if @shallow
git!(command)
end
Dir.chdir(dir) { git!('checkout', @branch) } if @branch
SourcesManager.check_version_information(dir)
end
Dir.chdir(dir) { git!('checkout', @branch) } if @branch
SourcesManager.check_version_information(dir)
end
end
end
......
......@@ -38,5 +38,14 @@ module Pod
`git log --pretty=oneline`.strip.split("\n").size.should == 1
end
end
it 'raises an informative error when the repos directory fails to be created' do
repos_dir = config.repos_dir
def repos_dir.mkpath
raise SystemCallError, 'Operation not permitted'
end
e = lambda { run_command('repo', 'add', 'private', test_repo_path) }.should.raise Informative
e.message.should.match /Could not create repos directory '#{tmp_repos_path}'/
end
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