Commit 0c5be42c authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'sh-fix-bitbucket-server-importer-default-branch' into 'master'

Fix wrong default branch imported with Bitbucket Server

See merge request gitlab-org/gitlab!74858
parents 1c85f188 ffc13533
......@@ -19,7 +19,8 @@ module Gitlab
end
def self.refmap
[:heads, :tags, '+refs/pull-requests/*/to:refs/merge-requests/*/head']
# We omit :heads and :tags since these are fetched in the import_repository
['+refs/pull-requests/*/to:refs/merge-requests/*/head']
end
# Unlike GitHub, you can't grab the commit SHAs for pull requests that
......@@ -140,11 +141,11 @@ module Gitlab
def import_repository
log_info(stage: 'import_repository', message: 'starting import')
project.ensure_repository
project.repository.import_repository(project.import_url)
project.repository.fetch_as_mirror(project.import_url, refmap: self.class.refmap)
log_info(stage: 'import_repository', message: 'finished import')
rescue Gitlab::Shell::Error => e
rescue ::Gitlab::Git::CommandError => e
Gitlab::ErrorTracking.log_exception(
e,
stage: 'import_repository', message: 'failed import', error: e.message
......
......@@ -27,20 +27,26 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
end
describe '#import_repository' do
let(:repo_url) { 'http://bitbucket:test@my-bitbucket' }
before do
expect(project.repository).to receive(:import_repository).with(repo_url)
end
it 'adds a remote' do
expect(subject).to receive(:import_pull_requests)
expect(subject).to receive(:delete_temp_branches)
expect(project.repository).to receive(:fetch_as_mirror)
.with('http://bitbucket:test@my-bitbucket',
refmap: [:heads, :tags, '+refs/pull-requests/*/to:refs/merge-requests/*/head'])
.with(repo_url,
refmap: ['+refs/pull-requests/*/to:refs/merge-requests/*/head'])
subject.execute
end
it 'raises a Gitlab::Shell exception in the fetch' do
expect(project.repository).to receive(:fetch_as_mirror).and_raise(Gitlab::Shell::Error)
it 'raises a Gitlab::Git::CommandError in the fetch' do
expect(project.repository).to receive(:fetch_as_mirror).and_raise(::Gitlab::Git::CommandError)
expect { subject.execute }.to raise_error(Gitlab::Shell::Error)
expect { subject.execute }.to raise_error(::Gitlab::Git::CommandError)
end
it 'raises an unhandled exception in the fetch' 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