Skip to content

Commit 3b99066

Browse files
authored
Fix incorrect diff expander for deletion of last lines in a file (#29501)
Fixes: #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.
1 parent 6841e58 commit 3b99066

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

services/gitdiff/gitdiff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (d *DiffLine) GetBlobExcerptQuery() string {
154154

155155
// GetExpandDirection gets DiffLineExpandDirection
156156
func (d *DiffLine) GetExpandDirection() DiffLineExpandDirection {
157-
if d.Type != DiffLineSection || d.SectionInfo == nil || d.SectionInfo.RightIdx-d.SectionInfo.LastRightIdx <= 1 {
157+
if d.Type != DiffLineSection || d.SectionInfo == nil || d.SectionInfo.LeftIdx-d.SectionInfo.LastLeftIdx <= 1 || d.SectionInfo.RightIdx-d.SectionInfo.LastRightIdx <= 1 {
158158
return DiffLineExpandNone
159159
}
160160
if d.SectionInfo.LastLeftIdx <= 0 && d.SectionInfo.LastRightIdx <= 0 {

0 commit comments

Comments
 (0)