aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/index/index.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-04-17 17:36:28 +0200
committerGitHub <noreply@github.com>2017-04-17 17:36:28 +0200
commitc991d2d1c2253ac246441bc92bf97804a73c0bf2 (patch)
tree9a6965fb0023262ea17d02bcedd9f48204a80750 /plumbing/format/index/index.go
parent057f1dd4fa44df509cb96977c0a8193407a22767 (diff)
parent4b0fc1eb6937b6e5f8569794e8b669443e2c7584 (diff)
downloadgo-git-c991d2d1c2253ac246441bc92bf97804a73c0bf2.tar.gz
Merge pull request #344 from mcuadros/submodules-checkout
worktree: reset and checkout support for submodules
Diffstat (limited to 'plumbing/format/index/index.go')
-rw-r--r--plumbing/format/index/index.go22
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)