diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index a3e9ad3bf9a..81128866835 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -956,8 +956,8 @@ func ExcerptBlob(ctx *context.Context) { return } lineCommits := allComments[filePath] - for _, line := range section.Lines { - if line.SectionInfo != nil && line.SectionInfo.RightHunkSize > 0 { + for index, line := range section.Lines { + if line.SectionInfo != nil && line.Type == 4 && !(line.SectionInfo.LastRightIdx == 0 && index+1 == len(section.Lines)) { start := int64(line.SectionInfo.LastRightIdx + 1) end := int64(line.SectionInfo.RightIdx - 1) for start <= end { diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 4b253e0eb66..c9e338c0807 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -121,7 +121,7 @@ func (d *DiffLine) GetHTMLDiffLineType() string { // CanComment returns whether a line can get commented func (d *DiffLine) CanComment() bool { - return len(d.Comments) == 0 + return len(d.Comments) == 0 && d.Type != DiffLineSection } // GetCommentSide returns the comment side of the first comment, if not set returns empty string @@ -481,8 +481,8 @@ func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, c for _, file := range diff.Files { if lineCommits, ok := allComments[file.Name]; ok { for _, section := range file.Sections { - for _, line := range section.Lines { - if line.SectionInfo != nil && line.SectionInfo.RightHunkSize > 0 { + for index, line := range section.Lines { + if line.SectionInfo != nil && line.Type == 4 && !(line.SectionInfo.LastRightIdx == 0 && index+1 == len(section.Lines)) { start := int64(line.SectionInfo.LastRightIdx + 1) end := int64(line.SectionInfo.RightIdx - 1) for start <= end { diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go index 644c2475f40..adcac355a7b 100644 --- a/services/gitdiff/gitdiff_test.go +++ b/services/gitdiff/gitdiff_test.go @@ -615,7 +615,7 @@ func TestDiff_LoadCommentsWithOutdated(t *testing.T) { } func TestDiffLine_CanComment(t *testing.T) { - assert.True(t, (&DiffLine{Type: DiffLineSection}).CanComment()) + assert.False(t, (&DiffLine{Type: DiffLineSection}).CanComment()) assert.False(t, (&DiffLine{Type: DiffLineAdd, Comments: []*issues_model.Comment{{Content: "bla"}}}).CanComment()) assert.True(t, (&DiffLine{Type: DiffLineAdd}).CanComment()) assert.True(t, (&DiffLine{Type: DiffLineDel}).CanComment())