From 6abb8d751ccaa16d2bc8aff9940faf93ee775b17 Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 15 Jun 2020 18:26:30 +0100 Subject: [PATCH] Invalidate comments when file is shortened (#11882) (#11884) Backport #11882 Fix #10686 Signed-off-by: Andrew Thornton --- models/issue_comment.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/models/issue_comment.go b/models/issue_comment.go index f7017435d7..bb3c4be7ba 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -8,6 +8,7 @@ package models import ( "fmt" + "regexp" "strings" "code.gitea.io/gitea/modules/git" @@ -489,10 +490,12 @@ func (c *Comment) LoadReview() error { return c.loadReview(x) } +var notEnoughLines = regexp.MustCompile(`fatal: file .* has only \d+ lines?`) + func (c *Comment) checkInvalidation(doer *User, repo *git.Repository, branch string) error { // FIXME differentiate between previous and proposed line commit, err := repo.LineBlame(branch, repo.Path, c.TreePath, uint(c.UnsignedLine())) - if err != nil && strings.Contains(err.Error(), "fatal: no such path") { + if err != nil && (strings.Contains(err.Error(), "fatal: no such path") || notEnoughLines.MatchString(err.Error())) { c.Invalidated = true return UpdateComment(c, doer) }