Commit 4733ce3e authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '225592-read-default_branch_name-when-initializing-w-readme-md' into 'master'

Use `default_branch_name` when initializing w/README.md

See merge request gitlab-org/gitlab!35801
parents 1e69e7ef 9ccec6d3
......@@ -135,7 +135,7 @@ module Projects
def create_readme
commit_attrs = {
branch_name: 'master',
branch_name: Gitlab::CurrentSettings.default_branch_name.presence || 'master',
commit_message: 'Initial commit',
file_path: 'README.md',
file_content: "# #{@project.name}\n\n#{@project.description}"
......
---
title: Use the application's default_branch_name when available when initializing a new repo with
a README
merge_request: 35801
author:
type: changed
......@@ -446,14 +446,35 @@ RSpec.describe Projects::CreateService, '#execute' do
end
context 'when readme initialization is requested' do
it 'creates README.md' do
let(:project) { create_project(user, opts) }
before do
opts[:initialize_with_readme] = '1'
end
project = create_project(user, opts)
shared_examples 'creates README.md' do
it { expect(project.repository.commit_count).to be(1) }
it { expect(project.repository.readme.name).to eql('README.md') }
it { expect(project.repository.readme.data).to include('# GitLab') }
end
it_behaves_like 'creates README.md'
expect(project.repository.commit_count).to be(1)
expect(project.repository.readme.name).to eql('README.md')
expect(project.repository.readme.data).to include('# GitLab')
context 'and a default_branch_name is specified' do
before do
allow(Gitlab::CurrentSettings)
.to receive(:default_branch_name)
.and_return('example_branch')
end
it_behaves_like 'creates README.md'
it 'creates README.md within the specified branch rather than master' do
branches = project.repository.branches
expect(branches.size).to eq(1)
expect(branches.collect(&:name)).to contain_exactly('example_branch')
end
end
end
......
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