Fixes: https://github.com/go-gitea/gitea/issues/29498 I don't quite understand this code, but this change does seem to fix the issue and I tested a number of diffs with it and saw no issue. The function gets such value if last line is an addition: ``` LastLeftIdx: (int) 0, LastRightIdx: (int) 47, LeftIdx: (int) 47, RightIdx: (int) 48, ``` If it's a deletion, it gets: ``` LastLeftIdx: (int) 47, LastRightIdx: (int) 0, LeftIdx: (int) 48, RightIdx: (int) 47, ``` So I think it's correct to make this check respect both left and right side. (cherry picked from commit 3b99066aa866e51e6a610716eaddfd1ea3645a67)
Showing the changes to services/gitdiff/gitdiff.go (1 of 1 file). Show all
Unified · Split
| @@ -152,7 +152,7 @@ func (d *DiffLine) GetBlobExcerptQuery() string { · 151 unmodified lines | |||
| 152 | 152 | ||
| 153 | // GetExpandDirection gets DiffLineExpandDirection | 153 | // GetExpandDirection gets DiffLineExpandDirection |
| 154 | func (d *DiffLine) GetExpandDirection() DiffLineExpandDirection { | 154 | func (d *DiffLine) GetExpandDirection() DiffLineExpandDirection { |
| 155 | if d.Type != DiffLineSection || d.SectionInfo == nil || d.SectionInfo.RightIdx-d.SectionInfo.LastRightIdx <= 1 { | 155 | if d.Type != DiffLineSection || d.SectionInfo == nil || d.SectionInfo.LeftIdx-d.SectionInfo.LastLeftIdx <= 1 || d.SectionInfo.RightIdx-d.SectionInfo.LastRightIdx <= 1 { |
| 156 | return DiffLineExpandNone | 156 | return DiffLineExpandNone |
| 157 | } | 157 | } |
| 158 | if d.SectionInfo.LastLeftIdx <= 0 && d.SectionInfo.LastRightIdx <= 0 { | 158 | if d.SectionInfo.LastLeftIdx <= 0 && d.SectionInfo.LastRightIdx <= 0 { |