diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 16d3874e1bec8..1ababf8202bbe 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -898,6 +898,11 @@ commits.signed_by = Signed by commits.signed_by_untrusted_user = Signed by untrusted user commits.signed_by_untrusted_user_unmatched = Signed by untrusted user who does not match committer commits.gpg_key_id = GPG Key ID +commits.count.ahead_1 = This branch is 1 commit ahead of %s. +commits.count.behind_1 = This branch is 1 commit behind %s. +commits.count.ahead_n = This branch is %d commits ahead of %s. +commits.count.behind_n = This branch is %d commits behind %s. +commits.count.even = This branch is even with %s. ext_issues = Ext. Issues ext_issues.desc = Link to an external issue tracker. diff --git a/routers/repo/view.go b/routers/repo/view.go index 2df5b30ce8f95..ac1a76048ab60 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -26,6 +26,7 @@ import ( "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/repofiles" "code.gitea.io/gitea/modules/setting" ) @@ -677,6 +678,40 @@ func renderCode(ctx *context.Context) { ctx.Data["TreeLink"] = treeLink ctx.Data["TreeNames"] = treeNames ctx.Data["BranchLink"] = branchLink + + if ctx.Repo.BranchName != ctx.Repo.Repository.DefaultBranch { + + divergence, err := repofiles.CountDivergingCommits(ctx.Repo.Repository, ctx.Repo.BranchName) + if err != nil { + ctx.ServerError("CountDivergingCommits", err) + return + } + + var msg string + + if divergence.Ahead == 0 && divergence.Behind == 0 { + msg = ctx.Tr("repo.commits.count.even", ctx.Repo.Repository.DefaultBranch) + } + + if divergence.Ahead > 0 { + if divergence.Ahead == 1 { + msg = ctx.Tr("repo.commits.count.ahead_1", ctx.Repo.Repository.DefaultBranch) + } else { + msg = ctx.Tr("repo.commits.count.ahead_n", divergence.Ahead, ctx.Repo.Repository.DefaultBranch) + } + } + + if divergence.Behind > 0 { + if divergence.Behind == 1 { + msg = ctx.Tr("repo.commits.count.behind_1", ctx.Repo.Repository.DefaultBranch) + } else { + msg = ctx.Tr("repo.commits.count.behind_n", divergence.Behind, ctx.Repo.Repository.DefaultBranch) + } + } + + ctx.Flash.Info(msg) + } + ctx.HTML(200, tplRepoHome) }