Skip to content

Commit decc962

Browse files
committed
Fix git diff hunk 0 based start line
1 parent b46623f commit decc962

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

services/gitdiff/gitdiff.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,9 @@ func parseHunks(ctx context.Context, curFile *DiffFile, maxLines, maxLineCharact
864864
}
865865
curSection.Lines = append(curSection.Lines, diffLine)
866866
curSection.FileName = curFile.Name
867-
// update line number.
868-
leftLine = lineSectionInfo.LeftIdx
869-
rightLine = lineSectionInfo.RightIdx
867+
// update line number. leftLine and rightLine are 1-based indexes, 0 means 1
868+
leftLine = max(lineSectionInfo.LeftIdx, 1)
869+
rightLine = max(lineSectionInfo.RightIdx, 1)
870870
continue
871871
case '\\':
872872
if maxLines > -1 && curFileLinesCount >= maxLines {

0 commit comments

Comments
 (0)