Add default branch to top results for branch rules pagination
What does this MR do and why?
The branch rules finder currently returns the sort order:
All branchesAll protected branches- Everything else alphabetically sorted
But it should have the sort order:
All branchesAll protected branches- Default branch
- Everything else alphabetically sorted
This MR adds the default branch to the top of the returned protected branches.
Query
scope :excluding_name, ->(name) { where.not(name: name) if name.present? }
https://console.postgres.ai/gitlab/gitlab-production-main/sessions/46478/commands/141764
SELECT "protected_branches".* FROM "protected_branches"
WHERE "protected_branches"."project_id" = 278964
AND "protected_branches"."name" != 'master'
References
See #576206 (comment 2949957056)
Screenshots or screen recordings
| before | after |
|---|---|
|
|
How to set up and validate locally
- Create a test project with multiple protected branches (e.g., 'a', 'b', 'c', 'main')
- Ensure 'main' is set as the default branch for the project
- Create protected branch rule for each branch
- Navigate to the project's branch rules page:
http://gdk.test:3000/[namespace]/[project]/-/settings/repository#branch-rules - Verify the sort order is:
- All branches rule
- All protected branches rule
- Default branch (main) rule
- Other branches in alphabetical order (a, b, c)
- Paginate through results and verify the default branch only appears on the first page
- Verify later pages exclude the default branch and show remaining branches in order
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Gavin Hinfey

