diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-04-02 10:40:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-02 10:40:28 +0200 |
commit | 32931400e23550cc840d2c2ae7bb5a20ef1946e7 (patch) | |
tree | cd74fcb15fb27e535bcc81e0c9ee7420d2423f8e | |
parent | 0c2618bc7d495322c6413b0ff62549712747cf9e (diff) | |
parent | a3cf1237f57399759c79b0b1827724d3481c8a9e (diff) | |
download | go-git-32931400e23550cc840d2c2ae7bb5a20ef1946e7.tar.gz |
Merge pull request #795 from shanedasilva/add_commit_hash_to_blame_result
Add commit hash to blame result
-rw-r--r-- | blame.go | 7 | ||||
-rw-r--r-- | blame_test.go | 5 |
2 files changed, 10 insertions, 2 deletions
@@ -109,12 +109,15 @@ type Line struct { Text string // Date is when the original text of the line was introduced Date time.Time + // Hash is the commit hash that introduced the original line + Hash plumbing.Hash } -func newLine(author, text string, date time.Time) *Line { +func newLine(author, text string, date time.Time, hash plumbing.Hash) *Line { return &Line{ Author: author, Text: text, + Hash: hash, Date: date, } } @@ -125,7 +128,7 @@ func newLines(contents []string, commits []*object.Commit) ([]*Line, error) { } result := make([]*Line, 0, len(contents)) for i := range contents { - l := newLine(commits[i].Author.Email, contents[i], commits[i].Author.When) + l := newLine(commits[i].Author.Email, contents[i], commits[i].Author.When, commits[i].Hash) result = append(result, l) } return result, nil diff --git a/blame_test.go b/blame_test.go index 51c546a..92911b1 100644 --- a/blame_test.go +++ b/blame_test.go @@ -32,6 +32,10 @@ func (s *BlameSuite) TestBlame(c *C) { obt, err := Blame(commit, t.path) c.Assert(err, IsNil) c.Assert(obt, DeepEquals, exp) + + for i, l := range obt.Lines { + c.Assert(l.Hash.String(), Equals, t.blames[i]) + } } } @@ -54,6 +58,7 @@ func (s *BlameSuite) mockBlame(c *C, t blameTest, r *Repository) (blame *BlameRe Author: commit.Author.Email, Text: lines[i], Date: commit.Author.When, + Hash: commit.Hash, } blamedLines = append(blamedLines, l) } |