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
def default_branch_from_preferences
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
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
end
describe '#default_branch' do
context 'with an empty repository' do
let_it_be(:project) { create(:project_empty_repo) }
context 'with default_branch_name' do
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
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('example_branch')
end
it 'returns the group default value' do
expect(project.default_branch).to eq('example_branch')
end
where(:instance_branch, :root_group_branch, :project_group_branch, :project_branch) do
'' | nil | nil | nil
nil | nil | nil | nil
'main' | nil | nil | 'main'
'main' | 'root_branch' | nil | 'root_branch'
'main' | 'root_branch' | 'group_branch' | 'group_branch'
end
context 'Gitlab::CurrentSettings.default_branch_name is available' do
with_them do
before do
expect(Gitlab::CurrentSettings)
.to receive(:default_branch_name)
.and_return(example_branch_name)
end
context 'is missing or nil' do
let(:example_branch_name) { nil }
it "returns nil" do
expect(project.default_branch).to be_nil
end
allow(Gitlab::CurrentSettings).to receive(:default_branch_name).and_return(instance_branch)
root_group.namespace_settings.update!(default_branch_name: root_group_branch)
project_group.namespace_settings.update!(default_branch_name: project_group_branch)
end
context 'is blank' do
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
it { expect(project.default_branch).to eq(project_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