aboutsummaryrefslogtreecommitdiffstats
path: root/blame.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-10-16 11:16:14 +0200
committerGitHub <noreply@github.com>2018-10-16 11:16:14 +0200
commit236ae868ec4a62af2f7eec79d622ab0ebc94ccef (patch)
tree649d2ea793e48d82c9f447256673ab3d054ed378 /blame.go
parent41d6f2c31e68a9fdcbff4a3da8c40247f1293cc9 (diff)
parentc4be04433cf894cead23cd1de2be54c2886e44ad (diff)
downloadgo-git-236ae868ec4a62af2f7eec79d622ab0ebc94ccef.tar.gz
Merge pull request #986 from mcuadros/fix-blame
blame: fix edge case with missing \n in content length causing mismatched length error
Diffstat (limited to 'blame.go')
-rw-r--r--blame.go21
1 files changed, 16 insertions, 5 deletions
diff --git a/blame.go b/blame.go
index 349cdd9..adb72d5 100644
--- a/blame.go
+++ b/blame.go
@@ -123,14 +123,25 @@ func newLine(author, text string, date time.Time, hash plumbing.Hash) *Line {
}
func newLines(contents []string, commits []*object.Commit) ([]*Line, error) {
- if len(contents) != len(commits) {
- return nil, errors.New("contents and commits have different length")
+ lcontents := len(contents)
+ lcommits := len(commits)
+
+ if lcontents != lcommits {
+ if lcontents == lcommits-1 && contents[lcontents-1] != "\n" {
+ contents = append(contents, "\n")
+ } else {
+ return nil, errors.New("contents and commits have different length")
+ }
}
- result := make([]*Line, 0, len(contents))
+
+ result := make([]*Line, 0, lcontents)
for i := range contents {
- l := newLine(commits[i].Author.Email, contents[i], commits[i].Author.When, commits[i].Hash)
- result = append(result, l)
+ result = append(result, newLine(
+ commits[i].Author.Email, contents[i],
+ commits[i].Author.When, commits[i].Hash,
+ ))
}
+
return result, nil
}