@@ -159,6 +159,53 @@ func TestRenameBranch(t *testing.T) {
159159 })
160160}
161161
162+ func TestRenameBranchProtectedRuleConflict (t * testing.T ) {
163+ assert .NoError (t , unittest .PrepareTestDatabase ())
164+ repo1 := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 1 })
165+ master := unittest .AssertExistsAndLoadBean (t , & git_model.Branch {RepoID : repo1 .ID , Name : "master" })
166+
167+ devBranch := & git_model.Branch {
168+ RepoID : repo1 .ID ,
169+ Name : "dev" ,
170+ CommitID : master .CommitID ,
171+ CommitMessage : master .CommitMessage ,
172+ CommitTime : master .CommitTime ,
173+ PusherID : master .PusherID ,
174+ }
175+ assert .NoError (t , db .Insert (t .Context (), devBranch ))
176+
177+ pbDev := git_model.ProtectedBranch {
178+ RepoID : repo1 .ID ,
179+ RuleName : "dev" ,
180+ CanPush : true ,
181+ }
182+ assert .NoError (t , git_model .UpdateProtectBranch (t .Context (), repo1 , & pbDev , git_model.WhitelistOptions {}))
183+
184+ pbMain := git_model.ProtectedBranch {
185+ RepoID : repo1 .ID ,
186+ RuleName : "main" ,
187+ CanPush : true ,
188+ }
189+ assert .NoError (t , git_model .UpdateProtectBranch (t .Context (), repo1 , & pbMain , git_model.WhitelistOptions {}))
190+
191+ assert .NoError (t , git_model .RenameBranch (t .Context (), repo1 , "dev" , "main" , func (ctx context.Context , isDefault bool ) error {
192+ return nil
193+ }))
194+
195+ unittest .AssertNotExistsBean (t , & git_model.Branch {RepoID : repo1 .ID , Name : "dev" })
196+ unittest .AssertExistsAndLoadBean (t , & git_model.Branch {RepoID : repo1 .ID , Name : "main" })
197+
198+ protectedDev , err := git_model .GetProtectedBranchRuleByName (t .Context (), repo1 .ID , "dev" )
199+ assert .NoError (t , err )
200+ assert .NotNil (t , protectedDev )
201+ assert .Equal (t , "dev" , protectedDev .RuleName )
202+
203+ protectedMainByID , err := git_model .GetProtectedBranchRuleByID (t .Context (), repo1 .ID , pbMain .ID )
204+ assert .NoError (t , err )
205+ assert .NotNil (t , protectedMainByID )
206+ assert .Equal (t , "main" , protectedMainByID .RuleName )
207+ }
208+
162209func TestOnlyGetDeletedBranchOnCorrectRepo (t * testing.T ) {
163210 assert .NoError (t , unittest .PrepareTestDatabase ())
164211
0 commit comments