@@ -38,13 +38,13 @@ import (
3838)
3939
4040// CreateNewBranch creates a new repository branch
41- func CreateNewBranch (ctx context.Context , doer * user_model.User , repo * repo_model.Repository , gitRepo * git. Repository , oldBranchName , branchName string ) (err error ) {
41+ func CreateNewBranch (ctx context.Context , doer * user_model.User , repo * repo_model.Repository , oldBranchName , branchName string ) (err error ) {
4242 branch , err := git_model .GetBranch (ctx , repo .ID , oldBranchName )
4343 if err != nil {
4444 return err
4545 }
4646
47- return CreateNewBranchFromCommit (ctx , doer , repo , gitRepo , branch .CommitID , branchName )
47+ return CreateNewBranchFromCommit (ctx , doer , repo , branch .CommitID , branchName )
4848}
4949
5050// Branch contains the branch information
@@ -374,7 +374,7 @@ func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, branchNames,
374374}
375375
376376// CreateNewBranchFromCommit creates a new repository branch
377- func CreateNewBranchFromCommit (ctx context.Context , doer * user_model.User , repo * repo_model.Repository , gitRepo * git. Repository , commitID , branchName string ) (err error ) {
377+ func CreateNewBranchFromCommit (ctx context.Context , doer * user_model.User , repo * repo_model.Repository , commitID , branchName string ) (err error ) {
378378 err = repo .MustNotBeArchived ()
379379 if err != nil {
380380 return err
@@ -399,7 +399,7 @@ func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo
399399}
400400
401401// RenameBranch rename a branch
402- func RenameBranch (ctx context.Context , repo * repo_model.Repository , doer * user_model.User , gitRepo * git. Repository , from , to string ) (string , error ) {
402+ func RenameBranch (ctx context.Context , repo * repo_model.Repository , doer * user_model.User , from , to string ) (string , error ) {
403403 err := repo .MustNotBeArchived ()
404404 if err != nil {
405405 return "" , err
@@ -413,8 +413,12 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m
413413 return "target_exist" , nil
414414 }
415415
416- if exist , _ := git_model .IsBranchExist (ctx , repo .ID , from ); ! exist {
417- return "from_not_exist" , nil
416+ fromBranch , err := git_model .GetBranch (ctx , repo .ID , from )
417+ if err != nil {
418+ if git_model .IsErrBranchNotExist (err ) {
419+ return "from_not_exist" , nil
420+ }
421+ return "" , err
418422 }
419423
420424 perm , err := access_model .GetUserRepoPermission (ctx , repo , doer )
@@ -472,14 +476,9 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m
472476 }); err != nil {
473477 return "" , err
474478 }
475- refNameTo := git .RefNameFromBranch (to )
476- refID , err := gitRepo .GetRefCommitID (refNameTo .String ())
477- if err != nil {
478- return "" , err
479- }
480479
481480 notify_service .DeleteRef (ctx , doer , repo , git .RefNameFromBranch (from ))
482- notify_service .CreateRef (ctx , doer , repo , refNameTo , refID )
481+ notify_service .CreateRef (ctx , doer , repo , git . RefNameFromBranch ( to ), fromBranch . CommitID )
483482
484483 return "" , nil
485484}
0 commit comments