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