From 18eef3b23a45d50da94d39a9559388b4b53545a8 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 31 May 2024 09:58:41 +0800 Subject: [PATCH] Fix branch order (#31174) Fix #31172 The original order or the default order should not be ignored even if we have an is_deleted order. (cherry picked from commit 1137a0357eb1e35a046e86a7277594154d0f6c85) --- 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 493611f217..81a43eaea3 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -88,17 +88,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 }