diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-01-08 08:37:06 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-01-08 08:37:06 +0000 |
commit | 15f7f52b4034d4ede3b923e95df6884f36194245 (patch) | |
tree | 674772a3acaa716b2dd938defe0f66c63bd0970f /app/models | |
parent | 2c66b942bde756554b22d8b54c586fe45f544b0e (diff) | |
parent | 819fc98fed227487b0a273ee294e374e7457782b (diff) | |
download | gitlab-ce-15f7f52b4034d4ede3b923e95df6884f36194245.tar.gz |
Merge branch '3968-protected-branch-is-not-set-for-default-branch-on-import' into 'master'
Protected branch is now created for default branch on import
Closes #3968
See merge request gitlab-org/gitlab-ce!16198
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 4cb9d9fe637..fbe65e700a4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1450,6 +1450,7 @@ class Project < ActiveRecord::Base import_finish remove_import_jid update_project_counter_caches + after_create_default_branch end def update_project_counter_caches @@ -1463,6 +1464,27 @@ class Project < ActiveRecord::Base end end + def after_create_default_branch + return unless default_branch + + # Ensure HEAD points to the default branch in case it is not master + change_head(default_branch) + + if current_application_settings.default_branch_protection != Gitlab::Access::PROTECTION_NONE && !ProtectedBranch.protected?(self, default_branch) + params = { + name: default_branch, + push_access_levels_attributes: [{ + access_level: current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_PUSH ? Gitlab::Access::DEVELOPER : Gitlab::Access::MASTER + }], + merge_access_levels_attributes: [{ + access_level: current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE ? Gitlab::Access::DEVELOPER : Gitlab::Access::MASTER + }] + } + + ProtectedBranches::CreateService.new(self, creator, params).execute(skip_authorization: true) + end + end + def remove_import_jid return unless import_jid |