fork of go-git with some jj specific features

blame: fix edge case with missing \n in content length causing mismatched length error

Signed-off-by: Máximo Cuadros <mcuadros@gmail.com>

Changed files
+42 -5
+16 -5
blame.go
··· 123 123 } 124 124 125 125 func newLines(contents []string, commits []*object.Commit) ([]*Line, error) { 126 - if len(contents) != len(commits) { 127 - return nil, errors.New("contents and commits have different length") 126 + lcontents := len(contents) 127 + lcommits := len(commits) 128 + 129 + if lcontents != lcommits { 130 + if lcontents == lcommits-1 && contents[lcontents-1] != "\n" { 131 + contents = append(contents, "\n") 132 + } else { 133 + return nil, errors.New("contents and commits have different length") 134 + } 128 135 } 129 - result := make([]*Line, 0, len(contents)) 136 + 137 + result := make([]*Line, 0, lcontents) 130 138 for i := range contents { 131 - l := newLine(commits[i].Author.Email, contents[i], commits[i].Author.When, commits[i].Hash) 132 - result = append(result, l) 139 + result = append(result, newLine( 140 + commits[i].Author.Email, contents[i], 141 + commits[i].Author.When, commits[i].Hash, 142 + )) 133 143 } 144 + 134 145 return result, nil 135 146 } 136 147
+26
blame_test.go
··· 2 2 3 3 import ( 4 4 "gopkg.in/src-d/go-git.v4/plumbing" 5 + "gopkg.in/src-d/go-git.v4/plumbing/object" 5 6 6 7 . "gopkg.in/check.v1" 7 8 "gopkg.in/src-d/go-git-fixtures.v3" ··· 12 13 } 13 14 14 15 var _ = Suite(&BlameSuite{}) 16 + 17 + func (s *BlameSuite) TestNewLines(c *C) { 18 + h := plumbing.NewHash("ce9f123d790717599aaeb76bc62510de437761be") 19 + lines, err := newLines([]string{"foo"}, []*object.Commit{{ 20 + Hash: h, 21 + Message: "foo", 22 + }}) 23 + 24 + c.Assert(err, IsNil) 25 + c.Assert(lines, HasLen, 1) 26 + c.Assert(lines[0].Text, Equals, "foo") 27 + c.Assert(lines[0].Hash, Equals, h) 28 + } 29 + 30 + func (s *BlameSuite) TestNewLinesWithNewLine(c *C) { 31 + lines, err := newLines([]string{"foo"}, []*object.Commit{ 32 + {Message: "foo"}, 33 + {Message: "bar"}, 34 + }) 35 + 36 + c.Assert(err, IsNil) 37 + c.Assert(lines, HasLen, 2) 38 + c.Assert(lines[0].Text, Equals, "foo") 39 + c.Assert(lines[1].Text, Equals, "\n") 40 + } 15 41 16 42 type blameTest struct { 17 43 repo string