aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue_comment.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-06-14 14:55:20 +0100
committerGitHub <noreply@github.com>2020-06-14 16:55:20 +0300
commit48648d1d86a7b55f5530e737e5262335ab5e17df (patch)
tree2afe7c39dcd96961d12b6f98f10871a43ba30941 /models/issue_comment.go
parentae3cfa844945f446b511dbcae358b3f5b930b3ce (diff)
downloadgitea-48648d1d86a7b55f5530e737e5262335ab5e17df.tar.gz
gitea-48648d1d86a7b55f5530e737e5262335ab5e17df.zip
Invalidate comments when file is shortened (#11882)
* Invalidate comments when file is shortened Fix #10686 Signed-off-by: Andrew Thornton <art27@cantab.net> * handle 1 line Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'models/issue_comment.go')
-rw-r--r--models/issue_comment.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go
index 3f2ee8b7d9..7e940cbec4 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)
}