From 4ad7c599e7025eaf5233c914a5d1571ea1de7cea Mon Sep 17 00:00:00 2001 From: Giteabot Date: Fri, 31 May 2024 11:34:05 +0800 Subject: [PATCH] Fix branch order (#31174) (#31193) Backport #31174 by @lunny Fix #31172 The original order or the default order should not be ignored even if we have an is_deleted order. Co-authored-by: Lunny Xiao (cherry picked from commit c6176ee59f4a25607dcfbc00757121f705101101) --- models/git/branch_list.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/models/git/branch_list.go b/models/git/branch_list.go index c6fc8ad4b1..9f79d72cde 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -92,17 +92,13 @@ func (opts FindBranchOptions) ToConds() builder.Cond { func (opts FindBranchOptions) ToOrders() string { orderBy := opts.OrderBy - if opts.IsDeletedBranch.ValueOrDefault(true) { // if deleted branch included, put them at the end - if orderBy != "" { - orderBy += ", " - } - orderBy += "is_deleted ASC" - } if orderBy == "" { // the commit_time might be the same, so add the "name" to make sure the order is stable - return "commit_time DESC, name ASC" + orderBy = "commit_time DESC, name ASC" + } + if opts.IsDeletedBranch.ValueOrDefault(true) { // if deleted branch included, put them at the beginning + orderBy = "is_deleted ASC, " + orderBy } - return orderBy }