Commit 4cb37a20 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'zj-remote-repo-exists-ee' into 'master'

Test if remote repository exists before cloning

Closes gitlab-ce#43929

See merge request gitlab-org/gitlab-ee!5130
parents f33aba93 188c372e
...@@ -436,7 +436,7 @@ group :ed25519 do ...@@ -436,7 +436,7 @@ group :ed25519 do
end end
# Gitaly GRPC client # Gitaly GRPC client
gem 'gitaly-proto', '~> 0.88.0', require: 'gitaly' gem 'gitaly-proto', '~> 0.91.0', require: 'gitaly'
gem 'grpc', '~> 1.10.0' gem 'grpc', '~> 1.10.0'
# Locked until https://github.com/google/protobuf/issues/4210 is closed # Locked until https://github.com/google/protobuf/issues/4210 is closed
......
...@@ -314,7 +314,7 @@ GEM ...@@ -314,7 +314,7 @@ GEM
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gherkin-ruby (0.3.2) gherkin-ruby (0.3.2)
gitaly-proto (0.88.0) gitaly-proto (0.91.0)
google-protobuf (~> 3.1) google-protobuf (~> 3.1)
grpc (~> 1.0) grpc (~> 1.0)
github-linguist (5.3.3) github-linguist (5.3.3)
...@@ -1096,7 +1096,7 @@ DEPENDENCIES ...@@ -1096,7 +1096,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.3) gettext_i18n_rails_js (~> 1.3)
gitaly-proto (~> 0.88.0) gitaly-proto (~> 0.91.0)
github-linguist (~> 5.3.3) github-linguist (~> 5.3.3)
gitlab-flowdock-git-hook (~> 1.0.1) gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-license (~> 1.0) gitlab-license (~> 1.0)
......
---
title: Test if remote repository exists when importing wikis
merge_request:
author:
type: fixed
...@@ -83,6 +83,10 @@ module Gitlab ...@@ -83,6 +83,10 @@ module Gitlab
end end
end end
def self.random_storage
Gitlab.config.repositories.storages.keys.sample
end
def self.address(storage) def self.address(storage)
params = Gitlab.config.repositories.storages[storage] params = Gitlab.config.repositories.storages[storage]
raise "storage not found: #{storage.inspect}" if params.nil? raise "storage not found: #{storage.inspect}" if params.nil?
......
...@@ -3,6 +3,17 @@ module Gitlab ...@@ -3,6 +3,17 @@ module Gitlab
class RemoteService class RemoteService
MAX_MSG_SIZE = 128.kilobytes.freeze MAX_MSG_SIZE = 128.kilobytes.freeze
def self.exists?(remote_url)
request = Gitaly::FindRemoteRepositoryRequest.new(remote: remote_url)
response = GitalyClient.call(GitalyClient.random_storage,
:remote_service,
:find_remote_repository, request,
timeout: GitalyClient.medium_timeout)
response.exists
end
def initialize(repository) def initialize(repository)
@repository = repository @repository = repository
@gitaly_repo = repository.gitaly_repository @gitaly_repo = repository.gitaly_repository
......
...@@ -16,7 +16,8 @@ module Gitlab ...@@ -16,7 +16,8 @@ module Gitlab
# Returns true if we should import the wiki for the project. # Returns true if we should import the wiki for the project.
def import_wiki? def import_wiki?
client.repository(project.import_source)&.has_wiki && client.repository(project.import_source)&.has_wiki &&
!project.wiki_repository_exists? !project.wiki_repository_exists? &&
Gitlab::GitalyClient::RemoteService.exists?(wiki_url)
end end
# Imports the repository data. # Imports the repository data.
...@@ -55,7 +56,6 @@ module Gitlab ...@@ -55,7 +56,6 @@ module Gitlab
def import_wiki_repository def import_wiki_repository
wiki_path = "#{project.disk_path}.wiki" wiki_path = "#{project.disk_path}.wiki"
wiki_url = project.import_url.sub(/\.git\z/, '.wiki.git')
storage_path = project.repository_storage_path storage_path = project.repository_storage_path
gitlab_shell.import_repository(storage_path, wiki_path, wiki_url) gitlab_shell.import_repository(storage_path, wiki_path, wiki_url)
...@@ -70,6 +70,10 @@ module Gitlab ...@@ -70,6 +70,10 @@ module Gitlab
end end
end end
def wiki_url
project.import_url.sub(/\.git\z/, '.wiki.git')
end
def update_clone_time def update_clone_time
project.update_column(:last_repository_updated_at, Time.zone.now) project.update_column(:last_repository_updated_at, Time.zone.now)
end end
......
...@@ -58,4 +58,14 @@ describe Gitlab::GitalyClient::RemoteService do ...@@ -58,4 +58,14 @@ describe Gitlab::GitalyClient::RemoteService do
client.update_remote_mirror(ref_name, only_branches_matching) client.update_remote_mirror(ref_name, only_branches_matching)
end end
end end
describe '.exists?' do
context "when the remote doesn't exist" do
let(:url) { 'https://gitlab.com/gitlab-org/ik-besta-niet-of-ik-word-geplaagd.git' }
it 'returns false' do
expect(described_class.exists?(url)).to be(false)
end
end
end
end end
...@@ -38,8 +38,12 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do ...@@ -38,8 +38,12 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do
expect(project) expect(project)
.to receive(:wiki_repository_exists?) .to receive(:wiki_repository_exists?)
.and_return(false) .and_return(false)
expect(Gitlab::GitalyClient::RemoteService)
.to receive(:exists?)
.with("foo.wiki.git")
.and_return(true)
expect(importer.import_wiki?).to eq(true) expect(importer.import_wiki?).to be(true)
end end
it 'returns false if the GitHub wiki is disabled' do it 'returns false if the GitHub wiki is disabled' do
......
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