diff options
author | Jason Song <i@wolfogre.com> | 2024-03-06 17:56:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-06 09:56:04 +0000 |
commit | a4bcfb8ef1d5b2b522f78c9560d53ddbdbb02218 (patch) | |
tree | 799f52346ed3e4f035d15d942166803d72501311 /routers | |
parent | 5bdf805e054ec4131d8f1451752f251e8807cc73 (diff) | |
download | gitea-a4bcfb8ef1d5b2b522f78c9560d53ddbdbb02218.tar.gz gitea-a4bcfb8ef1d5b2b522f78c9560d53ddbdbb02218.zip |
Detect broken git hooks (#29494)
Detect broken git hooks by checking if the commit id of branches in DB
is the same with the git repo.
It can help #29338 #28277 and maybe more issues.
Users could complain about actions, webhooks, and activities not
working, but they were not aware that it is caused by broken git hooks
unless they could see a warning.
<img width="1348" alt="image"
src="https://github.com/go-gitea/gitea/assets/9418365/2b92a46d-7f1d-4115-bef4-9f970bd695da">
It should be merged after #29493. Otherwise, users could see a ephemeral
warning after committing and opening the repo home page immediately.
And it also waits for #29495, since the doc link (the anchor part) will
be updated.
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/repo/view.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 4df10fbea1..d47c926fa1 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -998,6 +998,8 @@ func renderHomeCode(ctx *context.Context) { return } + checkOutdatedBranch(ctx) + checkCitationFile(ctx, entry) if ctx.Written() { return @@ -1064,6 +1066,31 @@ func renderHomeCode(ctx *context.Context) { ctx.HTML(http.StatusOK, tplRepoHome) } +func checkOutdatedBranch(ctx *context.Context) { + if !(ctx.Repo.IsAdmin() || ctx.Repo.IsOwner()) { + return + } + + // get the head commit of the branch since ctx.Repo.CommitID is not always the head commit of `ctx.Repo.BranchName` + commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.BranchName) + if err != nil { + log.Error("GetBranchCommitID: %v", err) + // Don't return an error page, as it can be rechecked the next time the user opens the page. + return + } + + dbBranch, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, ctx.Repo.BranchName) + if err != nil { + log.Error("GetBranch: %v", err) + // Don't return an error page, as it can be rechecked the next time the user opens the page. + return + } + + if dbBranch.CommitID != commit.ID.String() { + ctx.Flash.Warning(ctx.Tr("repo.error.broken_git_hook", "https://docs.gitea.com/help/faq#push-hook--webhook--actions-arent-running"), true) + } +} + // RenderUserCards render a page show users according the input template func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*user_model.User, error), tpl base.TplName) { page := ctx.FormInt("page") |