From e0caca67eff42123036cb5b458ff9a029a09c847 Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Wed, 21 Oct 2020 10:19:52 -0600 Subject: [PATCH 01/21] Add group-level default initial branch name setting --- .../repository/_initial_branch_name.html.haml | 21 +++++++++++++++++++ .../groups/settings/repository/show.html.haml | 1 + 2 files changed, 22 insertions(+) create mode 100644 app/views/groups/settings/repository/_initial_branch_name.html.haml diff --git a/app/views/groups/settings/repository/_initial_branch_name.html.haml b/app/views/groups/settings/repository/_initial_branch_name.html.haml new file mode 100644 index 00000000000000..6822662b5ea0a8 --- /dev/null +++ b/app/views/groups/settings/repository/_initial_branch_name.html.haml @@ -0,0 +1,21 @@ +%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 + = form_for @group, url: group_path(@group, anchor: 'js-default-branch-name'), html: { class: 'fieldset-form' } do |f| + = form_errors(@group) + + - 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, value: group.namespace_settings.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/groups/settings/repository/show.html.haml b/app/views/groups/settings/repository/show.html.haml index ff0c9de4fef866..a5819320405587 100644 --- a/app/views/groups/settings/repository/show.html.haml +++ b/app/views/groups/settings/repository/show.html.haml @@ -4,3 +4,4 @@ - deploy_token_description = s_('DeployTokens|Group deploy tokens allow access to the packages, repositories, and registry images within the group.') = render "shared/deploy_tokens/index", group_or_project: @group, description: deploy_token_description += render "initial_branch_name", group: @group -- GitLab From d659dfca999815dcd3ca79e42ba1c1bbf167e3bc Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Thu, 24 Sep 2020 06:24:16 -0600 Subject: [PATCH 02/21] Add changelog for group-level new setting --- .../unreleased/feature-group-default-initial-branch-name.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/feature-group-default-initial-branch-name.yml diff --git a/changelogs/unreleased/feature-group-default-initial-branch-name.yml b/changelogs/unreleased/feature-group-default-initial-branch-name.yml new file mode 100644 index 00000000000000..b3059a2c0b2d6e --- /dev/null +++ b/changelogs/unreleased/feature-group-default-initial-branch-name.yml @@ -0,0 +1,5 @@ +--- +title: Add Default Initial Branch Name for Repositories Group Setting +merge_request: 43290 +author: +type: added -- GitLab From c2ad8375d875efd1b27c42c6fff74c3b2db49203 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Thu, 15 Oct 2020 13:20:13 -0700 Subject: [PATCH 03/21] Delegate #default_branch_name to namespace_settings --- app/models/group.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/group.rb b/app/models/group.rb index 32ccc4ed3a7e5f..a20888e040b82f 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -109,6 +109,8 @@ class Group < Namespace .where("project_authorizations.user_id IN (?)", user_ids) end + delegate :default_branch_name, to: :namespace_settings + class << self def sort_by_attribute(method) if method == 'storage_size_desc' -- GitLab From cc01375d1f64d5fe702306b7d8fd3db8662cbe83 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Thu, 15 Oct 2020 14:36:56 -0700 Subject: [PATCH 04/21] Allow for redirect_target to hint at landing location --- app/controllers/groups_controller.rb | 8 +++++++- .../settings/repository/_initial_branch_name.html.haml | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 89e82e5db97495..cdad28099eea5f 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -132,7 +132,13 @@ def projects def update if Groups::UpdateService.new(@group, current_user, group_params).execute - redirect_to edit_group_path(@group, anchor: params[:update_section]), notice: "Group '#{@group.name}' was successfully updated." + notice = "Group '#{@group.name}' was successfully updated." + + if params.dig(:group, :redirect_target) == "repository_settings" + redirect_to group_settings_repository_path(@group, anchor: 'js-default-branch-name'), notice: notice + else + redirect_to edit_group_path(@group, anchor: params[:update_section]), notice: notice + end else @group.reset render action: "edit" diff --git a/app/views/groups/settings/repository/_initial_branch_name.html.haml b/app/views/groups/settings/repository/_initial_branch_name.html.haml index 6822662b5ea0a8..a3f40585c17790 100644 --- a/app/views/groups/settings/repository/_initial_branch_name.html.haml +++ b/app/views/groups/settings/repository/_initial_branch_name.html.haml @@ -18,4 +18,6 @@ = f.text_field :default_branch_name, value: group.namespace_settings.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.hidden_field :redirect_target, value: "repository_settings" = f.submit _('Save changes'), class: 'gl-button btn-success' -- GitLab From 8e59eea2a7377ac262f3cc89b732cbab87f8e98e Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Thu, 15 Oct 2020 17:25:33 -0600 Subject: [PATCH 05/21] Add feature flag for group default initial branch name --- app/views/groups/settings/repository/show.html.haml | 4 +++- .../development/group_default_initial_branch_name_ui.yml | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 config/feature_flags/development/group_default_initial_branch_name_ui.yml diff --git a/app/views/groups/settings/repository/show.html.haml b/app/views/groups/settings/repository/show.html.haml index a5819320405587..cf60ad2c38d390 100644 --- a/app/views/groups/settings/repository/show.html.haml +++ b/app/views/groups/settings/repository/show.html.haml @@ -4,4 +4,6 @@ - deploy_token_description = s_('DeployTokens|Group deploy tokens allow access to the packages, repositories, and registry images within the group.') = render "shared/deploy_tokens/index", group_or_project: @group, description: deploy_token_description -= render "initial_branch_name", group: @group + +- if Feature.enabled?(:group_default_initial_branch_name_ui, default_enabled: true) + = render "initial_branch_name", group: @group diff --git a/config/feature_flags/development/group_default_initial_branch_name_ui.yml b/config/feature_flags/development/group_default_initial_branch_name_ui.yml new file mode 100644 index 00000000000000..822b75afe38659 --- /dev/null +++ b/config/feature_flags/development/group_default_initial_branch_name_ui.yml @@ -0,0 +1,7 @@ +--- +name: group_default_initial_branch_name_ui +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/43290 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/268159 +type: development +group: group::source code +default_enabled: true -- GitLab From 0769233b3a61c52baa43070d56e10b7cefe23102 Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Sun, 18 Oct 2020 01:48:58 -0600 Subject: [PATCH 06/21] Add documentation for the UI to change the group branch default name --- doc/user/group/index.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/doc/user/group/index.md b/doc/user/group/index.md index 7a816c96f599d5..6088602b12996f 100644 --- a/doc/user/group/index.md +++ b/doc/user/group/index.md @@ -518,6 +518,47 @@ If you want to retain ownership over the original namespace and protect the URL redirects, then instead of changing a group's path or renaming a username, you can create a new group and transfer projects to it. +### Group repository settings + +You can change settings that are specific to repositories in your group. + +#### Custom initial branch name **(CORE ONLY)** + +> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/43290) in GitLab 13.6. +> - It's deployed behind a feature flag, enabled by default. +> - It's enabled on GitLab.com. +> - It cannot be enabled or disabled per-project. +> - It's recommended for production use. +> - For GitLab self-managed instances, GitLab administrators can opt to [disable the visible interface](#enable-or-disable-custom-initial-branch-name). **(CORE ONLY)** + +By default, when you create a new project in GitLab, the initial branch is called `master`. +For groups, a group administrator can customize the initial branch name to something +else. This way, every new project created under that group from then on will start from the custom branch name rather than `master`. To do so: + +1. Go to the **Group page > Settings > Repository** and expand **Default initial + branch name**. +1. Change the default initial branch to a custom name of your choice. +1. **Save Changes**. + +##### Enable or disable custom initial branch name **(CORE ONLY)** + +Setting the group default initial branch name is under development but ready for production use. +The visual interface to set it is deployed behind a feature flag that is **enabled by default**. +[GitLab administrators with access to the GitLab Rails console](../../administration/feature_flags.md) +can opt to disable it for your instance. + +To disable it: + +```ruby +Feature.disable(:group_default_initial_branch_name_ui) +``` + +To enable it: + +```ruby +Feature.enable(:group_default_initial_branch_name_ui) +``` + ### Remove a group To remove a group and its contents: -- GitLab From 397ea04a19a3d08272dd223c4194989b266eff5a Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Thu, 22 Oct 2020 16:24:50 +0000 Subject: [PATCH 07/21] Apply 1 suggestion(s) to 1 file(s) --- .../groups/settings/repository/_initial_branch_name.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/groups/settings/repository/_initial_branch_name.html.haml b/app/views/groups/settings/repository/_initial_branch_name.html.haml index a3f40585c17790..b8ad87a1803567 100644 --- a/app/views/groups/settings/repository/_initial_branch_name.html.haml +++ b/app/views/groups/settings/repository/_initial_branch_name.html.haml @@ -15,7 +15,7 @@ %fieldset .form-group = f.label :default_branch_name, _('Default initial branch name'), class: 'label-light' - = f.text_field :default_branch_name, value: group.namespace_settings.default_branch_name, placeholder: 'master', class: 'form-control' + = f.text_field :default_branch_name, value: group.namespace_settings&.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 -- GitLab From d59dc363765568902c5327719cc1511fdafa4178 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Mon, 26 Oct 2020 10:31:22 -0700 Subject: [PATCH 08/21] Extract #edit_group_origin_location to tidy #update --- app/controllers/groups_controller.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index cdad28099eea5f..8d528e123e180d 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -134,17 +134,21 @@ def update if Groups::UpdateService.new(@group, current_user, group_params).execute notice = "Group '#{@group.name}' was successfully updated." - if params.dig(:group, :redirect_target) == "repository_settings" - redirect_to group_settings_repository_path(@group, anchor: 'js-default-branch-name'), notice: notice - else - redirect_to edit_group_path(@group, anchor: params[:update_section]), notice: notice - end + redirect_to edit_group_origin_location, notice: notice else @group.reset render action: "edit" end end + def edit_group_origin_location + if params.dig(:group, :redirect_target) == 'repository_settings' + group_settings_repository_path(@group, anchor: 'js-default-branch-name') + else + edit_group_path(@group, anchor: params[:update_section]) + end + end + def destroy Groups::DestroyService.new(@group, current_user).async_execute -- GitLab From a9c4bd5a0ceda0430fb386f4866c047778fa1fdc Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Mon, 26 Oct 2020 13:10:06 -0600 Subject: [PATCH 09/21] Remove UI-only feature flag --- app/views/groups/settings/repository/show.html.haml | 4 +--- .../development/group_default_initial_branch_name_ui.yml | 7 ------- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 config/feature_flags/development/group_default_initial_branch_name_ui.yml diff --git a/app/views/groups/settings/repository/show.html.haml b/app/views/groups/settings/repository/show.html.haml index cf60ad2c38d390..a5819320405587 100644 --- a/app/views/groups/settings/repository/show.html.haml +++ b/app/views/groups/settings/repository/show.html.haml @@ -4,6 +4,4 @@ - deploy_token_description = s_('DeployTokens|Group deploy tokens allow access to the packages, repositories, and registry images within the group.') = render "shared/deploy_tokens/index", group_or_project: @group, description: deploy_token_description - -- if Feature.enabled?(:group_default_initial_branch_name_ui, default_enabled: true) - = render "initial_branch_name", group: @group += render "initial_branch_name", group: @group diff --git a/config/feature_flags/development/group_default_initial_branch_name_ui.yml b/config/feature_flags/development/group_default_initial_branch_name_ui.yml deleted file mode 100644 index 822b75afe38659..00000000000000 --- a/config/feature_flags/development/group_default_initial_branch_name_ui.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -name: group_default_initial_branch_name_ui -introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/43290 -rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/268159 -type: development -group: group::source code -default_enabled: true -- GitLab From 05ca93b3f2d7653f982b0ffd9fbf61fbdf64565a Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Mon, 26 Oct 2020 14:31:28 -0600 Subject: [PATCH 10/21] Test that the new UI is rendered properly --- .../features/groups/settings/repository_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/features/groups/settings/repository_spec.rb b/spec/features/groups/settings/repository_spec.rb index d20303027e592b..3c1609a260531d 100644 --- a/spec/features/groups/settings/repository_spec.rb +++ b/spec/features/groups/settings/repository_spec.rb @@ -25,4 +25,21 @@ let(:entity_type) { 'group' } end end + + context 'Default initial branch name' do + before do + visit group_settings_repository_path(group) + end + + it 'has the setting section' do + expect(page).to have_css("#js-default-branch-name") + end + + it 'renders the correct setting section content' do + within("#js-default-branch-name") do + expect(page).to have_content("Default initial branch name") + expect(page).to have_content("Set the default name of the initial branch when creating new repositories through the user interface.") + end + end + end end -- GitLab From 15ec4e2560c6acfc04e7f3a981738f4ee3b53ced Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Mon, 26 Oct 2020 14:36:30 -0600 Subject: [PATCH 11/21] Remove feature flag for the Group initial branch name UI --- doc/user/group/index.md | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/doc/user/group/index.md b/doc/user/group/index.md index 6088602b12996f..59b24ea8847e03 100644 --- a/doc/user/group/index.md +++ b/doc/user/group/index.md @@ -525,11 +525,6 @@ You can change settings that are specific to repositories in your group. #### Custom initial branch name **(CORE ONLY)** > - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/43290) in GitLab 13.6. -> - It's deployed behind a feature flag, enabled by default. -> - It's enabled on GitLab.com. -> - It cannot be enabled or disabled per-project. -> - It's recommended for production use. -> - For GitLab self-managed instances, GitLab administrators can opt to [disable the visible interface](#enable-or-disable-custom-initial-branch-name). **(CORE ONLY)** By default, when you create a new project in GitLab, the initial branch is called `master`. For groups, a group administrator can customize the initial branch name to something @@ -540,25 +535,6 @@ else. This way, every new project created under that group from then on will sta 1. Change the default initial branch to a custom name of your choice. 1. **Save Changes**. -##### Enable or disable custom initial branch name **(CORE ONLY)** - -Setting the group default initial branch name is under development but ready for production use. -The visual interface to set it is deployed behind a feature flag that is **enabled by default**. -[GitLab administrators with access to the GitLab Rails console](../../administration/feature_flags.md) -can opt to disable it for your instance. - -To disable it: - -```ruby -Feature.disable(:group_default_initial_branch_name_ui) -``` - -To enable it: - -```ruby -Feature.enable(:group_default_initial_branch_name_ui) -``` - ### Remove a group To remove a group and its contents: -- GitLab From 53fe05c37a491c8928fd8df9adeaa86e56d44557 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Tue, 27 Oct 2020 11:44:39 -0700 Subject: [PATCH 12/21] Reject nil values from incoming params --- app/services/namespace_settings/update_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/namespace_settings/update_service.rb b/app/services/namespace_settings/update_service.rb index 3c9b7b637acc04..37bdd80cd29d98 100644 --- a/app/services/namespace_settings/update_service.rb +++ b/app/services/namespace_settings/update_service.rb @@ -9,7 +9,7 @@ class UpdateService def initialize(current_user, group, settings) @current_user = current_user @group = group - @settings_params = settings + @settings_params = settings.reject { |_, v| v.blank? } end def execute -- GitLab From cfb0fa33169fd3f70abdad97b47c81e13ecd39fa Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Wed, 28 Oct 2020 16:36:20 -0600 Subject: [PATCH 13/21] Correct form input text to be more accurate --- .../groups/settings/repository/_initial_branch_name.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/groups/settings/repository/_initial_branch_name.html.haml b/app/views/groups/settings/repository/_initial_branch_name.html.haml index b8ad87a1803567..87c2ecf52495f9 100644 --- a/app/views/groups/settings/repository/_initial_branch_name.html.haml +++ b/app/views/groups/settings/repository/_initial_branch_name.html.haml @@ -17,7 +17,7 @@ = f.label :default_branch_name, _('Default initial branch name'), class: 'label-light' = f.text_field :default_branch_name, value: group.namespace_settings&.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 + = (_("Changes affect new repositories only. If not specified, either the configured application-wide default or Git's default name %{branch_name_default} will be used.") % { branch_name_default: fallback_branch_name }).html_safe = f.hidden_field :redirect_target, value: "repository_settings" = f.submit _('Save changes'), class: 'gl-button btn-success' -- GitLab From ffef1d6520085213459ccb6f95e6c2a50000a68a Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Thu, 29 Oct 2020 06:09:46 -0600 Subject: [PATCH 14/21] Update text translations --- locale/gitlab.pot | 3 +++ 1 file changed, 3 insertions(+) diff --git a/locale/gitlab.pot b/locale/gitlab.pot index d04a3507c37e1e..06b84ce3f323ab 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -4923,6 +4923,9 @@ msgstr "" msgid "Changes affect new repositories only. If not specified, Git's default name %{branch_name_default} will be used." msgstr "" +msgid "Changes affect new repositories only. If not specified, either the configured application-wide default or Git's default name %{branch_name_default} will be used." +msgstr "" + msgid "Changes are shown as if the %{b_open}source%{b_close} revision was being merged into the %{b_open}target%{b_close} revision." msgstr "" -- GitLab From 30e9a15e2814d874b1b5033a92089d3165e6080a Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 30 Oct 2020 08:15:00 -0700 Subject: [PATCH 15/21] Use compact and remove empty strings because #blank? removes 'false' --- app/services/namespace_settings/update_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/namespace_settings/update_service.rb b/app/services/namespace_settings/update_service.rb index 37bdd80cd29d98..5b1f9ad3b4bdb9 100644 --- a/app/services/namespace_settings/update_service.rb +++ b/app/services/namespace_settings/update_service.rb @@ -9,7 +9,7 @@ class UpdateService def initialize(current_user, group, settings) @current_user = current_user @group = group - @settings_params = settings.reject { |_, v| v.blank? } + @settings_params = settings.compact.delete_if { |_, v| v.to_s.strip == '' } end def execute -- GitLab From 57fd39b7b292dd19cd4a62609e388e80ad56cbc1 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 30 Oct 2020 10:13:46 -0700 Subject: [PATCH 16/21] Compact isn't available yet on params --- app/services/namespace_settings/update_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/namespace_settings/update_service.rb b/app/services/namespace_settings/update_service.rb index 5b1f9ad3b4bdb9..e286d3d17e4f27 100644 --- a/app/services/namespace_settings/update_service.rb +++ b/app/services/namespace_settings/update_service.rb @@ -9,7 +9,7 @@ class UpdateService def initialize(current_user, group, settings) @current_user = current_user @group = group - @settings_params = settings.compact.delete_if { |_, v| v.to_s.strip == '' } + @settings_params = settings.delete_if { |_, v| v.to_s.strip == '' } end def execute -- GitLab From 614d8c1e89d86b0120935d365f2fa4842415f3aa Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 30 Oct 2020 14:38:43 -0700 Subject: [PATCH 17/21] Remove params filtering from UpdateService --- app/services/namespace_settings/update_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/namespace_settings/update_service.rb b/app/services/namespace_settings/update_service.rb index e286d3d17e4f27..3c9b7b637acc04 100644 --- a/app/services/namespace_settings/update_service.rb +++ b/app/services/namespace_settings/update_service.rb @@ -9,7 +9,7 @@ class UpdateService def initialize(current_user, group, settings) @current_user = current_user @group = group - @settings_params = settings.delete_if { |_, v| v.to_s.strip == '' } + @settings_params = settings end def execute -- GitLab From c93609b4ab6a366e12c009a21c2e5ab12115d793 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 30 Oct 2020 14:39:23 -0700 Subject: [PATCH 18/21] Set default_branch_name to nil when empty string --- app/models/namespace_setting.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/namespace_setting.rb b/app/models/namespace_setting.rb index 6f31208f28b3d4..960f003a6b7fbd 100644 --- a/app/models/namespace_setting.rb +++ b/app/models/namespace_setting.rb @@ -6,10 +6,18 @@ class NamespaceSetting < ApplicationRecord validate :default_branch_name_content validate :allow_mfa_for_group + before_validation :normalize_default_branch_name + NAMESPACE_SETTINGS_PARAMS = [:default_branch_name].freeze self.primary_key = :namespace_id + private + + def normalize_default_branch_name + self.default_branch_name = nil if default_branch_name.to_s.strip == "" + end + def default_branch_name_content return if default_branch_name.nil? -- GitLab From 3a597327075203b0d61049f69ebc32b7f2503942 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 30 Oct 2020 19:15:39 -0700 Subject: [PATCH 19/21] Tweak test to match before_validation result --- spec/models/namespace_setting_spec.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/spec/models/namespace_setting_spec.rb b/spec/models/namespace_setting_spec.rb index c6e8d5b129cbac..59b7510051f65d 100644 --- a/spec/models/namespace_setting_spec.rb +++ b/spec/models/namespace_setting_spec.rb @@ -36,13 +36,10 @@ context "when an empty string" do before do - namespace_settings.default_branch_name = '' + namespace_settings.default_branch_name = "" end - it "returns an error" do - expect(namespace_settings.valid?).to be_falsey - expect(namespace_settings.errors.full_messages).not_to be_empty - end + it_behaves_like "doesn't return an error" end end -- GitLab From 5b571b5c25a827e02c18f0e25f10b654fede3865 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Tue, 3 Nov 2020 08:37:04 -0800 Subject: [PATCH 20/21] Duh use #blank? --- app/models/namespace_setting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/namespace_setting.rb b/app/models/namespace_setting.rb index 960f003a6b7fbd..50844403d7f514 100644 --- a/app/models/namespace_setting.rb +++ b/app/models/namespace_setting.rb @@ -15,7 +15,7 @@ class NamespaceSetting < ApplicationRecord private def normalize_default_branch_name - self.default_branch_name = nil if default_branch_name.to_s.strip == "" + self.default_branch_name = nil if default_branch_name.blank? end def default_branch_name_content -- GitLab From d811223595a55acf09fe92e74969aca671e4d33a Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Tue, 3 Nov 2020 08:38:07 -0800 Subject: [PATCH 21/21] Remove extraneoous blank line --- .../groups/settings/repository/_initial_branch_name.html.haml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/groups/settings/repository/_initial_branch_name.html.haml b/app/views/groups/settings/repository/_initial_branch_name.html.haml index 87c2ecf52495f9..3ef8dccae0834a 100644 --- a/app/views/groups/settings/repository/_initial_branch_name.html.haml +++ b/app/views/groups/settings/repository/_initial_branch_name.html.haml @@ -9,7 +9,6 @@ .settings-content = form_for @group, url: group_path(@group, anchor: 'js-default-branch-name'), html: { class: 'fieldset-form' } do |f| = form_errors(@group) - - fallback_branch_name = 'master' %fieldset -- GitLab