]> source.dussan.org Git - gitea.git/commitdiff
Fix branch order (#31174) (#31193)
authorGiteabot <teabot@gitea.io>
Fri, 31 May 2024 03:34:05 +0000 (11:34 +0800)
committerGitHub <noreply@github.com>
Fri, 31 May 2024 03:34:05 +0000 (11:34 +0800)
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 <xiaolunwen@gmail.com>
models/git/branch_list.go

index 5c887461d5a0708573b036c8a8b81cb394182139..25e84526d29e4eee4905f18e4abc0508676fbf10 100644 (file)
@@ -107,17 +107,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
 }