Commit 05eea37a authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #4273 from sguillope/sguillope/handle-add-repo-mkpath-exception

[Repo Command] Handle add repo mkpath exception
parents 585abeb9 d0e07f55
...@@ -71,6 +71,11 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -71,6 +71,11 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Sylvain Guillopé](https://github.com/sguillope) [Sylvain Guillopé](https://github.com/sguillope)
[#3151](https://github.com/CocoaPods/CocoaPods/issues/3151) [#3151](https://github.com/CocoaPods/CocoaPods/issues/3151)
* Gracefully handle exception if creating the repos directory fails due to a
system error like a permission issue.
[Sylvain Guillopé](https://github.com/sguillope)
[#4177](https://github.com/CocoaPods/CocoaPods/issues/4177)
## 0.39.0.beta.4 (2015-09-02) ## 0.39.0.beta.4 (2015-09-02)
##### Bug Fixes ##### Bug Fixes
......
...@@ -39,16 +39,49 @@ module Pod ...@@ -39,16 +39,49 @@ module Pod
def run def run
prefix = @shallow ? 'Creating shallow clone of' : 'Cloning' prefix = @shallow ? 'Creating shallow clone of' : 'Cloning'
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 create_repos_dir
Dir.chdir(config.repos_dir) do clone_repo
command = ['clone', @url, @name] checkout_branch
command << '--depth=1' if @shallow
git!(command)
end
Dir.chdir(dir) { git!('checkout', @branch) } if @branch
SourcesManager.check_version_information(dir) SourcesManager.check_version_information(dir)
end end
end end
private
# Creates the repos directory specified in the configuration by
# `config.repos_dir`.
#
# @return [void]
#
# @raise If the directory cannot be created due to a system error.
#
def create_repos_dir
config.repos_dir.mkpath
rescue => e
raise Informative, "Could not create '#{config.repos_dir}', the CocoaPods repo cache directory.\n" \
"#{e.class.name}: #{e.message}"
end
# Clones the git spec-repo according to parameters passed to the
# command.
#
# @return [void]
#
def clone_repo
Dir.chdir(config.repos_dir) do
command = ['clone', @url, @name]
command << '--depth=1' if @shallow
git!(command)
end
end
# Checks out the branch of the git spec-repo if provided.
#
# @return [void]
#
def checkout_branch
Dir.chdir(dir) { git!('checkout', @branch) } if @branch
end
end end
end end
end end
......
...@@ -38,5 +38,14 @@ module Pod ...@@ -38,5 +38,14 @@ module Pod
`git log --pretty=oneline`.strip.split("\n").size.should == 1 `git log --pretty=oneline`.strip.split("\n").size.should == 1
end end
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 '#{tmp_repos_path}', the CocoaPods repo cache directory./
end
end 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