Skip to content

Commit 48648d1

Browse files
authored
Invalidate comments when file is shortened (#11882)
* Invalidate comments when file is shortened Fix #10686 Signed-off-by: Andrew Thornton <[email protected]> * handle 1 line Signed-off-by: Andrew Thornton <[email protected]>
1 parent ae3cfa8 commit 48648d1

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
@@ -10,6 +10,7 @@ import (
1010
"container/list"
1111
"encoding/json"
1212
"fmt"
13+
"regexp"
1314
"strings"
1415

1516
"code.gitea.io/gitea/modules/git"
@@ -505,10 +506,12 @@ func (c *Comment) LoadReview() error {
505506
return c.loadReview(x)
506507
}
507508

509+
var notEnoughLines = regexp.MustCompile(`fatal: file .* has only \d+ lines?`)
510+
508511
func (c *Comment) checkInvalidation(doer *User, repo *git.Repository, branch string) error {
509512
// FIXME differentiate between previous and proposed line
510513
commit, err := repo.LineBlame(branch, repo.Path, c.TreePath, uint(c.UnsignedLine()))
511-
if err != nil && strings.Contains(err.Error(), "fatal: no such path") {
514+
if err != nil && (strings.Contains(err.Error(), "fatal: no such path") || notEnoughLines.MatchString(err.Error())) {
512515
c.Invalidated = true
513516
return UpdateComment(c, doer)
514517
}

0 commit comments

Comments
 (0)