diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-02-17 12:34:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-17 12:34:12 +0100 |
commit | 886dc83f3ed518a78772055497bcc7d7621b468e (patch) | |
tree | fbc0a6bd40806f9cd3e1d1dfe772c34014ef09c9 /plumbing | |
parent | 638e0d2864580f611fe5e630314d2fcde6389c60 (diff) | |
parent | 9720a5ff740a5934915c16d306ceff9e6470889e (diff) | |
download | go-git-886dc83f3ed518a78772055497bcc7d7621b468e.tar.gz |
Merge pull request #749 from irias/masterv4.1.1
plumbing: diff, fix crash when a small ending equal-chunk
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/format/diff/unified_encoder.go | 8 | ||||
-rw-r--r-- | plumbing/format/diff/unified_encoder_test.go | 37 |
2 files changed, 43 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 } } diff --git a/plumbing/format/diff/unified_encoder_test.go b/plumbing/format/diff/unified_encoder_test.go index 6e12070..0e419ca 100644 --- a/plumbing/format/diff/unified_encoder_test.go +++ b/plumbing/format/diff/unified_encoder_test.go @@ -476,6 +476,43 @@ index ab5eed5d4a2c33aeef67e0188ee79bed666bde6f..0adddcde4fd38042c354518351820eb0 W `, }, { + patch: oneChunkPatch, + desc: "modified deleting lines file with context to 6", + context: 6, + diff: `diff --git a/onechunk.txt b/onechunk.txt +index ab5eed5d4a2c33aeef67e0188ee79bed666bde6f..0adddcde4fd38042c354518351820eb06c417c82 100644 +--- a/onechunk.txt ++++ b/onechunk.txt +@@ -1,27 +1,23 @@ +-A + B + C + D + E + F + G +-H + I + J + K + L + M + N +-Ñ + O + P + Q + R + S + T +-U + V + W + X + Y + Z +`, +}, { patch: oneChunkPatch, desc: "modified deleting lines file with context to 3", |