diff options
-rw-r--r-- | plumbing/format/diff/unified_encoder.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/plumbing/format/diff/unified_encoder.go b/plumbing/format/diff/unified_encoder.go index cf2a34b..58edd95 100644 --- a/plumbing/format/diff/unified_encoder.go +++ b/plumbing/format/diff/unified_encoder.go @@ -262,11 +262,15 @@ func (c *hunksGenerator) processEqualsLines(ls []string, i int) { c.current.AddOp(Equal, c.afterContext...) c.afterContext = nil } else { - c.current.AddOp(Equal, c.afterContext[:c.ctxLines]...) + ctxLines := c.ctxLines + if ctxLines > len(c.afterContext) { + ctxLines = len(c.afterContext) + } + c.current.AddOp(Equal, c.afterContext[:ctxLines]...) c.hunks = append(c.hunks, c.current) c.current = nil - c.beforeContext = c.afterContext[c.ctxLines:] + c.beforeContext = c.afterContext[ctxLines:] c.afterContext = nil } } |