mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	@@ -184,6 +184,24 @@ func (repo *Repository) IsProtectedBranch(branchName string, doer *User) (bool,
 | 
			
		||||
		BranchName: branchName,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	has, err := x.Exist(protectedBranch)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return true, err
 | 
			
		||||
	}
 | 
			
		||||
	return has, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsProtectedBranchForPush checks if branch is protected for push
 | 
			
		||||
func (repo *Repository) IsProtectedBranchForPush(branchName string, doer *User) (bool, error) {
 | 
			
		||||
	if doer == nil {
 | 
			
		||||
		return true, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protectedBranch := &ProtectedBranch{
 | 
			
		||||
		RepoID:     repo.ID,
 | 
			
		||||
		BranchName: branchName,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	has, err := x.Get(protectedBranch)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return true, err
 | 
			
		||||
 
 | 
			
		||||
@@ -85,9 +85,9 @@ func (r *Repository) CanCreateBranch() bool {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CanCommitToBranch returns true if repository is editable and user has proper access level
 | 
			
		||||
//   and branch is not protected
 | 
			
		||||
//   and branch is not protected for push
 | 
			
		||||
func (r *Repository) CanCommitToBranch(doer *models.User) (bool, error) {
 | 
			
		||||
	protectedBranch, err := r.Repository.IsProtectedBranch(r.BranchName, doer)
 | 
			
		||||
	protectedBranch, err := r.Repository.IsProtectedBranchForPush(r.BranchName, doer)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return false, err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user