summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-01-08 08:37:06 +0000
committerDouwe Maan <douwe@gitlab.com>2018-01-08 08:37:06 +0000
commit15f7f52b4034d4ede3b923e95df6884f36194245 (patch)
tree674772a3acaa716b2dd938defe0f66c63bd0970f /app/models
parent2c66b942bde756554b22d8b54c586fe45f544b0e (diff)
parent819fc98fed227487b0a273ee294e374e7457782b (diff)
downloadgitlab-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.rb22
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