Commit c4604fbd authored by Igor Drozdov's avatar Igor Drozdov

Create main branch if no branches exist

Currently when we create a branch and the repo is empty
`master` branch is created by default.

Let's create `main` branch in this case instead
parent 15448f95
......@@ -152,7 +152,7 @@ class Projects::BranchesController < Projects::ApplicationController
ref_escaped = strip_tags(sanitize(params[:ref]))
Addressable::URI.unescape(ref_escaped)
else
@project.default_branch || 'master'
@project.default_branch_or_main
end
end
......
......@@ -2,8 +2,8 @@
module Branches
class CreateService < BaseService
def execute(branch_name, ref, create_master_if_empty: true)
create_master_branch if create_master_if_empty && project.empty_repo?
def execute(branch_name, ref, create_default_branch_if_empty: true)
create_default_branch if create_default_branch_if_empty && project.empty_repo?
result = ::Branches::ValidateNewService.new(project).execute(branch_name)
......@@ -27,13 +27,13 @@ module Branches
private
def create_master_branch
def create_default_branch
project.repository.create_file(
current_user,
'/README.md',
'',
message: 'Add README.md',
branch_name: 'master'
branch_name: project.default_branch_or_main
)
end
end
......
......@@ -73,7 +73,7 @@ module Projects
local_branch = local_branches[name]
if local_branch.nil?
result = ::Branches::CreateService.new(project, current_user).execute(name, upstream_branch.dereferenced_target.sha, create_master_if_empty: false)
result = ::Branches::CreateService.new(project, current_user).execute(name, upstream_branch.dereferenced_target.sha, create_default_branch_if_empty: false)
if result[:status] == :error
errors << result[:message]
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