Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Add commit hash to blame result #795

Merged
merged 1 commit into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions blame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
}

Expand All @@ -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)
}
Expand Down