Commit 9bf53bbc authored by Nick Thomas's avatar Nick Thomas

Merge branch 'id-rename-default_branch_or_master' into 'master'

Rename default_branch_or_master to default_branch_or_main [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!60258
parents 9b22d9bf 4c9cae31
...@@ -144,7 +144,7 @@ module Projects ...@@ -144,7 +144,7 @@ module Projects
end end
def define_badges_variables def define_badges_variables
@ref = params[:ref] || @project.default_branch || 'master' @ref = params[:ref] || @project.default_branch_or_main
@badges = [Gitlab::Ci::Badge::Pipeline::Status, @badges = [Gitlab::Ci::Badge::Pipeline::Status,
Gitlab::Ci::Badge::Coverage::Report] Gitlab::Ci::Badge::Coverage::Report]
......
...@@ -2532,8 +2532,10 @@ class Project < ApplicationRecord ...@@ -2532,8 +2532,10 @@ class Project < ApplicationRecord
.exists? .exists?
end end
def default_branch_or_master def default_branch_or_main
default_branch || 'master' return default_branch if default_branch
Feature.enabled?(:main_branch_over_master, self, default_enabled: :yaml) ? 'main' : 'master'
end end
def ci_config_path_or_default def ci_config_path_or_default
......
...@@ -108,7 +108,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -108,7 +108,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
end end
def add_license_ide_path def add_license_ide_path
ide_edit_path(project, default_branch_or_master, 'LICENSE') ide_edit_path(project, default_branch_or_main, 'LICENSE')
end end
def add_changelog_path def add_changelog_path
...@@ -116,7 +116,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -116,7 +116,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
end end
def add_changelog_ide_path def add_changelog_ide_path
ide_edit_path(project, default_branch_or_master, 'CHANGELOG') ide_edit_path(project, default_branch_or_main, 'CHANGELOG')
end end
def add_contribution_guide_path def add_contribution_guide_path
...@@ -124,7 +124,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -124,7 +124,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
end end
def add_contribution_guide_ide_path def add_contribution_guide_ide_path
ide_edit_path(project, default_branch_or_master, 'CONTRIBUTING.md') ide_edit_path(project, default_branch_or_main, 'CONTRIBUTING.md')
end end
def add_readme_path def add_readme_path
...@@ -132,7 +132,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -132,7 +132,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
end end
def add_readme_ide_path def add_readme_ide_path
ide_edit_path(project, default_branch_or_master, 'README.md') ide_edit_path(project, default_branch_or_main, 'README.md')
end end
def add_ci_yml_path def add_ci_yml_path
...@@ -249,10 +249,10 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -249,10 +249,10 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
nil, nil,
nil, nil,
{ {
'target_branch' => default_branch_or_master, 'target_branch' => default_branch_or_main,
'original_branch' => default_branch_or_master, 'original_branch' => default_branch_or_main,
'can_push_code' => 'true', 'can_push_code' => 'true',
'path' => project_create_blob_path(project, default_branch_or_master), 'path' => project_create_blob_path(project, default_branch_or_main),
'project_path' => project.path 'project_path' => project.path
} }
) )
...@@ -268,7 +268,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -268,7 +268,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
def new_file_anchor_data def new_file_anchor_data
if can_current_user_push_to_default_branch? if can_current_user_push_to_default_branch?
new_file_path = empty_repo? ? ide_edit_path(project, default_branch_or_master) : project_new_blob_path(project, default_branch_or_master) new_file_path = empty_repo? ? ide_edit_path(project, default_branch_or_main) : project_new_blob_path(project, default_branch_or_main)
AnchorData.new(false, AnchorData.new(false,
statistic_icon + _('New file'), statistic_icon + _('New file'),
...@@ -472,7 +472,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -472,7 +472,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
commit_message ||= s_("CommitMessage|Add %{file_name}") % { file_name: file_name } commit_message ||= s_("CommitMessage|Add %{file_name}") % { file_name: file_name }
project_new_blob_path( project_new_blob_path(
project, project,
default_branch_or_master, default_branch_or_main,
file_name: file_name, file_name: file_name,
commit_message: commit_message, commit_message: commit_message,
branch_name: branch_name branch_name: branch_name
......
...@@ -30,7 +30,7 @@ module Ci ...@@ -30,7 +30,7 @@ module Ci
end end
def should_track_failures? def should_track_failures?
return false unless project.default_branch_or_master == pipeline.ref return false unless project.default_branch_or_main == pipeline.ref
# We fetch for up to MAX_TRACKABLE_FAILURES + 1 builds. So if ever we get # We fetch for up to MAX_TRACKABLE_FAILURES + 1 builds. So if ever we get
# 201 total number of builds with the assumption that each job has at least # 201 total number of builds with the assumption that each job has at least
......
...@@ -73,7 +73,7 @@ module MergeRequests ...@@ -73,7 +73,7 @@ module MergeRequests
end end
def default_branch def default_branch
target_project.default_branch || 'master' target_project.default_branch_or_main
end end
def merge_request def merge_request
......
...@@ -149,7 +149,7 @@ module Projects ...@@ -149,7 +149,7 @@ module Projects
def create_readme def create_readme
commit_attrs = { commit_attrs = {
branch_name: @project.default_branch || 'master', branch_name: @project.default_branch_or_main,
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}"
......
...@@ -39,7 +39,7 @@ module Repositories ...@@ -39,7 +39,7 @@ module Repositories
project, project,
user, user,
version:, version:,
branch: project.default_branch_or_master, branch: project.default_branch_or_main,
from: nil, from: nil,
to: branch, to: branch,
date: DateTime.now, date: DateTime.now,
......
...@@ -28,14 +28,14 @@ ...@@ -28,14 +28,14 @@
%li.dropdown-header= _('This repository') %li.dropdown-header= _('This repository')
- if can_push_code - if can_push_code
%li.qa-new-file-option= link_to _('New file'), project_new_blob_path(@project, @project.default_branch || 'master') %li.qa-new-file-option= link_to _('New file'), project_new_blob_path(@project, @project.default_branch_or_main)
- unless @project.empty_repo? - unless @project.empty_repo?
%li= link_to _('New branch'), new_project_branch_path(@project) %li= link_to _('New branch'), new_project_branch_path(@project)
%li= link_to _('New tag'), new_project_tag_path(@project) %li= link_to _('New tag'), new_project_tag_path(@project)
- elsif can_collaborate_with_project?(@project) - elsif can_collaborate_with_project?(@project)
%li= link_to _('New file'), project_new_blob_path(@project, @project.default_branch || 'master') %li= link_to _('New file'), project_new_blob_path(@project, @project.default_branch_or_main)
- elsif create_mr_from_new_fork - elsif create_mr_from_new_fork
- continue_params = { to: project_new_blob_path(@project, @project.default_branch || 'master'), - continue_params = { to: project_new_blob_path(@project, @project.default_branch_or_main),
notice: edit_in_new_fork_notice, notice: edit_in_new_fork_notice,
notice_now: edit_in_new_fork_notice_now } notice_now: edit_in_new_fork_notice_now }
- fork_path = project_forks_path(@project, namespace_key: current_user.namespace.id, continue: continue_params) - fork_path = project_forks_path(@project, namespace_key: current_user.namespace.id, continue: continue_params)
......
- @content_class = "limit-container-width" unless fluid_layout - @content_class = "limit-container-width" unless fluid_layout
- default_branch_name = @project.default_branch_or_master - default_branch_name = @project.default_branch_or_main
- @skip_current_level_breadcrumb = true - @skip_current_level_breadcrumb = true
= render partial: 'flash_messages', locals: { project: @project } = render partial: 'flash_messages', locals: { project: @project }
......
...@@ -7,4 +7,4 @@ ...@@ -7,4 +7,4 @@
"new-environment-path" => new_project_environment_path(@project), "new-environment-path" => new_project_environment_path(@project),
"help-page-path" => help_page_path("ci/environments/index.md"), "help-page-path" => help_page_path("ci/environments/index.md"),
"project-path" => @project.full_path, "project-path" => @project.full_path,
"default-branch-name" => @project.default_branch_or_master } } "default-branch-name" => @project.default_branch_or_main } }
---
title: Rename default branch for empty project actions
merge_request: 60258
author:
type: changed
---
name: main_branch_over_master
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/60258
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/329190
milestone: '13.12'
type: development
group: group::source code
default_enabled: false
...@@ -53,8 +53,8 @@ module Security ...@@ -53,8 +53,8 @@ module Security
security_policy_management_project.repository security_policy_management_project.repository
end end
def default_branch_or_master def default_branch_or_main
security_policy_management_project.default_branch_or_master security_policy_management_project.default_branch_or_main
end end
def active_policy_names_with_dast_profiles def active_policy_names_with_dast_profiles
...@@ -75,7 +75,7 @@ module Security ...@@ -75,7 +75,7 @@ module Security
end end
def scan_execution_policy_at(path) def scan_execution_policy_at(path)
policy_repo.blob_data_at(default_branch_or_master, path) policy_repo.blob_data_at(default_branch_or_main, path)
.then { |config| Gitlab::Config::Loader::Yaml.new(config).load!.fetch(:scan_execution_policy, []) } .then { |config| Gitlab::Config::Loader::Yaml.new(config).load!.fetch(:scan_execution_policy, []) }
end end
......
...@@ -53,7 +53,7 @@ module Projects ...@@ -53,7 +53,7 @@ module Projects
return '' if project.empty_repo? return '' if project.empty_repo?
gitlab_ci = Gitlab::FileDetector::PATTERNS[:gitlab_ci] gitlab_ci = Gitlab::FileDetector::PATTERNS[:gitlab_ci]
Gitlab::Routing.url_helpers.project_blame_path(project, File.join(project.default_branch_or_master, gitlab_ci)) Gitlab::Routing.url_helpers.project_blame_path(project, File.join(project.default_branch_or_main, gitlab_ci))
end end
def features def features
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
@version = attributes[:version] @version = attributes[:version]
end end
def blob_path_for(project, sha: project&.default_branch_or_master) def blob_path_for(project, sha: project&.default_branch_or_main)
return if path.blank? return if path.blank?
return path if sha.blank? return path if sha.blank?
......
...@@ -47,7 +47,7 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Dependency do ...@@ -47,7 +47,7 @@ RSpec.describe Gitlab::Ci::Reports::LicenseScanning::Dependency do
let(:project) { build_stubbed(:project) } let(:project) { build_stubbed(:project) }
specify { expect(subject).to eql("/#{project.namespace.path}/#{project.name}/-/blob/#{project.default_branch_or_master}/#{lockfile}") } specify { expect(subject).to eql("/#{project.namespace.path}/#{project.name}/-/blob/master/#{lockfile}") }
end end
end end
end end
...@@ -8,7 +8,7 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do ...@@ -8,7 +8,7 @@ RSpec.describe Security::OrchestrationPolicyConfiguration do
create( :security_orchestration_policy_configuration, security_policy_management_project: security_policy_management_project) create( :security_orchestration_policy_configuration, security_policy_management_project: security_policy_management_project)
end end
let(:default_branch) { security_policy_management_project.default_branch_or_master } let(:default_branch) { security_policy_management_project.default_branch }
let(:repository) { instance_double(Repository, root_ref: 'master') } let(:repository) { instance_double(Repository, root_ref: 'master') }
describe 'associations' do describe 'associations' do
......
...@@ -68,7 +68,7 @@ RSpec.describe DastOnDemandScans::CreateService do ...@@ -68,7 +68,7 @@ RSpec.describe DastOnDemandScans::CreateService do
auth_url: dast_site_profile.auth_url, auth_url: dast_site_profile.auth_url,
auth_username: dast_site_profile.auth_username, auth_username: dast_site_profile.auth_username,
auth_username_field: dast_site_profile.auth_username_field, auth_username_field: dast_site_profile.auth_username_field,
branch: project.default_branch_or_master, branch: project.default_branch,
dast_profile: nil, dast_profile: nil,
excluded_urls: dast_site_profile.excluded_urls.join(','), excluded_urls: dast_site_profile.excluded_urls.join(','),
full_scan_enabled: false, full_scan_enabled: false,
......
...@@ -55,7 +55,7 @@ RSpec.describe Security::SecurityOrchestrationPolicies::OnDemandScanPipelineConf ...@@ -55,7 +55,7 @@ RSpec.describe Security::SecurityOrchestrationPolicies::OnDemandScanPipelineConf
auth_username: site_profile.auth_username, auth_username: site_profile.auth_username,
auth_username_field: site_profile.auth_username_field, auth_username_field: site_profile.auth_username_field,
dast_profile: nil, dast_profile: nil,
branch: project.default_branch_or_master, branch: project.default_branch,
excluded_urls: site_profile.excluded_urls.join(','), excluded_urls: site_profile.excluded_urls.join(','),
full_scan_enabled: false, full_scan_enabled: false,
show_debug_messages: false, show_debug_messages: false,
......
...@@ -224,7 +224,7 @@ module API ...@@ -224,7 +224,7 @@ module API
desc: 'The commit message to use when committing the changelog' desc: 'The commit message to use when committing the changelog'
end end
post ':id/repository/changelog' do post ':id/repository/changelog' do
branch = params[:branch] || user_project.default_branch_or_master branch = params[:branch] || user_project.default_branch_or_main
access = Gitlab::UserAccess.new(current_user, container: user_project) access = Gitlab::UserAccess.new(current_user, container: user_project)
unless access.can_push_to_branch?(branch) unless access.can_push_to_branch?(branch)
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
def load! def load!
recent_failures_count.each do |key_hash, count| recent_failures_count.each do |key_hash, count|
failed_junit_tests[key_hash].set_recent_failures(count, project.default_branch_or_master) failed_junit_tests[key_hash].set_recent_failures(count, project.default_branch_or_main)
end end
end end
......
...@@ -194,7 +194,7 @@ FactoryBot.define do ...@@ -194,7 +194,7 @@ FactoryBot.define do
filename, filename,
content, content,
message: "Automatically created file #{filename}", message: "Automatically created file #{filename}",
branch_name: project.default_branch_or_master branch_name: project.default_branch || 'master'
) )
end end
end end
......
...@@ -85,7 +85,7 @@ RSpec.describe Gitlab::TreeSummary do ...@@ -85,7 +85,7 @@ RSpec.describe Gitlab::TreeSummary do
'long.txt', 'long.txt',
'', '',
message: message, message: message,
branch_name: project.default_branch_or_master branch_name: project.default_branch
) )
end end
......
...@@ -6892,6 +6892,37 @@ RSpec.describe Project, factory_default: :keep do ...@@ -6892,6 +6892,37 @@ RSpec.describe Project, factory_default: :keep do
end end
end end
describe '#default_branch_or_main' do
let(:project) { create(:project, :repository) }
before do
# Stubbing it as true since the FF disabled for tests globally
stub_feature_flags(main_branch_over_master: true)
end
it 'returns default branch' do
expect(project.default_branch_or_main).to eq(project.default_branch)
end
context 'when default branch is nil' do
let(:project) { create(:project, :empty_repo) }
it 'returns main' do
expect(project.default_branch_or_main).to eq('main')
end
context 'main_branch_over_master is disabled' do
before do
stub_feature_flags(main_branch_over_master: false)
end
it 'returns master' do
expect(project.default_branch_or_main).to eq('master')
end
end
end
end
def finish_job(export_job) def finish_job(export_job)
export_job.start export_job.start
export_job.finish export_job.finish
......
...@@ -275,6 +275,12 @@ RSpec.configure do |config| ...@@ -275,6 +275,12 @@ RSpec.configure do |config|
# https://gitlab.com/groups/gitlab-org/-/epics/5531 # https://gitlab.com/groups/gitlab-org/-/epics/5531
stub_feature_flags(refactor_blob_viewer: false) stub_feature_flags(refactor_blob_viewer: false)
# Disable `main_branch_over_master` as we migrate
# from `master` to `main` accross our codebase.
# It's done in order to preserve the concistency in tests
# As we're ready to change `master` usages to `main`, let's enable it
stub_feature_flags(main_branch_over_master: false)
allow(Gitlab::GitalyClient).to receive(:can_use_disk?).and_return(enable_rugged) allow(Gitlab::GitalyClient).to receive(:can_use_disk?).and_return(enable_rugged)
else else
unstub_all_feature_flags unstub_all_feature_flags
......
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