Commit 9ccec6d3 authored by Kerri Miller's avatar Kerri Miller Committed by Bob Van Landuyt

Use `default_branch_name` when initializing w/README.md

parent d52619d7
......@@ -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