Skip to content

Commit aee9f0e

Browse files
committed
Only call add_known_host() if clone_protocol_ssh?
1 parent f006709 commit aee9f0e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

app/models/repository/git_remote.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ def clone_host
3636
return p[:host]
3737
end
3838

39+
def clone_protocol_ssh?
40+
# Possible valid values (via http://git-scm.com/book/ch4-1.html):
41+
# ssh://user@server/project.git
42+
# user@server:project.git
43+
# server:project.git
44+
# For simplicity we just assume if it's not HTTP(S), then it's SSH.
45+
!clone_url.match(/^http/)
46+
end
47+
3948
# Hook into Repository.fetch_changesets to also run 'git fetch'.
4049
def fetch_changesets
4150
# ensure we don't fetch twice during the same request
@@ -81,7 +90,7 @@ def two_remotes_equal(a,b)
8190
end
8291

8392
def ensure_possibly_empty_clone_exists
84-
Repository::GitRemote.add_known_host(clone_host)
93+
Repository::GitRemote.add_known_host(clone_host) if clone_protocol_ssh?
8594

8695
unless system "git", "ls-remote", "-h", clone_url
8796
return "#{clone_url} is not a valid remote."
@@ -128,7 +137,7 @@ def parse(url)
128137

129138
def fetch
130139
puts "Fetching repo #{clone_path}"
131-
Repository::GitRemote.add_known_host(clone_host)
140+
Repository::GitRemote.add_known_host(clone_host) if clone_protocol_ssh?
132141

133142
err = ensure_possibly_empty_clone_exists
134143
Rails.logger.warn err if err

0 commit comments

Comments
 (0)