aboutsummaryrefslogtreecommitdiffstats
path: root/commit.go
diff options
context:
space:
mode:
authorAlberto Cortés <alberto@sourced.tech>2015-11-27 12:39:34 +0100
committerAlberto Cortés <alberto@sourced.tech>2015-12-04 09:48:41 +0100
commit48bf5bdeb9092ee5004014c0bf7a21f0e2fbf6fc (patch)
treed96d8dfe4c8e4e18f19f2f50d67befc4d9a88d57 /commit.go
parentd643cea1e8a6d618b2eddfdbed086c7bdf208658 (diff)
downloadgo-git-48bf5bdeb9092ee5004014c0bf7a21f0e2fbf6fc.tar.gz
fix PR#7 comments
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()