Only call add_known_host() if clone_protocol_ssh?

This commit is contained in:
Alex Dergachev 2014-12-12 22:55:27 +00:00
parent f006709f64
commit aee9f0eccd

View File

@ -36,6 +36,15 @@ class Repository::GitRemote < Repository::Git
return p[:host] return p[:host]
end end
def clone_protocol_ssh?
# Possible valid values (via http://git-scm.com/book/ch4-1.html):
# ssh://user@server/project.git
# user@server:project.git
# server:project.git
# For simplicity we just assume if it's not HTTP(S), then it's SSH.
!clone_url.match(/^http/)
end
# Hook into Repository.fetch_changesets to also run 'git fetch'. # Hook into Repository.fetch_changesets to also run 'git fetch'.
def fetch_changesets def fetch_changesets
# ensure we don't fetch twice during the same request # ensure we don't fetch twice during the same request
@ -81,7 +90,7 @@ class Repository::GitRemote < Repository::Git
end end
def ensure_possibly_empty_clone_exists def ensure_possibly_empty_clone_exists
Repository::GitRemote.add_known_host(clone_host) Repository::GitRemote.add_known_host(clone_host) if clone_protocol_ssh?
unless system "git", "ls-remote", "-h", clone_url unless system "git", "ls-remote", "-h", clone_url
return "#{clone_url} is not a valid remote." return "#{clone_url} is not a valid remote."
@ -128,7 +137,7 @@ class Repository::GitRemote < Repository::Git
def fetch def fetch
puts "Fetching repo #{clone_path}" puts "Fetching repo #{clone_path}"
Repository::GitRemote.add_known_host(clone_host) Repository::GitRemote.add_known_host(clone_host) if clone_protocol_ssh?
err = ensure_possibly_empty_clone_exists err = ensure_possibly_empty_clone_exists
Rails.logger.warn err if err Rails.logger.warn err if err