aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/diff/unified_encoder.go
diff options
context:
space:
mode:
authorAntonio Jesus Navarro Perez <antnavper@gmail.com>2018-09-07 10:50:31 +0200
committerAntonio Jesus Navarro Perez <antnavper@gmail.com>2018-09-07 10:50:31 +0200
commit80170bd73d5d6298ea6d40c66987fcde8148f1e8 (patch)
treeb27087d0dd2be6e311d1adb12f8998eda742b15e /plumbing/format/diff/unified_encoder.go
parentd3cec13ac0b195bfb897ed038a08b5130ab9969e (diff)
downloadgo-git-80170bd73d5d6298ea6d40c66987fcde8148f1e8.tar.gz
Fix fatal corrupt patch in unified diff format
Signed-off-by: Antonio Jesus Navarro Perez <antnavper@gmail.com>
Diffstat (limited to 'plumbing/format/diff/unified_encoder.go')
-rw-r--r--plumbing/format/diff/unified_encoder.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/plumbing/format/diff/unified_encoder.go b/plumbing/format/diff/unified_encoder.go
index 58edd95..8bd6d8a 100644
--- a/plumbing/format/diff/unified_encoder.go
+++ b/plumbing/format/diff/unified_encoder.go
@@ -237,9 +237,13 @@ func (c *hunksGenerator) addLineNumbers(la, lb int, linesBefore int, i int, op O
// we need to search for a reference for the next diff
switch {
case linesBefore != 0 && c.ctxLines != 0:
- clb = lb - c.ctxLines + 1
+ if lb > c.ctxLines {
+ clb = lb - c.ctxLines + 1
+ } else {
+ clb = 1
+ }
case c.ctxLines == 0:
- clb = lb - c.ctxLines
+ clb = lb
case i != len(c.chunks)-1:
next := c.chunks[i+1]
if next.Type() == op || next.Type() == Equal {