Commit 0dddb586 authored by Sylvain Guillopé's avatar Sylvain Guillopé Committed by Sylvain Guillopé

[Repo Command] Refactor Repo::Add#run method

Handling the SystemCallError exception made the body of the run method
a bit busier. Break down the implementation in smaller private methods
for better readability and maintainability.
parent 0574ae2f
...@@ -39,21 +39,48 @@ module Pod ...@@ -39,21 +39,48 @@ 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
begin create_repos_dir
config.repos_dir.mkpath clone_repo
rescue SystemCallError => e checkout_branch
raise Informative, "Could not create repos directory '#{config.repos_dir}'\n#{e.errno.to_s} #{e.message}" SourcesManager.check_version_information(dir)
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
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 SystemCallError => e
raise Informative, "Could not create repos directory '#{config.repos_dir}'\n#{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
......
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