Skip to content

Commit 3103499

Browse files
committed
clean unrelated
1 parent 74760d5 commit 3103499

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

models/git/protected_banch_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestBranchRuleSort(t *testing.T) {
9292
RuleName: "a",
9393
CreatedUnix: 4,
9494
}}
95-
expect := []string{"a", "b", "c", "a/*", "b/*"}
95+
expect := []string{"c", "b", "a", "a/*", "b/*"}
9696

9797
pbr := ProtectedBranchRules(in)
9898
pbr.sort()

models/git/protected_branch_list.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package git
66
import (
77
"context"
88
"sort"
9-
"strings"
109

1110
"code.gitea.io/gitea/models/db"
1211
"code.gitea.io/gitea/modules/optional"
@@ -30,12 +29,7 @@ func (rules ProtectedBranchRules) sort() {
3029
rules[i].loadGlob()
3130
rules[j].loadGlob()
3231
if rules[i].isPlainName != rules[j].isPlainName {
33-
// plain name comes first, so plain name means "less"
34-
return rules[i].isPlainName
35-
}
36-
if rules[i].isPlainName {
37-
// both are plain names so sort alphabetically
38-
return strings.Compare(rules[i].RuleName, rules[j].RuleName) < 0
32+
return rules[i].isPlainName // plain name comes first, so plain name means "less"
3933
}
4034
return rules[i].CreatedUnix < rules[j].CreatedUnix
4135
})
@@ -48,7 +42,7 @@ func FindRepoProtectedBranchRules(ctx context.Context, repoID int64) (ProtectedB
4842
if err != nil {
4943
return nil, err
5044
}
51-
rules.sort() // make sure first match is detected in right order
45+
rules.sort() // to make non-glob rules have higher priority, and for same glob/non-glob rules, first created rules have higher priority
5246
return rules, nil
5347
}
5448

0 commit comments

Comments
 (0)