From 3d1b30d81ddf83040180b8c004efb48098968dc4 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sun, 14 Jun 2020 11:06:35 +0100 Subject: [PATCH 1/2] Invalidate comments when file is shortened 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 3f2ee8b7d951e..71a190a727297 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -10,6 +10,7 @@ import ( "container/list" "encoding/json" "fmt" + "regexp" "strings" "code.gitea.io/gitea/modules/git" @@ -505,10 +506,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) } From f847f0acfe0e94372a334b4f3bf0beed999e7509 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sun, 14 Jun 2020 11:09:49 +0100 Subject: [PATCH 2/2] handle 1 line Signed-off-by: Andrew Thornton --- models/issue_comment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issue_comment.go b/models/issue_comment.go index 71a190a727297..7e940cbec493f 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -506,7 +506,7 @@ func (c *Comment) LoadReview() error { return c.loadReview(x) } -var notEnoughLines = regexp.MustCompile(`fatal: file .* has only \d+ lines`) +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