aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/commit.go
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/object/commit.go')
-rw-r--r--plumbing/object/commit.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/plumbing/object/commit.go b/plumbing/object/commit.go
index c5a1867..772ce17 100644
--- a/plumbing/object/commit.go
+++ b/plumbing/object/commit.go
@@ -3,6 +3,7 @@ package object
import (
"bufio"
"bytes"
+ "errors"
"fmt"
"io"
"strings"
@@ -91,6 +92,16 @@ func (c *Commit) NumParents() int {
return len(c.ParentHashes)
}
+var ErrNoParents = errors.New("commit has no parents")
+
+// FirstParent returns the first parent of c.
+func (c *Commit) FirstParent() (*Commit, error) {
+ if len(c.ParentHashes) == 0 {
+ return nil, ErrNoParents
+ }
+ return GetCommit(c.s, c.ParentHashes[0])
+}
+
// File returns the file with the specified "path" in the commit and a
// nil error if the file exists. If the file does not exist, it returns
// a nil file and the ErrFileNotFound error.