From 73eb5097ef6cbbe5635f62019af4e18e992af414 Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Fri, 10 Jul 2020 13:07:25 -0600 Subject: [PATCH 1/2] Add new setting for the default initial branch name --- .../_initial_branch_name.html.haml | 12 ++++++++++++ .../admin/application_settings/repository.html.haml | 12 ++++++++++++ locale/gitlab.pot | 9 +++++++++ 3 files changed, 33 insertions(+) create mode 100644 app/views/admin/application_settings/_initial_branch_name.html.haml diff --git a/app/views/admin/application_settings/_initial_branch_name.html.haml b/app/views/admin/application_settings/_initial_branch_name.html.haml new file mode 100644 index 00000000000000..e76374e88a88c7 --- /dev/null +++ b/app/views/admin/application_settings/_initial_branch_name.html.haml @@ -0,0 +1,12 @@ += form_for @application_setting, url: general_admin_application_settings_path(anchor: 'js-default-branch-name'), html: { class: 'fieldset-form' } do |f| + = form_errors(@application_setting) + + - fallback_branch_name = 'master' + + %fieldset + .form-group + = f.label :default_branch_name, _('Default initial branch name'), class: 'label-light' + = f.text_field :default_branch_name, placeholder: 'master', class: 'form-control' + %span.form-text.text-muted + = (_("Changes affect new repositories only. If not specified, Git's default name %{branch_name_default} will be used.") % { branch_name_default: fallback_branch_name } ).html_safe + = f.submit _('Save changes'), class: 'gl-button btn-success' diff --git a/app/views/admin/application_settings/repository.html.haml b/app/views/admin/application_settings/repository.html.haml index b0934a9d9fb5cf..11de79cf4a2eaf 100644 --- a/app/views/admin/application_settings/repository.html.haml +++ b/app/views/admin/application_settings/repository.html.haml @@ -2,6 +2,18 @@ - page_title _("Repository") - @content_class = "limit-container-width" unless fluid_layout +- if Feature.enabled?(:global_default_branch_name) + %section.settings.as-default-branch-name.no-animate#js-default-branch-name{ class: ('expanded' if expanded_by_default?) } + .settings-header + %h4 + = _('Default initial branch name') + %button.gl-button.js-settings-toggle{ type: 'button' } + = expanded_by_default? ? _('Collapse') : _('Expand') + %p + = _('Set the default name of the initial branch when creating new repositories through the user interface.') + .settings-content + = render 'initial_branch_name' + %section.settings.as-mirror.no-animate#js-mirror-settings{ class: ('expanded' if expanded_by_default?) } .settings-header %h4 diff --git a/locale/gitlab.pot b/locale/gitlab.pot index ea171aa2e0d64c..489d39bc436738 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -4260,6 +4260,9 @@ msgstr "" msgid "Changes" msgstr "" +msgid "Changes affect new repositories only. If not specified, Git's default name %{branch_name_default} will be used." +msgstr "" + msgid "Changes are shown as if the source revision was being merged into the target revision." msgstr "" @@ -7405,6 +7408,9 @@ msgstr "" msgid "Default first day of the week in calendars and date pickers." msgstr "" +msgid "Default initial branch name" +msgstr "" + msgid "Default issue template" msgstr "" @@ -21068,6 +21074,9 @@ msgstr "" msgid "Set the default expiration time for each job's artifacts. 0 for unlimited. The default unit is in seconds, but you can define an alternative. For example: 4 mins 2 sec, 2h42min." msgstr "" +msgid "Set the default name of the initial branch when creating new repositories through the user interface." +msgstr "" + msgid "Set the due date to %{due_date}." msgstr "" -- GitLab From b8863bb3f8ee8912acf46473470197c886f9fac1 Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Wed, 8 Jul 2020 22:35:28 -0600 Subject: [PATCH 2/2] Add tests for default initial branch name setting --- .../repository.html.haml_spec.rb | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 spec/views/admin/application_settings/repository.html.haml_spec.rb diff --git a/spec/views/admin/application_settings/repository.html.haml_spec.rb b/spec/views/admin/application_settings/repository.html.haml_spec.rb new file mode 100644 index 00000000000000..b110bc277acdbc --- /dev/null +++ b/spec/views/admin/application_settings/repository.html.haml_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'admin/application_settings/repository.html.haml' do + let(:app_settings) { build(:application_setting) } + let(:user) { create(:admin) } + + before do + assign(:application_setting, app_settings) + allow(view).to receive(:current_user).and_return(user) + end + + describe 'default initial branch name' do + context 'when the feature flag is disabled' do + before do + stub_feature_flags(global_default_branch_name: false) + end + + it 'does not show the setting section' do + render + + expect(rendered).not_to have_css("#js-default-branch-name") + end + end + + context 'when the feature flag is enabled' do + before do + stub_feature_flags(global_default_branch_name: true) + end + + it 'has the setting section' do + render + + expect(rendered).to have_css("#js-default-branch-name") + end + + it 'renders the correct setting section content' do + render + + expect(rendered).to have_content("Default initial branch name") + expect(rendered).to have_content("Set the default name of the initial branch when creating new repositories through the user interface.") + end + end + end +end -- GitLab