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

plumbing: object, commit.Parent() method #534

Merged
merged 2 commits into from
Nov 20, 2017
Merged
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions plumbing/object/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package object
import (
"bufio"
"bytes"
"errors"
"fmt"
"io"
"strings"
Expand Down Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you create create test or this?

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.
Expand Down