Skip to content

Commit

Permalink
Invalidate comments when file is shortened (#11882)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
zeripath authored Jun 14, 2020
1 parent ae3cfa8 commit 48648d1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"container/list"
"encoding/json"
"fmt"
"regexp"
"strings"

"code.gitea.io/gitea/modules/git"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 48648d1

Please sign in to comment.