diff options
Diffstat (limited to 'routers/repo/branch.go')
-rw-r--r-- | routers/repo/branch.go | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/routers/repo/branch.go b/routers/repo/branch.go index 4d5b3996c9..8b987f0a60 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/repofiles" "code.gitea.io/gitea/modules/util" ) @@ -28,6 +29,8 @@ type Branch struct { IsProtected bool IsDeleted bool DeletedBranch *models.DeletedBranch + CommitsAhead int + CommitsBehind int } // Branches render repository branch page @@ -168,16 +171,25 @@ func loadBranches(ctx *context.Context) []*Branch { return nil } - isProtected, err := ctx.Repo.Repository.IsProtectedBranch(rawBranches[i].Name, ctx.User) + branchName := rawBranches[i].Name + isProtected, err := ctx.Repo.Repository.IsProtectedBranch(branchName, ctx.User) if err != nil { ctx.ServerError("IsProtectedBranch", err) return nil } + divergence, divergenceError := repofiles.CountDivergingCommits(ctx.Repo.Repository, branchName) + if divergenceError != nil { + ctx.ServerError("CountDivergingCommits", divergenceError) + return nil + } + branches[i] = &Branch{ - Name: rawBranches[i].Name, - Commit: commit, - IsProtected: isProtected, + Name: branchName, + Commit: commit, + IsProtected: isProtected, + CommitsAhead: divergence.Ahead, + CommitsBehind: divergence.Behind, } } |