Refactor the clone method to decrease its cyclomatic complexity
This commit is contained in:
@@ -10,10 +10,10 @@ ClassLength:
|
||||
Enabled: false
|
||||
|
||||
CyclomaticComplexity:
|
||||
Max: 16
|
||||
Max: 9
|
||||
|
||||
LineLength:
|
||||
Max: 174
|
||||
Max: 163
|
||||
|
||||
MethodLength:
|
||||
Max: 31
|
||||
|
||||
@@ -40,23 +40,13 @@ class Homesick < Thor
|
||||
elsif uri =~ GITHUB_NAME_REPO_PATTERN
|
||||
destination = Pathname.new(uri).basename
|
||||
git_clone "https://github.com/#{Regexp.last_match[1]}.git", destination: destination
|
||||
elsif uri =~ /%r([^%r]*?)(\.git)?\Z/
|
||||
elsif uri =~ /%r([^%r]*?)(\.git)?\Z/ || uri =~ /[^:]+:([^:]+)(\.git)?\Z/
|
||||
destination = Pathname.new(Regexp.last_match[1])
|
||||
git_clone uri
|
||||
elsif uri =~ /[^:]+:([^:]+)(\.git)?\Z/
|
||||
destination = Pathname.new(Regexp.last_match[1])
|
||||
git_clone uri
|
||||
git_clone uri, destination: destination
|
||||
else
|
||||
fail "Unknown URI format: #{uri}"
|
||||
end
|
||||
|
||||
if destination.join('.gitmodules').exist?
|
||||
inside destination do
|
||||
git_submodule_init
|
||||
git_submodule_update
|
||||
end
|
||||
end
|
||||
|
||||
rc(destination)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,17 @@ class Homesick
|
||||
say_status 'git clone', "#{repo} to #{destination.expand_path}", :green unless options[:quiet]
|
||||
system "git clone -q --config push.default=upstream --recursive #{repo} #{destination}" unless options[:pretend]
|
||||
end
|
||||
|
||||
git_setup_submodules destination
|
||||
end
|
||||
|
||||
def git_setup_submodules(path)
|
||||
if path.join('.gitmodules').exist?
|
||||
inside path do
|
||||
git_submodule_init
|
||||
git_submodule_update
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def git_init(path = '.')
|
||||
|
||||
Reference in New Issue
Block a user