Skip to content

Commit baf7515

Browse files
committed
feat: check branch commit
1 parent db545b2 commit baf7515

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

routers/web/repo/view.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) {
768768
}
769769
}
770770

771+
771772
// Home render repository home page
772773
func Home(ctx *context.Context) {
773774
if setting.Other.EnableFeed {
@@ -1006,6 +1007,8 @@ func renderHomeCode(ctx *context.Context) {
10061007
return
10071008
}
10081009

1010+
checkOutdatedBranch(ctx)
1011+
10091012
checkCitationFile(ctx, entry)
10101013
if ctx.Written() {
10111014
return
@@ -1072,6 +1075,31 @@ func renderHomeCode(ctx *context.Context) {
10721075
ctx.HTML(http.StatusOK, tplRepoHome)
10731076
}
10741077

1078+
func checkOutdatedBranch(ctx *context.Context) {
1079+
// get the head commit of the branch since ctx.Repo.CommitID is not always the head commit of `ctx.Repo.BranchName`
1080+
commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.BranchName)
1081+
if err != nil {
1082+
log.Error("GetBranchCommitID: %v", err)
1083+
// Don't return an error page, as it can be rechecked the next time the user opens the page.
1084+
return
1085+
}
1086+
1087+
1088+
dbBranch, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, ctx.Repo.BranchName)
1089+
if err != nil {
1090+
log.Error("GetBranch: %v", err)
1091+
// Don't return an error page, as it can be rechecked the next time the user opens the page.
1092+
return
1093+
}
1094+
1095+
if commit.ID.String() != dbBranch.CommitID &&
1096+
time.Since(commit.)
1097+
{
1098+
1099+
}
1100+
}
1101+
1102+
10751103
// RenderUserCards render a page show users according the input template
10761104
func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*user_model.User, error), tpl base.TplName) {
10771105
page := ctx.FormInt("page")
@@ -1147,3 +1175,5 @@ func Forks(ctx *context.Context) {
11471175

11481176
ctx.HTML(http.StatusOK, tplForks)
11491177
}
1178+
1179+

0 commit comments

Comments
 (0)