mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Do not allow commiting to protected branch from online editor (#1502)
* Do not allow commiting to protected branch from online editor * Add editor integration tests for adding new file and not allowing to add new file to protected branch
This commit is contained in:
		@@ -63,6 +63,23 @@ func (repo *Repository) GetProtectedBranches() ([]*ProtectedBranch, error) {
 | 
			
		||||
	return protectedBranches, x.Find(&protectedBranches, &ProtectedBranch{RepoID: repo.ID})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsProtectedBranch checks if branch is protected
 | 
			
		||||
func (repo *Repository) IsProtectedBranch(branchName string) (bool, error) {
 | 
			
		||||
	protectedBranch := &ProtectedBranch{
 | 
			
		||||
		RepoID:     repo.ID,
 | 
			
		||||
		BranchName: branchName,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	has, err := x.Get(protectedBranch)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return true, err
 | 
			
		||||
	} else if has {
 | 
			
		||||
		return true, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return false, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AddProtectedBranch add protection to branch
 | 
			
		||||
func (repo *Repository) AddProtectedBranch(branchName string, canPush bool) error {
 | 
			
		||||
	protectedBranch := &ProtectedBranch{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user