Commit de3af288 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'sh-remove-bitbucket-mirror-constant' into 'master'

Fix import handling errors in Bitbucket Server importer

See merge request gitlab-org/gitlab-ce!24499
parents 3effc289 100b050b
---
title: Fix import handling errors in Bitbucket Server importer
merge_request: 24499
author:
type: fixed
...@@ -132,7 +132,7 @@ module Gitlab ...@@ -132,7 +132,7 @@ module Gitlab
project.repository.fetch_as_mirror(project.import_url, refmap: self.class.refmap, remote_name: REMOTE_NAME) project.repository.fetch_as_mirror(project.import_url, refmap: self.class.refmap, remote_name: REMOTE_NAME)
log_info(stage: 'import_repository', message: 'finished import') log_info(stage: 'import_repository', message: 'finished import')
rescue Gitlab::Shell::Error, Gitlab::Git::RepositoryMirroring::RemoteError => e rescue Gitlab::Shell::Error => e
log_error(stage: 'import_repository', message: 'failed import', error: e.message) log_error(stage: 'import_repository', message: 'failed import', error: e.message)
# Expire cache to prevent scenarios such as: # Expire cache to prevent scenarios such as:
...@@ -140,7 +140,7 @@ module Gitlab ...@@ -140,7 +140,7 @@ module Gitlab
# 2. Retried import, repo is broken or not imported but +exists?+ still returns true # 2. Retried import, repo is broken or not imported but +exists?+ still returns true
project.repository.expire_content_cache if project.repository_exists? project.repository.expire_content_cache if project.repository_exists?
raise e.message raise
end end
# Bitbucket Server keeps tracks of references for open pull requests in # Bitbucket Server keeps tracks of references for open pull requests in
......
...@@ -21,12 +21,9 @@ describe Gitlab::BitbucketServerImport::Importer do ...@@ -21,12 +21,9 @@ describe Gitlab::BitbucketServerImport::Importer do
end end
describe '#import_repository' do describe '#import_repository' do
before do it 'adds a remote' do
expect(subject).to receive(:import_pull_requests) expect(subject).to receive(:import_pull_requests)
expect(subject).to receive(:delete_temp_branches) expect(subject).to receive(:delete_temp_branches)
end
it 'adds a remote' do
expect(project.repository).to receive(:fetch_as_mirror) expect(project.repository).to receive(:fetch_as_mirror)
.with('http://bitbucket:test@my-bitbucket', .with('http://bitbucket:test@my-bitbucket',
refmap: [:heads, :tags, '+refs/pull-requests/*/to:refs/merge-requests/*/head'], refmap: [:heads, :tags, '+refs/pull-requests/*/to:refs/merge-requests/*/head'],
...@@ -34,6 +31,18 @@ describe Gitlab::BitbucketServerImport::Importer do ...@@ -34,6 +31,18 @@ describe Gitlab::BitbucketServerImport::Importer do
subject.execute subject.execute
end end
it 'raises a Gitlab::Shell exception in the fetch' do
expect(project.repository).to receive(:fetch_as_mirror).and_raise(Gitlab::Shell::Error)
expect { subject.execute }.to raise_error(Gitlab::Shell::Error)
end
it 'raises an unhandled exception in the fetch' do
expect(project.repository).to receive(:fetch_as_mirror).and_raise(RuntimeError)
expect { subject.execute }.to raise_error(RuntimeError)
end
end end
describe '#import_pull_requests' do describe '#import_pull_requests' 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