diff options
Diffstat (limited to 'plumbing/format/index/index.go')
-rw-r--r-- | plumbing/format/index/index.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/plumbing/format/index/index.go b/plumbing/format/index/index.go index 61e7d66..402a48e 100644 --- a/plumbing/format/index/index.go +++ b/plumbing/format/index/index.go @@ -1,20 +1,21 @@ package index import ( + "bytes" "errors" "fmt" "time" - "bytes" - "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/filemode" ) var ( - // ErrUnsupportedVersion is returned by Decode when the idxindex file - // version is not supported. - ErrUnsupportedVersion = errors.New("Unsuported version") + // ErrUnsupportedVersion is returned by Decode when the index file version + // is not supported. + ErrUnsupportedVersion = errors.New("unsupported version") + // ErrEntryNotFound is returned by Index.Entry, if an entry is not found. + ErrEntryNotFound = errors.New("entry not found") indexSignature = []byte{'D', 'I', 'R', 'C'} treeExtSignature = []byte{'T', 'R', 'E', 'E'} @@ -50,6 +51,17 @@ type Index struct { ResolveUndo *ResolveUndo } +// Entry returns the entry that match the given path, if any. +func (i *Index) Entry(path string) (Entry, error) { + for _, e := range i.Entries { + if e.Name == path { + return e, nil + } + } + + return Entry{}, ErrEntryNotFound +} + // String is equivalent to `git ls-files --stage --debug` func (i *Index) String() string { buf := bytes.NewBuffer(nil) |