Commit 60a14e9b authored by Markus Koller's avatar Markus Koller

Merge branch '251963-respect-group-s-default-branch-name-when-present' into 'master'

Respect Group's default branch name when present

See merge request gitlab-org/gitlab!44370
parents a1acada0 6765e044
...@@ -84,7 +84,11 @@ module HasRepository ...@@ -84,7 +84,11 @@ module HasRepository
end end
def default_branch_from_preferences 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 end
def reload_default_branch def reload_default_branch
......
...@@ -552,6 +552,10 @@ class Group < Namespace ...@@ -552,6 +552,10 @@ class Group < Namespace
owners.first || parent&.default_owner || owner owners.first || parent&.default_owner || owner
end end
def default_branch_name
namespace_settings&.default_branch_name
end
def access_level_roles def access_level_roles
GroupMember.access_level_roles GroupMember.access_level_roles
end end
......
...@@ -147,7 +147,7 @@ module Projects ...@@ -147,7 +147,7 @@ module Projects
def create_readme def create_readme
commit_attrs = { commit_attrs = {
branch_name: Gitlab::CurrentSettings.default_branch_name.presence || 'master', branch_name: @project.default_branch || 'master',
commit_message: 'Initial commit', commit_message: 'Initial commit',
file_path: 'README.md', file_path: 'README.md',
file_content: "# #{@project.name}\n\n#{@project.description}" file_content: "# #{@project.name}\n\n#{@project.description}"
......
- @content_class = "limit-container-width" unless fluid_layout - @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") - breadcrumb_title _("Details")
- page_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 ...@@ -1506,6 +1506,28 @@ RSpec.describe Group do
end end
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 describe '#default_owner' do
let(:group) { build(:group) } let(:group) { build(:group) }
......
...@@ -4979,15 +4979,21 @@ RSpec.describe Project do ...@@ -4979,15 +4979,21 @@ RSpec.describe Project do
context "with an empty repository" do context "with an empty repository" do
let_it_be(:project) { create(:project_empty_repo) } 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 before do
expect(Gitlab::CurrentSettings) expect(Gitlab::CurrentSettings)
.not_to receive(:default_branch_name)
expect(project.group)
.to receive(:default_branch_name) .to receive(:default_branch_name)
.and_return(nil) .and_return('example_branch')
end end
it "returns that value" do it "returns the group default value" do
expect(project.default_branch).to be_nil expect(project.default_branch).to eq("example_branch")
end end
end end
...@@ -4995,11 +5001,23 @@ RSpec.describe Project do ...@@ -4995,11 +5001,23 @@ RSpec.describe Project do
before do before do
expect(Gitlab::CurrentSettings) expect(Gitlab::CurrentSettings)
.to receive(:default_branch_name) .to receive(:default_branch_name)
.and_return('example_branch') .and_return(example_branch_name)
end end
it "returns that value" do context "is missing or nil" do
expect(project.default_branch).to eq("example_branch") 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 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