Skip to content

Commit d29e12d

Browse files
committed
Push whitelist now doesn't apply to branch deletion (go-gitea#4601)
1 parent 0990286 commit d29e12d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

models/branches.go

+18
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@ func (repo *Repository) IsProtectedBranch(branchName string, doer *User) (bool,
184184
BranchName: branchName,
185185
}
186186

187+
has, err := x.Exist(protectedBranch)
188+
if err != nil {
189+
return true, err
190+
}
191+
return has, nil
192+
}
193+
194+
// IsProtectedBranchForPush checks if branch is protected for push
195+
func (repo *Repository) IsProtectedBranchForPush(branchName string, doer *User) (bool, error) {
196+
if doer == nil {
197+
return true, nil
198+
}
199+
200+
protectedBranch := &ProtectedBranch{
201+
RepoID: repo.ID,
202+
BranchName: branchName,
203+
}
204+
187205
has, err := x.Get(protectedBranch)
188206
if err != nil {
189207
return true, err

modules/context/repo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func (r *Repository) CanCreateBranch() bool {
8585
}
8686

8787
// CanCommitToBranch returns true if repository is editable and user has proper access level
88-
// and branch is not protected
88+
// and branch is not protected for push
8989
func (r *Repository) CanCommitToBranch(doer *models.User) (bool, error) {
90-
protectedBranch, err := r.Repository.IsProtectedBranch(r.BranchName, doer)
90+
protectedBranch, err := r.Repository.IsProtectedBranchForPush(r.BranchName, doer)
9191
if err != nil {
9292
return false, err
9393
}

0 commit comments

Comments
 (0)