summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--services/gitdiff/gitdiff.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 8768b960fc..18d56c174a 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -1014,6 +1014,11 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
}
diffLine := &DiffLine{Type: DiffLineAdd, RightIdx: rightLine}
rightLine++
+ if curSection == nil {
+ // Create a new section to represent this hunk
+ curSection = &DiffSection{}
+ curFile.Sections = append(curFile.Sections, curSection)
+ }
curSection.Lines = append(curSection.Lines, diffLine)
case '-':
curFileLinesCount++
@@ -1026,6 +1031,11 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
if leftLine > 0 {
leftLine++
}
+ if curSection == nil {
+ // Create a new section to represent this hunk
+ curSection = &DiffSection{}
+ curFile.Sections = append(curFile.Sections, curSection)
+ }
curSection.Lines = append(curSection.Lines, diffLine)
case ' ':
curFileLinesCount++
@@ -1036,6 +1046,11 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
diffLine := &DiffLine{Type: DiffLinePlain, LeftIdx: leftLine, RightIdx: rightLine}
leftLine++
rightLine++
+ if curSection == nil {
+ // Create a new section to represent this hunk
+ curSection = &DiffSection{}
+ curFile.Sections = append(curFile.Sections, curSection)
+ }
curSection.Lines = append(curSection.Lines, diffLine)
default:
// This is unexpected