Commit e85f4459 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '293953_inherit_default_branch_name_for_subgroups' into 'master'

Inherit default branch name for subgroups

See merge request gitlab-org/gitlab!57101
parents d786b198 604093ca
...@@ -77,9 +77,14 @@ module HasRepository ...@@ -77,9 +77,14 @@ module HasRepository
def default_branch_from_preferences def default_branch_from_preferences
return unless empty_repo? return unless empty_repo?
group_branch_default_name = group&.default_branch_name if respond_to?(:group) (default_branch_from_group_preferences || Gitlab::CurrentSettings.default_branch_name).presence
end
def default_branch_from_group_preferences
return unless respond_to?(:group)
return unless group
(group_branch_default_name || Gitlab::CurrentSettings.default_branch_name).presence group.default_branch_name || group.root_ancestor.default_branch_name
end end
def reload_default_branch def reload_default_branch
......
---
title: Inherit default branch name for subgroups
merge_request: 57101
author:
type: fixed
...@@ -5225,57 +5225,27 @@ RSpec.describe Project, factory_default: :keep do ...@@ -5225,57 +5225,27 @@ RSpec.describe Project, factory_default: :keep do
end end
describe '#default_branch' do describe '#default_branch' do
context 'with an empty repository' do context 'with default_branch_name' do
let_it_be(:project) { create(:project_empty_repo) } let_it_be_with_refind(:root_group) { create(:group) }
let_it_be_with_refind(:project_group) { create(:group, parent: root_group) }
let_it_be_with_refind(:project) { create(:project, path: 'avatar', namespace: project_group) }
context 'group.default_branch_name is available' do where(:instance_branch, :root_group_branch, :project_group_branch, :project_branch) do
let(:project_group) { create(:group) } '' | nil | nil | nil
let(:project) { create(:project, path: 'avatar', namespace: project_group) } nil | nil | nil | nil
'main' | nil | nil | 'main'
before do 'main' | 'root_branch' | nil | 'root_branch'
expect(Gitlab::CurrentSettings) 'main' | 'root_branch' | 'group_branch' | 'group_branch'
.not_to receive(:default_branch_name)
expect(project.group)
.to receive(:default_branch_name)
.and_return('example_branch')
end
it 'returns the group default value' do
expect(project.default_branch).to eq('example_branch')
end
end end
context 'Gitlab::CurrentSettings.default_branch_name is available' do with_them do
before do before do
expect(Gitlab::CurrentSettings) allow(Gitlab::CurrentSettings).to receive(:default_branch_name).and_return(instance_branch)
.to receive(:default_branch_name) root_group.namespace_settings.update!(default_branch_name: root_group_branch)
.and_return(example_branch_name) project_group.namespace_settings.update!(default_branch_name: project_group_branch)
end
context 'is missing or nil' do
let(:example_branch_name) { nil }
it "returns nil" do
expect(project.default_branch).to be_nil
end
end end
context 'is blank' do it { expect(project.default_branch).to eq(project_branch) }
let(:example_branch_name) { '' }
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 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