aboutsummaryrefslogtreecommitdiffstats
path: root/commit.go
diff options
context:
space:
mode:
Diffstat (limited to 'commit.go')
-rw-r--r--commit.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/commit.go b/commit.go
index afd67ab..99dbf37 100644
--- a/commit.go
+++ b/commit.go
@@ -3,12 +3,16 @@ package git
import (
"bufio"
"bytes"
+ "errors"
"fmt"
"io"
"gopkg.in/src-d/go-git.v2/core"
)
+// New errors defined by this package.
+var ErrFileNotFound = errors.New("file not found")
+
type Hash core.Hash
// Commit points to a single tree, marking it as what the project looked like
@@ -50,6 +54,18 @@ func (c *Commit) NumParents() int {
return len(c.parents)
}
+// File returns the file with the specified "path" in the commit and a
+// nil error if the file exists. If the file does not exists, it returns
+// a nil file and the ErrFileNotFound error.
+func (c *Commit) File(path string) (file *File, err error) {
+ for file := range c.Tree().Files() {
+ if file.Name == path {
+ return file, nil
+ }
+ }
+ return nil, ErrFileNotFound
+}
+
// Decode transform an core.Object into a Blob struct
func (c *Commit) Decode(o core.Object) error {
c.Hash = o.Hash()