Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit 258a447

Browse files
jonasfranzappleboy
authored andcommitted
Add line blame (#116)
* Add line blame Signed-off-by: Jonas Franz <[email protected]> * Use uint instead of int to prevent failures Signed-off-by: Jonas Franz <[email protected]>
1 parent f1ecc13 commit 258a447

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

repo_blame.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@
44

55
package git
66

7+
import "fmt"
8+
79
// FileBlame return the Blame object of file
810
func (repo *Repository) FileBlame(revision, path, file string) ([]byte, error) {
911
return NewCommand("blame", "--root", file).RunInDirBytes(path)
1012
}
13+
14+
// LineBlame returns the latest commit at the given line
15+
func (repo *Repository) LineBlame(revision, path, file string, line uint) (*Commit, error) {
16+
res, err := NewCommand("blame", fmt.Sprintf("-L %d,%d", line, line), "-p", revision, file).RunInDir(path)
17+
if err != nil {
18+
return nil, err
19+
}
20+
if len(res) < 40 {
21+
return nil, fmt.Errorf("invalid result of blame: %s", res)
22+
}
23+
return repo.GetCommit(string(res[:40]))
24+
}

0 commit comments

Comments
 (0)