@@ -286,6 +286,11 @@ func pushNewBranch(ctx context.Context, repo *repo_model.Repository, pusher *use
286286 if err := repo_model .UpdateRepositoryCols (ctx , repo , "default_branch" , "is_empty" ); err != nil {
287287 return nil , fmt .Errorf ("UpdateRepositoryCols: %w" , err )
288288 }
289+ } else {
290+ // calculate the number of commits in the branch
291+ if err := UpdateRepoBranchCommitsCount (ctx , repo , opts .RefFullName .BranchName (), newCommit ); err != nil {
292+ log .Error ("UpdateRepoBranchCommitsCount: %v" , err )
293+ }
289294 }
290295
291296 l , err := newCommit .CommitsBeforeLimit (10 )
@@ -296,7 +301,7 @@ func pushNewBranch(ctx context.Context, repo *repo_model.Repository, pusher *use
296301 return l , nil
297302}
298303
299- func UpdateRepoBranchCommitsCount (ctx context.Context , repo * repo_model.Repository , branch string , newCommit * git.Commit , isForcePush bool ) error {
304+ func UpdateRepoBranchCommitsCount (ctx context.Context , repo * repo_model.Repository , branch string , newCommit * git.Commit ) error {
300305 // calculate the number of commits in the branch
301306 commitsCount , err := newCommit .CommitsCount ()
302307 if err != nil {
@@ -313,6 +318,11 @@ func pushUpdateBranch(ctx context.Context, repo *repo_model.Repository, pusher *
313318
314319 branch := opts .RefFullName .BranchName ()
315320
321+ // calculate the number of commits in the branch
322+ if err := UpdateRepoBranchCommitsCount (ctx , repo , branch , newCommit ); err != nil {
323+ log .Error ("UpdateRepoBranchCommitsCount: %v" , err )
324+ }
325+
316326 isForcePush , err := newCommit .IsForcePush (opts .OldCommitID )
317327 if err != nil {
318328 log .Error ("IsForcePush %s:%s failed: %v" , repo .FullName (), branch , err )
@@ -329,11 +339,6 @@ func pushUpdateBranch(ctx context.Context, repo *repo_model.Repository, pusher *
329339 NewCommitID : opts .NewCommitID ,
330340 })
331341
332- // calculate the number of commits in the branch
333- if err := UpdateRepoBranchCommitsCount (ctx , repo , branch , newCommit , isForcePush ); err != nil {
334- log .Error ("UpdateRepoBranchCommitsCount: %v" , err )
335- }
336-
337342 return l , nil
338343}
339344
0 commit comments