diff options
author | Marco Wessel <marco@poop.nl> | 2015-01-25 16:33:54 +0100 |
---|---|---|
committer | Marco Wessel <marco@poop.nl> | 2015-01-25 17:09:10 +0100 |
commit | aad6ceaef9ccfba8e058012a0877b80c103a3838 (patch) | |
tree | 33042a755f2c35024c140f20e9d63aba7e450ff4 /app | |
parent | 254d1d7aa07fd1b45dd4090e98bcba86f5d3c699 (diff) | |
download | gitlab-ce-aad6ceaef9ccfba8e058012a0877b80c103a3838.tar.gz |
Allow configuring protection of the default branch upon first push
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/application_settings_controller.rb | 1 | ||||
-rw-r--r-- | app/models/application_setting.rb | 2 | ||||
-rw-r--r-- | app/services/git_push_service.rb | 10 | ||||
-rw-r--r-- | app/views/admin/application_settings/_form.html.haml | 4 |
4 files changed, 15 insertions, 2 deletions
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb index a937f484877..7458542fc73 100644 --- a/app/controllers/admin/application_settings_controller.rb +++ b/app/controllers/admin/application_settings_controller.rb @@ -22,6 +22,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController def application_setting_params params.require(:application_setting).permit( :default_projects_limit, + :default_branch_protection, :signup_enabled, :signin_enabled, :gravatar_enabled, diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 45ae79a75cc..3285a1a248e 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -4,6 +4,7 @@ # # id :integer not null, primary key # default_projects_limit :integer +# default_branch_protection :integer # signup_enabled :boolean # signin_enabled :boolean # gravatar_enabled :boolean @@ -25,6 +26,7 @@ class ApplicationSetting < ActiveRecord::Base def self.create_from_defaults create( default_projects_limit: Settings.gitlab['default_projects_limit'], + default_branch_protection: Settings.gitlab['default_branch_protection'], signup_enabled: Settings.gitlab['signup_enabled'], signin_enabled: Settings.gitlab['signin_enabled'], gravatar_enabled: Settings.gravatar['enabled'], diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index 872b886c575..b45ca0a5e6b 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -1,5 +1,7 @@ class GitPushService attr_accessor :project, :user, :push_data, :push_commits + include Gitlab::CurrentSettings + include Gitlab::Access # This method will be called after each git update # and only if the provided user and project is present in GitLab. @@ -29,8 +31,12 @@ class GitPushService if is_default_branch?(ref) # Initial push to the default branch. Take the full history of that branch as "newly pushed". @push_commits = project.repository.commits(newrev) - # Default branch is protected by default - project.protected_branches.create({ name: project.default_branch }) + + # Set protection on the default branch if configured + if (current_application_settings.default_branch_protection != PROTECTION_NONE) + developers_can_push = current_application_settings.default_branch_protection == PROTECTION_DEV_CAN_PUSH ? true : false + project.protected_branches.create({ name: project.default_branch, developers_can_push: developers_can_push }) + end else # Use the pushed commits that aren't reachable by the default branch # as a heuristic. This may include more commits than are actually pushed, but diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index 9423a207068..bf0ee49d2f4 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -26,6 +26,10 @@ .col-sm-10 = f.number_field :default_projects_limit, class: 'form-control' .form-group + = f.label :default_branch_protection, class: 'control-label' + .col-sm-10 + = f.select :default_branch_protection, options_for_select(Gitlab::Access.protection_options, @application_setting.default_branch_protection), {}, class: 'form-control' + .form-group = f.label :home_page_url, class: 'control-label' .col-sm-10 = f.text_field :home_page_url, class: 'form-control', placeholder: 'http://company.example.com' |