From 78f00682430f1034d8b9de66930ed65091fcc7ed Mon Sep 17 00:00:00 2001
From: Jacques <jerasmus@gitlab.com>
Date: Tue, 4 Mar 2025 11:35:44 +0100
Subject: [PATCH] Prevent editing squash option for All protected branches

Prevents editing squash options when the target is All protected branches
---
 .../branch_rules/components/view/index.vue       | 11 +++++++++--
 .../branch_rules/components/view/index_spec.js   | 16 ++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/app/assets/javascripts/projects/settings/branch_rules/components/view/index.vue b/app/assets/javascripts/projects/settings/branch_rules/components/view/index.vue
index a677529cc19d..3690f59852c4 100644
--- a/app/assets/javascripts/projects/settings/branch_rules/components/view/index.vue
+++ b/app/assets/javascripts/projects/settings/branch_rules/components/view/index.vue
@@ -230,8 +230,11 @@ export default {
     isAllBranchesRule() {
       return this.branch === this.$options.i18n.allBranches;
     },
+    isAllProtectedBranchesRule() {
+      return this.branch === this.$options.i18n.allProtectedBranches;
+    },
     isPredefinedRule() {
-      return this.isAllBranchesRule || this.branch === this.$options.i18n.allProtectedBranches;
+      return this.isAllBranchesRule || this.isAllProtectedBranchesRule;
     },
     hasPushAccessLevelSet() {
       return this.pushAccessLevels?.total > 0;
@@ -251,7 +254,11 @@ export default {
       return this.showApprovers || this.showSquashSetting;
     },
     showSquashSetting() {
-      return this.glFeatures.branchRuleSquashSettings && !this.branch?.includes('*'); // Squash settings are not available for wildcards
+      return (
+        this.glFeatures.branchRuleSquashSettings &&
+        !this.branch?.includes('*') &&
+        !this.isAllProtectedBranchesRule
+      ); // Squash settings are not available for wildcards or All protected branches
     },
     showEditSquashSetting() {
       return (
diff --git a/spec/frontend/projects/settings/branch_rules/components/view/index_spec.js b/spec/frontend/projects/settings/branch_rules/components/view/index_spec.js
index 24146e940b1a..c2d4e340dd49 100644
--- a/spec/frontend/projects/settings/branch_rules/components/view/index_spec.js
+++ b/spec/frontend/projects/settings/branch_rules/components/view/index_spec.js
@@ -319,6 +319,22 @@ describe('View branch rules', () => {
 
       expect(findSquashSettingSection().exists()).toBe(false);
     });
+
+    it.each`
+      branch                      | expectedExists | description
+      ${'main'}                   | ${true}        | ${'shows squash section for regular branch'}
+      ${'All branches'}           | ${true}        | ${'shows squash section for all branches'}
+      ${'All protected branches'} | ${false}       | ${'hides squash section for protected branches'}
+      ${'feature-*'}              | ${false}       | ${'hides squash section for wildcard branches'}
+    `('$description', async ({ branch, expectedExists }) => {
+      jest.spyOn(util, 'getParameterByName').mockReturnValueOnce(branch);
+
+      await createComponent({
+        glFeatures: { branchRuleSquashSettings: true },
+      });
+
+      expect(findSquashSettingSection().exists()).toBe(expectedExists);
+    });
   });
 
   it('renders page title', () => {
-- 
GitLab