0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2025-01-06 05:24:27 +01:00

clean unrelated

This commit is contained in:
6543 2024-10-17 10:32:18 +02:00
parent 74760d5223
commit 3103499b2a
2 changed files with 3 additions and 9 deletions

View file

@ -92,7 +92,7 @@ func TestBranchRuleSort(t *testing.T) {
RuleName: "a",
CreatedUnix: 4,
}}
expect := []string{"a", "b", "c", "a/*", "b/*"}
expect := []string{"c", "b", "a", "a/*", "b/*"}
pbr := ProtectedBranchRules(in)
pbr.sort()

View file

@ -6,7 +6,6 @@ package git
import (
"context"
"sort"
"strings"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/optional"
@ -30,12 +29,7 @@ func (rules ProtectedBranchRules) sort() {
rules[i].loadGlob()
rules[j].loadGlob()
if rules[i].isPlainName != rules[j].isPlainName {
// plain name comes first, so plain name means "less"
return rules[i].isPlainName
}
if rules[i].isPlainName {
// both are plain names so sort alphabetically
return strings.Compare(rules[i].RuleName, rules[j].RuleName) < 0
return rules[i].isPlainName // plain name comes first, so plain name means "less"
}
return rules[i].CreatedUnix < rules[j].CreatedUnix
})
@ -48,7 +42,7 @@ func FindRepoProtectedBranchRules(ctx context.Context, repoID int64) (ProtectedB
if err != nil {
return nil, err
}
rules.sort() // make sure first match is detected in right order
rules.sort() // to make non-glob rules have higher priority, and for same glob/non-glob rules, first created rules have higher priority
return rules, nil
}