Commit 6765e044 authored by Kerri Miller's avatar Kerri Miller Committed by Markus Koller

Respect Group's default branch name when present

parent d6954c00
......@@ -84,7 +84,11 @@ module HasRepository
end
def default_branch_from_preferences
empty_repo? ? Gitlab::CurrentSettings.default_branch_name : nil
return unless empty_repo?
group_branch_default_name = group&.default_branch_name if respond_to?(:group)
group_branch_default_name || Gitlab::CurrentSettings.default_branch_name
end
def reload_default_branch
......
......@@ -552,6 +552,10 @@ class Group < Namespace
owners.first || parent&.default_owner || owner
end
def default_branch_name
namespace_settings&.default_branch_name
end
def access_level_roles
GroupMember.access_level_roles
end
......
......@@ -147,7 +147,7 @@ module Projects
def create_readme
commit_attrs = {
branch_name: Gitlab::CurrentSettings.default_branch_name.presence || 'master',
branch_name: @project.default_branch || 'master',
commit_message: 'Initial commit',
file_path: 'README.md',
file_content: "# #{@project.name}\n\n#{@project.description}"
......
- @content_class = "limit-container-width" unless fluid_layout
- default_branch_name = Gitlab::CurrentSettings.default_branch_name.presence || "master"
- default_branch_name = @project.default_branch || "master"
- breadcrumb_title _("Details")
- page_title _("Details")
......
---
title: Respect Group's default branch name when present
merge_request: 44370
author:
type: changed
......@@ -1506,6 +1506,28 @@ RSpec.describe Group do
end
end
describe "#default_branch_name" do
context "group.namespace_settings does not have a default branch name" do
it "returns nil" do
expect(group.default_branch_name).to be_nil
end
end
context "group.namespace_settings has a default branch name" do
let(:example_branch_name) { "example_branch_name" }
before do
expect(group.namespace_settings)
.to receive(:default_branch_name)
.and_return(example_branch_name)
end
it "returns the default branch name" do
expect(group.default_branch_name).to eq(example_branch_name)
end
end
end
describe '#default_owner' do
let(:group) { build(:group) }
......
......@@ -4979,15 +4979,21 @@ RSpec.describe Project do
context "with an empty repository" do
let_it_be(:project) { create(:project_empty_repo) }
context "Gitlab::CurrentSettings.default_branch_name is unavailable" do
context "group.default_branch_name is available" do
let(:project_group) { create(:group) }
let(:project) { create(:project, path: 'avatar', namespace: project_group) }
before do
expect(Gitlab::CurrentSettings)
.not_to receive(:default_branch_name)
expect(project.group)
.to receive(:default_branch_name)
.and_return(nil)
.and_return('example_branch')
end
it "returns that value" do
expect(project.default_branch).to be_nil
it "returns the group default value" do
expect(project.default_branch).to eq("example_branch")
end
end
......@@ -4995,11 +5001,23 @@ RSpec.describe Project do
before do
expect(Gitlab::CurrentSettings)
.to receive(:default_branch_name)
.and_return('example_branch')
.and_return(example_branch_name)
end
it "returns that value" do
expect(project.default_branch).to eq("example_branch")
context "is missing or nil" do
let(:example_branch_name) { nil }
it "returns nil" do
expect(project.default_branch).to be_nil
end
end
context "is present" do
let(:example_branch_name) { "example_branch_name" }
it "returns the expected branch name" do
expect(project.default_branch).to eq(example_branch_name)
end
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