From 3103499b2a9b75a33ef25c12591bd899ac908363 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 17 Oct 2024 10:32:18 +0200 Subject: [PATCH] clean unrelated --- models/git/protected_banch_list_test.go | 2 +- models/git/protected_branch_list.go | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/models/git/protected_banch_list_test.go b/models/git/protected_banch_list_test.go index 8852e898d8e..94a48f37e6a 100644 --- a/models/git/protected_banch_list_test.go +++ b/models/git/protected_banch_list_test.go @@ -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() diff --git a/models/git/protected_branch_list.go b/models/git/protected_branch_list.go index d028a494141..613333a5a29 100644 --- a/models/git/protected_branch_list.go +++ b/models/git/protected_branch_list.go @@ -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 }