Skip to content

Commit 6abb8d7

Browse files
authored
Invalidate comments when file is shortened (#11882) (#11884)
Backport #11882 Fix #10686 Signed-off-by: Andrew Thornton <[email protected]>
1 parent fdc6287 commit 6abb8d7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

models/issue_comment.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package models
88

99
import (
1010
"fmt"
11+
"regexp"
1112
"strings"
1213

1314
"code.gitea.io/gitea/modules/git"
@@ -489,10 +490,12 @@ func (c *Comment) LoadReview() error {
489490
return c.loadReview(x)
490491
}
491492

493+
var notEnoughLines = regexp.MustCompile(`fatal: file .* has only \d+ lines?`)
494+
492495
func (c *Comment) checkInvalidation(doer *User, repo *git.Repository, branch string) error {
493496
// FIXME differentiate between previous and proposed line
494497
commit, err := repo.LineBlame(branch, repo.Path, c.TreePath, uint(c.UnsignedLine()))
495-
if err != nil && strings.Contains(err.Error(), "fatal: no such path") {
498+
if err != nil && (strings.Contains(err.Error(), "fatal: no such path") || notEnoughLines.MatchString(err.Error())) {
496499
c.Invalidated = true
497500
return UpdateComment(c, doer)
498501
}

0 commit comments

Comments
 (0)