Commit e887a6d1 authored by Igor Drozdov's avatar Igor Drozdov

Create main branch by default for design repos

Currently when we copy design repo and the repo is empty
`master` branch is created by default.

Let's create `main` branch in this case instead
parent abff3eb9
......@@ -86,7 +86,7 @@ module DesignManagement
def with_temporary_branch(&block)
target_repository.create_if_not_exists
create_master_branch! if target_repository.empty?
create_default_branch! if target_repository.empty?
create_temporary_branch!
yield
......@@ -95,9 +95,9 @@ module DesignManagement
end
# A project that does not have any designs will have a blank design
# repository. To create a temporary branch from `master` we need
# create `master` first by adding a file to it.
def create_master_branch!
# repository. To create a temporary branch from default branch we need to
# create default branch first by adding a file to it.
def create_default_branch!
target_repository.create_file(
git_user,
".CopyDesignCollectionService_#{Time.now.to_i}",
......@@ -121,7 +121,7 @@ module DesignManagement
target_repository.rm_branch(git_user, temporary_branch)
end
# Merge the temporary branch containing the commits to `master`
# Merge the temporary branch containing the commits to default branch
# and update the state of the target_design_collection.
def finalize!
source_sha = shas.last
......
......@@ -13,7 +13,7 @@ module DesignManagement
attr_reader :issue
def target_branch
repository.root_ref || "master"
repository.root_ref || Gitlab::DefaultBranch.value(object: project)
end
def collection
......
......@@ -195,6 +195,14 @@ RSpec.describe DesignManagement::CopyDesignCollection::CopyService, :clean_gitla
expect { subject }.to change { target_repository.branch_names }.from([]).to(['master'])
end
it 'does not create default branch when one exists' do
target_repository.create_if_not_exists
target_repository.create_file(user, '.meta', '.gitlab', branch_name: 'new-branch', message: 'message')
expect { subject }.not_to change { target_repository.branch_names }
expect(target_repository.branch_names).to eq(['new-branch'])
end
it 'leaves the design collection in the correct copy state' do
subject
......
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