Quellcode durchsuchen

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>
tags/v1.13.0-rc1
zeripath vor 4 Jahren
Ursprung
Commit
48648d1d86
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden
1 geänderte Dateien mit 4 neuen und 1 gelöschten Zeilen
  1. 4
    1
      models/issue_comment.go

+ 4
- 1
models/issue_comment.go Datei anzeigen

@@ -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)
}

Laden…
Abbrechen
Speichern