Skip to content

Commit

Permalink
Fix branch order (#31174) (#31193)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
GiteaBot and lunny authored May 31, 2024
1 parent e8c776c commit c6176ee
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions models/git/branch_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit c6176ee

Please sign in to comment.