mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 14:31:02 +00:00 
			
		
		
		
	Merge pull request '[BUG] Don't overwrite protected branch accidentally' (#2473) from gusted/forgejo-error-duplicate into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2473 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
		
				commit
				
					
						775956cc68
					
				
			
		
					 4 changed files with 57 additions and 5 deletions
				
			
		|  | @ -132,12 +132,15 @@ func SettingsProtectedBranchPost(ctx *context.Context) { | |||
| 			} | ||||
| 		} | ||||
| 	} else { | ||||
| 		// FIXME: If a new ProtectBranch has a duplicate RuleName, an error should be returned. | ||||
| 		// Currently, if a new ProtectBranch with a duplicate RuleName is created, the existing ProtectBranch will be updated. | ||||
| 		// But we cannot modify this logic now because many unit tests rely on it. | ||||
| 		// Check if a rule already exists with this rulename, if so redirect to it. | ||||
| 		protectBranch, err = git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, f.RuleName) | ||||
| 		if err != nil { | ||||
| 			ctx.ServerError("GetProtectBranchOfRepoByName", err) | ||||
| 			ctx.ServerError("GetProtectedBranchRuleByName", err) | ||||
| 			return | ||||
| 		} | ||||
| 		if protectBranch != nil { | ||||
| 			ctx.Flash.Error(ctx.Tr("repo.settings.protected_branch_duplicate_rule_name")) | ||||
| 			ctx.Redirect(fmt.Sprintf("%s/settings/branches/edit?rule_name=%s", ctx.Repo.RepoLink, protectBranch.RuleName)) | ||||
| 			return | ||||
| 		} | ||||
| 	} | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue